1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/stores/edition_store.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
import { alt } from '../alt';
import EditionActions from '../actions/edition_actions';
import EditionSource from '../sources/edition_source';
import CoaSource from '../sources/coa_source';
2015-05-26 13:48:46 +02:00
class EditionStore {
constructor() {
this.edition = {};
this.editionMeta = {
err: null,
idToFetch: null
};
this.coaMeta = {
err: null
};
this.bindActions(EditionActions);
this.registerAsync(Object.assign(EditionSource, CoaSource));
}
onFetchEdition(idToFetch) {
this.editionMeta.idToFetch = idToFetch;
this.getInstance().lookupEdition();
}
onSuccessFetchEdition(res) {
if(res && res.edition) {
this.edition = res.edition;
this.editionMeta.err = null;
this.editionMeta.idToFetch = null;
if (this.edition.coa && this.edition.acl.acl_coa &&
typeof this.edition.coa.constructor !== Object) {
this.getInstance().lookupCoa();
} else if(!this.edition.coa && this.edition.acl.acl_coa) {
this.getInstance().performCreateCoa();
}
} else {
this.editionMeta.err = new Error('Problem fetching the edition');
}
}
onSuccessFetchCoa(res) {
if (res && res.coa && Object.keys(this.edition).length) {
this.edition.coa = res.coa;
this.coaMeta.err = null;
} else {
this.coaMeta.err = new Error('Problem generating/fetching the COA');
}
}
onFlushEdition() {
this.edition = {};
this.editionMeta = {
err: null,
idToFetch: null
};
this.coaMeta = {
err: null
};
}
onErrorEdition(err) {
this.editionMeta.err = err;
2015-10-19 15:29:57 +02:00
}
onErrorCoa(err) {
this.coaMeta.err = err;
}
}
2015-06-15 08:44:44 +02:00
export default alt.createStore(EditionStore, 'EditionStore');