// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. const TextFormatting = require('../utils/text_formatting.jsx'); export default class PostAttachment extends React.Component { constructor(props) { super(props); this.getFieldsTable = this.getFieldsTable.bind(this); } getFieldsTable() { const fields = this.props.attachment.fields; if (!fields || !fields.length) { return ''; } const compactTable = fields.filter((field) => field.short).length > 0; let tHead; let tBody; if (compactTable) { let headerCols = []; let bodyCols = []; fields.forEach((field, i) => { headerCols.push( {field.title} ); bodyCols.push( ); }); tHead = ( {headerCols} ); tBody = ( {bodyCols} ); } else { tBody = []; fields.forEach((field, i) => { tBody.push( {field.title} ); }); } return ( {tHead} {tBody}
); } render() { const data = this.props.attachment; let preText; if (data.pretext) { preText = (
); } let author = []; if (data.author_name || data.author_icon) { if (data.author_icon) { author.push( ); } if (data.author_name) { author.push( {data.author_name} ); } } if (data.author_link) { author = ( {author} ); } let title; if (data.title) { if (data.title_link) { title = (

{data.title}

); } else { title = (

{data.title}

); } } let text; if (data.text) { text = (
); } let image; if (data.image_url) { image = ( ); } let thumb; if (data.thumb_url) { thumb = (
); } const fields = this.getFieldsTable(); let useBorderStyle; if (data.color && data.color[0] === '#') { useBorderStyle = {borderLeftColor: data.color}; } return (
{preText}
{author} {title}
{text} {image} {fields}
{thumb}
); } } PostAttachment.propTypes = { attachment: React.PropTypes.object.isRequired };