2015-05-26 17:25:03 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-05-21 17:59:38 +02:00
|
|
|
import alt from '../alt';
|
|
|
|
import EditionsListActions from '../actions/edition_list_actions';
|
|
|
|
|
|
|
|
class EditionListStore {
|
|
|
|
constructor() {
|
2015-05-26 13:14:35 +02:00
|
|
|
this.editionList = {};
|
2015-05-21 17:59:38 +02:00
|
|
|
this.bindActions(EditionsListActions);
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:48:48 +02:00
|
|
|
onUpdateEditionList({pieceId, editionListOfPiece}) {
|
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 16:48:48 +02:00
|
|
|
this.editionList[pieceId] = editionListOfPiece;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectEdition({pieceId, editionId}) {
|
|
|
|
|
|
|
|
this.editionList[pieceId].forEach((edition) => {
|
|
|
|
if(edition.edition_number === editionId) {
|
|
|
|
if(edition.selected) {
|
|
|
|
edition.selected = false;
|
|
|
|
} else {
|
|
|
|
edition.selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-21 17:59:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default alt.createStore(EditionListStore);
|