2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
import alt from '../alt';
|
2015-07-24 13:44:28 +02:00
|
|
|
import Q from 'q';
|
2015-05-21 17:59:38 +02:00
|
|
|
|
2015-05-19 17:13:09 +02:00
|
|
|
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
|
|
|
|
|
|
|
class PieceListActions {
|
|
|
|
constructor() {
|
|
|
|
this.generateActions(
|
2015-07-01 19:05:47 +02:00
|
|
|
'updatePieceList',
|
2015-07-09 15:44:20 +02:00
|
|
|
'updatePieceListRequestActions',
|
2015-07-10 13:54:25 +02:00
|
|
|
'updatePropertyForPiece'
|
2015-05-19 17:13:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:33:38 +02:00
|
|
|
fetchPieceList(page, pageSize, search, orderBy, orderAsc) {
|
2015-07-13 19:12:24 +02:00
|
|
|
// To prevent flickering on a pagination request,
|
|
|
|
// we overwrite the piecelist with an empty list before
|
|
|
|
// pieceListCount === -1 defines the loading state
|
|
|
|
this.actions.updatePieceList({
|
|
|
|
page,
|
|
|
|
pageSize,
|
|
|
|
search,
|
|
|
|
orderBy,
|
|
|
|
orderAsc,
|
|
|
|
'pieceList': [],
|
|
|
|
'pieceListCount': -1
|
|
|
|
});
|
|
|
|
|
|
|
|
// afterwards, we can load the list
|
|
|
|
|
2015-07-24 13:44:28 +02:00
|
|
|
return Q.Promise((resolve, reject) => {
|
2015-07-01 19:05:47 +02:00
|
|
|
PieceListFetcher
|
|
|
|
.fetch(page, pageSize, search, orderBy, orderAsc)
|
|
|
|
.then((res) => {
|
|
|
|
this.actions.updatePieceList({
|
|
|
|
page,
|
|
|
|
pageSize,
|
|
|
|
search,
|
|
|
|
orderBy,
|
|
|
|
orderAsc,
|
|
|
|
'pieceList': res.pieces,
|
|
|
|
'pieceListCount': res.count
|
|
|
|
});
|
|
|
|
resolve();
|
2015-07-07 09:22:46 +02:00
|
|
|
})
|
|
|
|
.catch((err) => reject(err));
|
2015-07-01 19:05:47 +02:00
|
|
|
});
|
|
|
|
}
|
2015-07-09 15:44:20 +02:00
|
|
|
|
2015-07-01 19:05:47 +02:00
|
|
|
fetchPieceRequestActions() {
|
2015-05-21 17:59:38 +02:00
|
|
|
PieceListFetcher
|
2015-07-01 19:05:47 +02:00
|
|
|
.fetchRequestActions()
|
2015-05-19 17:13:09 +02:00
|
|
|
.then((res) => {
|
2015-07-01 19:05:47 +02:00
|
|
|
this.actions.updatePieceListRequestActions(res.piece_ids);
|
2015-07-17 15:41:09 +02:00
|
|
|
})
|
|
|
|
.catch((err) => console.logGlobal(err));
|
2015-05-19 17:13:09 +02:00
|
|
|
}
|
2015-06-05 11:06:36 +02:00
|
|
|
}
|
2015-05-19 17:13:09 +02:00
|
|
|
|
|
|
|
export default alt.createActions(PieceListActions);
|