diff --git a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js index 16c69689..86241c76 100644 --- a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js +++ b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js @@ -71,7 +71,11 @@ let PieceListBulkModal = React.createClass({ handleSuccess() { this.fetchSelectedPieceEditionList() .forEach((pieceId) => { - EditionListActions.fetchEditionList(pieceId, this.state.orderBy, this.state.orderAsc); + let editionsForPiece = this.state.editionList[pieceId]; + for(let i = 1; i <= editionsForPiece.page; i++) { + EditionListActions.fetchEditionList(pieceId, i, editionsForPiece.pageSize, editionsForPiece.orderBy, editionsForPiece.orderAsc); + } + }); EditionListActions.clearAllEditionSelections(); }, diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 93afbda6..b8e7cada 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -13,27 +13,28 @@ class EditionListStore { } onUpdateEditionList({pieceId, editionListOfPiece, page, pageSize, orderBy, orderAsc}) { - if(this.editionList[pieceId]) { + - let pageOfCurrentEditionList = this.editionList[pieceId].slice((page - 1) * pageSize, pageSize); - - if(pageOfCurrentEditionList.length < 1) { - // just append newly received editions - console.log('asdasd'); - this.editionList[pieceId].push.apply(this.editionList[pieceId], editionListOfPiece); - } else { - // merge with existing page's editions - pageOfCurrentEditionList.forEach((edition, i) => { + for(let i = 0; i < editionListOfPiece.length; i++) { - if(editionListOfPiece[i]) { - edition = React.addons.update(edition, {$merge: editionListOfPiece[i]}); - } - - this.editionList[pieceId].splice((page - 1) * pageSize + i, 0, edition); - }); + // if editionList for a specific piece does not exist yet, + // just initialize a new array + if(!this.editionList[pieceId]) { + this.editionList[pieceId] = []; + } + + // this is the index formula for accessing an edition of a specific + // page + let storeEditionIndex = (page - 1) * pageSize + i; + let editionsForPieces = this.editionList[pieceId]; + + // if edition already exists, just merge + if(editionsForPieces[storeEditionIndex]) { + editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]}); + } else { + // if does not exist, assign + editionsForPieces[storeEditionIndex] = editionListOfPiece[i]; } - } else { - this.editionList[pieceId] = editionListOfPiece; } /**