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

62 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-26 17:25:03 +02:00
import React from 'react';
import alt from '../alt';
import EditionsListActions from '../actions/edition_list_actions';
class EditionListStore {
constructor() {
2015-05-26 13:14:35 +02:00
this.editionList = {};
this.bindActions(EditionsListActions);
}
onUpdateEditionList({pieceId, editionListOfPiece, orderBy, orderAsc}) {
2015-05-26 17:25:03 +02:00
if(this.editionList[pieceId]) {
this.editionList[pieceId].forEach((edition, i) => {
// This uses the index of the new editionList for determining the edition.
// If the list of editions can be sorted in the future, this needs to be changed!
editionListOfPiece[i] = React.addons.update(edition, {$merge: editionListOfPiece[i]});
});
2015-05-26 17:25:03 +02:00
}
2015-05-26 16:48:48 +02:00
this.editionList[pieceId] = editionListOfPiece;
/**
* orderBy and orderAsc are specific to a single list of editons
* therefore they need to be saved in relation to their parent-piece.
*
* Default values for both are set in the editon_list-actions.
*/
this.editionList[pieceId].orderBy = orderBy;
this.editionList[pieceId].orderAsc = orderAsc;
2015-05-26 16:48:48 +02:00
}
onSelectEdition({pieceId, editionId}) {
this.editionList[pieceId].forEach((edition) => {
2015-06-01 14:10:11 +02:00
if(edition.id === editionId) {
2015-05-26 16:48:48 +02:00
if(edition.selected) {
edition.selected = false;
} else {
edition.selected = true;
}
}
});
}
2015-06-01 15:12:31 +02:00
onClearAllEditionSelections() {
Object
.keys(this.editionList)
.forEach((pieceId) => {
this.editionList[pieceId]
.forEach((edition) => {
try {
delete edition.selected;
} catch(err) {
//just ignore
}
});
});
}
}
export default alt.createStore(EditionListStore);