2015-05-22 16:51:08 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import TableColumnContentModel from '../../models/table_column_content_model';
|
2015-05-26 14:05:34 +02:00
|
|
|
import TableColumnMixin from '../../mixins/table_column_mixin';
|
2015-05-22 16:51:08 +02:00
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
import EditionListStore from '../../stores/edition_list_store';
|
|
|
|
import EditionListActions from '../../actions/edition_list_actions';
|
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
// ToDo: Create Table-specific Utils to not lock it to projects utilities
|
|
|
|
import GeneralUtils from '../../utils/general_utils';
|
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
import Table from './table';
|
|
|
|
import TableItem from './table_item';
|
|
|
|
import TableItemText from './table_item_text';
|
2015-05-22 16:51:08 +02:00
|
|
|
import TableItemSubtableButton from './table_item_subtable_button';
|
|
|
|
|
|
|
|
|
|
|
|
let TableItemSubtable = React.createClass({
|
2015-05-26 14:05:34 +02:00
|
|
|
mixins: [TableColumnMixin],
|
2015-05-22 16:51:08 +02:00
|
|
|
propTypes: {
|
|
|
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(TableColumnContentModel)),
|
|
|
|
columnContent: React.PropTypes.object
|
|
|
|
},
|
|
|
|
|
2015-05-22 18:41:15 +02:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
'open': false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-05-26 13:14:35 +02:00
|
|
|
EditionListStore.listen(this.onChange);
|
2015-05-22 18:41:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
loadEditionList() {
|
2015-05-26 13:14:35 +02:00
|
|
|
if(this.state.open) {
|
|
|
|
this.setState({
|
|
|
|
'open': false
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EditionListActions.fetchEditionList(this.props.columnContent.id);
|
|
|
|
this.setState({
|
|
|
|
'open': true,
|
|
|
|
'editionList': EditionListStore.getState()
|
|
|
|
});
|
|
|
|
}
|
2015-05-22 18:41:15 +02:00
|
|
|
},
|
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
render() {
|
|
|
|
|
|
|
|
let calcColumnElementContent = () => {
|
|
|
|
return this.props.columnList.map((column, i) => {
|
|
|
|
|
|
|
|
let TypeElement = column.displayType;
|
|
|
|
let columnClass = this.calcColumnClasses(this.props.columnList, i);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={columnClass + ' ascribe-table-item-column'} key={i}>
|
|
|
|
<TypeElement content={this.props.columnContent[column.columnName]} width="50" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
|
|
|
|
let renderEditionListTable = () => {
|
|
|
|
|
|
|
|
let columnList = [
|
|
|
|
new TableColumnContentModel('edition_number', 'Edition Number', TableItemText, 2, false),
|
|
|
|
new TableColumnContentModel('user_registered', 'User', TableItemText, 4, true),
|
|
|
|
new TableColumnContentModel('bitcoin_id', 'Bitcoin Address', TableItemText, 4, true)
|
|
|
|
];
|
|
|
|
|
|
|
|
if(this.state.open && this.state.editionList[this.props.columnContent.id] && this.state.editionList[this.props.columnContent.id].length) {
|
|
|
|
return (
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
|
|
|
<Table itemList={this.state.editionList[this.props.columnContent.id]} columnList={columnList}>
|
|
|
|
{this.state.editionList[this.props.columnContent.id].map((edition, i) => {
|
|
|
|
return (
|
|
|
|
<TableItem
|
|
|
|
key={i}>
|
|
|
|
</TableItem>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
return (
|
|
|
|
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12 ascribe-table-item">
|
|
|
|
<div className="row">
|
|
|
|
{calcColumnElementContent()}
|
|
|
|
<div className="col-xs-2 col-sm-2 col-md-2 col-lg-2 ascribe-table-item-column">
|
2015-05-22 18:41:15 +02:00
|
|
|
<TableItemSubtableButton content="Editions" onClick={this.loadEditionList}>
|
2015-05-22 16:51:08 +02:00
|
|
|
</TableItemSubtableButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-05-26 13:14:35 +02:00
|
|
|
{renderEditionListTable()}
|
2015-05-22 16:51:08 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
export default TableItemSubtable;
|