1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/stores/piece_list_store.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
import alt from '../alt';
import PieceListActions from '../actions/piece_list_actions';
2015-05-20 16:44:45 +02:00
class PieceListStore {
constructor() {
/**
* The store manages the state that is introduced by fetching
* the resource with certain parameters.
*
* This means that pieceList for example only contains pageSize-many items.
* Of course this can be altered by page as well.
*
* This is also the reason why we store a pieceListCount, which is essentially
* the number of items the resource actually - without pagination - provides.
*/
this.pieceList = [];
this.pieceListCount = 0;
2015-05-21 12:12:25 +02:00
this.page = 1;
this.pageSize = 10;
this.search = '';
this.orderBy = 'artist_name';
2015-05-21 12:12:25 +02:00
this.orderAsc = true;
this.bindActions(PieceListActions);
}
onShowEditionList(pieceId) {
this.pieceList
.forEach((piece) => {
if(piece.id === pieceId) {
if(piece.show) {
piece.show = false;
} else {
piece.show = true;
}
}
});
}
onCloseAllEditionLists() {
this.pieceList
.forEach((piece) => {
piece.show = false;
});
}
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount }) {
this.page = page;
this.pageSize = pageSize;
this.search = search;
2015-05-21 12:12:25 +02:00
this.orderAsc = orderAsc;
this.orderBy = orderBy;
this.pieceListCount = pieceListCount;
/**
* Pagination - Known Issue:
* #########################
*
*
* The piece list store currently stores the open/close state of a piece list item.
*
* Once a new page is requested, this.pieceList will be overwritten, which means that the
* open/close state of a specific list item will be thrown away.
*
* This means that when opening an editionListTable on a piece, and continuing
* clicking next or back in the pagination, the editionListTable will return to its
* default value, which is "close".
*
* We did not implement this, as we're going to add pagination to pieceList at some
* point anyway. Then, this problem is automatically resolved.
*/
this.pieceList = pieceList;
}
}
export default alt.createStore(PieceListStore);