2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-06-04 13:48:07 +02:00
|
|
|
import { ColumnModel } from './models/table_models';
|
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
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
import Table from './table';
|
2015-05-26 20:20:17 +02:00
|
|
|
import TableItemWrapper from './table_item_wrapper';
|
2015-05-26 13:14:35 +02:00
|
|
|
import TableItemText from './table_item_text';
|
2015-05-26 19:59:37 +02:00
|
|
|
import TableItemAcl from './table_item_acl';
|
|
|
|
import TableItemSelectable from './table_item_selectable';
|
2015-05-22 16:51:08 +02:00
|
|
|
import TableItemSubtableButton from './table_item_subtable_button';
|
|
|
|
|
|
|
|
|
|
|
|
let TableItemSubtable = React.createClass({
|
|
|
|
propTypes: {
|
2015-06-04 13:48:07 +02:00
|
|
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)),
|
2015-05-22 16:51:08 +02:00
|
|
|
columnContent: React.PropTypes.object
|
|
|
|
},
|
|
|
|
|
2015-05-22 18:41:15 +02:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
'open': false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
2015-05-26 13:14:35 +02:00
|
|
|
EditionListStore.listen(this.onChange);
|
2015-05-22 18:41:15 +02:00
|
|
|
},
|
|
|
|
|
2015-06-05 11:06:36 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
EditionListStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
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 {
|
2015-05-26 17:25:03 +02:00
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
EditionListActions.fetchEditionList(this.props.columnContent.id);
|
|
|
|
this.setState({
|
|
|
|
'open': true,
|
|
|
|
'editionList': EditionListStore.getState()
|
|
|
|
});
|
|
|
|
}
|
2015-05-22 18:41:15 +02:00
|
|
|
},
|
|
|
|
|
2015-05-26 16:48:48 +02:00
|
|
|
selectItem(parentId, itemId) {
|
|
|
|
EditionListActions.selectEdition({
|
|
|
|
'pieceId': parentId,
|
|
|
|
'editionId': itemId
|
|
|
|
});
|
2015-05-22 16:51:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
let renderEditionListTable = () => {
|
|
|
|
|
|
|
|
let columnList = [
|
2015-06-04 13:48:07 +02:00
|
|
|
new ColumnModel('edition_number', 'Number', TableItemText, 2, false),
|
|
|
|
new ColumnModel('user_registered', 'User', TableItemText, 4, true),
|
|
|
|
new ColumnModel('acl', 'Actions', TableItemAcl, 4, true)
|
2015-05-26 13:14:35 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
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 (
|
2015-05-26 16:48:48 +02:00
|
|
|
<TableItemSelectable
|
2015-05-27 09:56:26 +02:00
|
|
|
className="ascribe-table-item-selectable"
|
2015-05-26 16:48:48 +02:00
|
|
|
selectItem={this.selectItem}
|
|
|
|
parentId={this.props.columnContent.id}
|
2015-06-05 11:06:36 +02:00
|
|
|
key={i} />
|
2015-05-26 13:14:35 +02:00
|
|
|
);
|
2015-06-05 11:06:36 +02:00
|
|
|
})}
|
2015-05-26 13:14:35 +02:00
|
|
|
</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">
|
2015-05-26 20:20:17 +02:00
|
|
|
<TableItemWrapper
|
|
|
|
columnList={this.props.columnList}
|
|
|
|
columnContent={this.props.columnContent}
|
2015-06-05 11:06:36 +02:00
|
|
|
columnWidth={12} />
|
2015-05-27 09:56:26 +02:00
|
|
|
<div className="col-xs-1 col-sm-1 col-md-1 col-lg-1 ascribe-table-item-column">
|
2015-06-05 11:06:36 +02:00
|
|
|
<TableItemSubtableButton content="+" onClick={this.loadEditionList} />
|
2015-05-22 16:51:08 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-05-26 13:14:35 +02:00
|
|
|
{renderEditionListTable()}
|
2015-06-05 11:06:36 +02:00
|
|
|
</div>
|
2015-05-22 16:51:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-26 14:43:04 +02:00
|
|
|
export default TableItemSubtable;
|