2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
import React from 'react';
|
2015-06-16 09:27:04 +02:00
|
|
|
import Router from 'react-router';
|
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-29 16:28:05 +02:00
|
|
|
import AccordionList from './ascribe_accordion_list/accordion_list';
|
|
|
|
import AccordionListItem from './ascribe_accordion_list/accordion_list_item';
|
2015-06-01 11:51:03 +02:00
|
|
|
import AccordionListItemTableEditions from './ascribe_accordion_list/accordion_list_item_table_editions';
|
2015-05-21 16:02:42 +02:00
|
|
|
|
2015-05-27 13:57:11 +02:00
|
|
|
import Pagination from './ascribe_pagination/pagination';
|
|
|
|
|
2015-06-02 09:10:26 +02:00
|
|
|
import PieceListBulkModal from './ascribe_piece_list_bulk_modal/piece_list_bulk_modal';
|
2015-06-02 10:10:09 +02:00
|
|
|
import PieceListToolbar from './ascribe_piece_list_toolbar/piece_list_toolbar';
|
2015-05-19 17:13:09 +02:00
|
|
|
|
2015-06-16 09:57:14 +02:00
|
|
|
import AppConstants from '../constants/application_constants';
|
|
|
|
|
2015-05-20 16:44:45 +02:00
|
|
|
|
2015-05-19 17:16:01 +02:00
|
|
|
let PieceList = React.createClass({
|
2015-06-05 11:06:36 +02:00
|
|
|
propTypes: {
|
|
|
|
query: React.PropTypes.object
|
|
|
|
},
|
|
|
|
|
2015-06-16 09:27:04 +02:00
|
|
|
mixins: [Router.Navigation, Router.State],
|
|
|
|
|
2015-05-21 12:12:25 +02:00
|
|
|
getInitialState() {
|
|
|
|
return PieceListStore.getState();
|
|
|
|
},
|
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
componentDidMount() {
|
2015-05-26 13:52:44 +02:00
|
|
|
let page = this.props.query.page || 1;
|
2015-05-26 11:47:56 +02:00
|
|
|
PieceListStore.listen(this.onChange);
|
2015-06-09 16:10:38 +02:00
|
|
|
if (this.state.pieceList.length === 0){
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2015-05-26 13:14:35 +02:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
2015-05-22 17:11:17 +02:00
|
|
|
},
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
paginationGoToPage(page) {
|
2015-06-05 11:06:36 +02:00
|
|
|
return () => PieceListActions.fetchPieceList(page, this.state.pageSize,
|
2015-05-22 17:11:17 +02:00
|
|
|
this.state.search, this.state.orderBy,
|
|
|
|
this.state.orderAsc);
|
2015-05-22 13:58:09 +02:00
|
|
|
},
|
|
|
|
|
2015-06-16 09:27:04 +02:00
|
|
|
searchFor(searchTerm) {
|
|
|
|
PieceListActions.fetchPieceList(1, this.state.pageSize, searchTerm, this.state.orderBy, this.state.orderAsc);
|
|
|
|
this.transitionTo(this.getPathname(), {page: 1});
|
|
|
|
},
|
|
|
|
|
2015-05-29 16:28:05 +02:00
|
|
|
accordionChangeOrder(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-26 13:52:44 +02:00
|
|
|
let currentPage = parseInt(this.props.query.page, 10) || 1;
|
2015-06-05 11:06:36 +02:00
|
|
|
let totalPages = Math.ceil(this.state.pieceListCount / this.state.pageSize);
|
2015-06-16 09:57:14 +02:00
|
|
|
let loadingElement = (<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_medium.gif'} />);
|
2015-05-29 16:28:05 +02:00
|
|
|
return (
|
2015-06-01 11:51:03 +02:00
|
|
|
<div>
|
2015-06-16 09:57:14 +02:00
|
|
|
<PieceListToolbar
|
2015-06-16 09:27:04 +02:00
|
|
|
className="ascribe-piece-list-toolbar"
|
|
|
|
searchFor={this.searchFor} />
|
2015-06-02 09:10:26 +02:00
|
|
|
<PieceListBulkModal className="ascribe-piece-list-bulk-modal" />
|
2015-05-29 16:28:05 +02:00
|
|
|
<AccordionList
|
2015-06-01 11:51:03 +02:00
|
|
|
className="ascribe-accordion-list"
|
2015-05-29 16:28:05 +02:00
|
|
|
changeOrder={this.accordionChangeOrder}
|
|
|
|
itemList={this.state.pieceList}
|
|
|
|
orderBy={this.state.orderBy}
|
|
|
|
orderAsc={this.state.orderAsc}
|
|
|
|
search={this.state.search}
|
|
|
|
page={this.state.page}
|
2015-06-16 09:57:14 +02:00
|
|
|
pageSize={this.state.pageSize}
|
|
|
|
loadingElement={loadingElement}>
|
2015-05-29 16:28:05 +02:00
|
|
|
{this.state.pieceList.map((item, i) => {
|
|
|
|
return (
|
2015-06-05 11:06:36 +02:00
|
|
|
<AccordionListItem
|
2015-05-29 16:28:05 +02:00
|
|
|
className="col-xs-12 col-sm-10 col-md-8 col-lg-8 col-sm-offset-1 col-md-offset-2 col-lg-offset-2 ascribe-accordion-list-item"
|
|
|
|
content={item}
|
2015-06-01 11:51:03 +02:00
|
|
|
key={i}>
|
2015-06-05 11:06:36 +02:00
|
|
|
<AccordionListItemTableEditions
|
2015-06-04 17:28:14 +02:00
|
|
|
className="ascribe-accordion-list-item-table col-xs-12 col-sm-8 col-md-6 col-lg-6 col-sm-offset-2 col-md-offset-3 col-lg-offset-3"
|
2015-06-12 17:18:40 +02:00
|
|
|
parentId={item.id} />
|
2015-06-01 11:51:03 +02:00
|
|
|
</AccordionListItem>
|
2015-05-29 16:28:05 +02:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</AccordionList>
|
|
|
|
<Pagination
|
|
|
|
currentPage={currentPage}
|
|
|
|
totalPages={totalPages}
|
2015-06-05 11:06:36 +02:00
|
|
|
goToPage={this.paginationGoToPage} />
|
2015-05-29 16:28:05 +02:00
|
|
|
</div>
|
|
|
|
);
|
2015-05-19 17:13:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PieceList;
|