2015-05-19 17:13:09 +02:00
|
|
|
import React from 'react';
|
2015-05-20 11:32:56 +02:00
|
|
|
import AltContainer from 'alt/AltContainer';
|
2015-05-19 17:13:09 +02:00
|
|
|
|
|
|
|
import PieceListStore from '../stores/piece_list_store';
|
|
|
|
import PieceListActions from '../actions/piece_list_actions';
|
2015-05-20 15:22:29 +02:00
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
import EditionListStore from '../stores/edition_list_store';
|
|
|
|
import EditionListActions from '../actions/edition_list_actions';
|
|
|
|
|
2015-05-21 15:14:05 +02:00
|
|
|
import Table from './ascribe_table/table';
|
2015-05-22 14:15:12 +02:00
|
|
|
import TableItem from './ascribe_table/table_item';
|
2015-05-21 15:14:05 +02:00
|
|
|
import TableItemImg from './ascribe_table/table_item_img';
|
|
|
|
import TableItemText from './ascribe_table/table_item_text';
|
2015-05-22 16:51:08 +02:00
|
|
|
import TableItemSubtable from './ascribe_table/table_item_subtable';
|
|
|
|
import TableItemSubtableButton from './ascribe_table/table_item_subtable_button';
|
2015-05-19 17:13:09 +02:00
|
|
|
|
2015-05-22 16:51:08 +02:00
|
|
|
import TableColumnContentModel from '../models/table_column_content_model';
|
2015-05-21 16:02:42 +02:00
|
|
|
|
2015-05-22 15:03:29 +02:00
|
|
|
import Pagination from './ascribe_pagination/pagination'
|
2015-05-19 17:13:09 +02:00
|
|
|
|
2015-05-20 16:44:45 +02:00
|
|
|
|
2015-05-19 17:16:01 +02:00
|
|
|
let PieceList = React.createClass({
|
2015-05-20 11:32:56 +02:00
|
|
|
|
2015-05-21 12:12:25 +02:00
|
|
|
getInitialState() {
|
|
|
|
return PieceListStore.getState();
|
|
|
|
},
|
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
componentDidMount() {
|
2015-05-21 17:54:27 +02:00
|
|
|
let page = this.props.query.page || this.state.page;
|
2015-05-22 16:51:08 +02:00
|
|
|
PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
|
2015-05-19 17:13:09 +02:00
|
|
|
},
|
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
PieceListStore.unlisten(this.onChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange() {
|
|
|
|
this.setState(this.getInitialState());
|
|
|
|
},
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
paginationGoToPage(page) {
|
2015-05-22 17:11:17 +02:00
|
|
|
return (e) => PieceListActions.fetchPieceList(page, this.state.pageSize,
|
|
|
|
this.state.search, this.state.orderBy,
|
|
|
|
this.state.orderAsc);
|
2015-05-22 13:58:09 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
tableChangeOrder(orderBy, orderAsc) {
|
2015-05-22 17:11:17 +02:00
|
|
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize,
|
|
|
|
this.state.search, orderBy, orderAsc);
|
2015-05-22 12:58:06 +02:00
|
|
|
},
|
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
render() {
|
2015-05-21 16:02:42 +02:00
|
|
|
let columnList = [
|
2015-05-22 16:51:08 +02:00
|
|
|
new TableColumnContentModel('thumbnail', '', TableItemImg, 2, false),
|
|
|
|
new TableColumnContentModel('artist_name', 'Artist', TableItemText, 4, true),
|
|
|
|
new TableColumnContentModel('title', 'Title', TableItemText, 4, true)
|
2015-05-21 16:02:42 +02:00
|
|
|
];
|
2015-05-20 19:19:57 +02:00
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
let currentPage = parseInt(this.props.query.page, 10);
|
|
|
|
let totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize)
|
|
|
|
|
2015-05-22 13:43:53 +02:00
|
|
|
// Could wrap this altContainer potentially once again.
|
2015-05-19 17:13:09 +02:00
|
|
|
return (
|
2015-05-22 13:43:53 +02:00
|
|
|
<AltContainer
|
2015-05-22 16:51:08 +02:00
|
|
|
store={PieceListStore}
|
2015-05-22 11:33:38 +02:00
|
|
|
transform={(props) => {
|
|
|
|
return {
|
|
|
|
'itemList': props.pieceList,
|
2015-05-22 13:43:53 +02:00
|
|
|
'itemListCount': props.pieceListCount,
|
2015-05-22 11:33:38 +02:00
|
|
|
'orderBy': props.orderBy,
|
|
|
|
'orderAsc': props.orderAsc,
|
|
|
|
'search': props.search,
|
|
|
|
'page': props.page,
|
2015-05-22 16:51:08 +02:00
|
|
|
'pageSize': props.pageSize,
|
2015-05-22 11:33:38 +02:00
|
|
|
}
|
2015-05-22 11:25:21 +02:00
|
|
|
}}>
|
2015-05-22 16:51:08 +02:00
|
|
|
<Table columnList={columnList} changeOrder={this.tableChangeOrder}>
|
2015-05-22 18:41:15 +02:00
|
|
|
<TableItemSubtable store={EditionListStore} actions={EditionListActions}></TableItemSubtable>
|
2015-05-22 14:15:12 +02:00
|
|
|
</Table>
|
2015-05-22 17:11:17 +02:00
|
|
|
<Pagination currentPage={currentPage}
|
|
|
|
totalPages={totalPages}
|
|
|
|
goToPage={this.paginationGoToPage} />
|
2015-05-20 11:32:56 +02:00
|
|
|
</AltContainer>
|
2015-05-19 17:13:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PieceList;
|