var CrudConfig, TocConfig, _, actions, extendConfig, flux, makeSimpleStore, ref, ref1, store;
flux = require('flux-react');
_ = require('underscore');
ref = require('./helpers'), CrudConfig = ref.CrudConfig, extendConfig = ref.extendConfig, makeSimpleStore = ref.makeSimpleStore;
TocConfig = {
_sections: {},
FAILED: function() {
return console.error('BUG: could not load readings');
},
_reset: function() {
return this._sections = {};
},
_loaded: function(obj, id) {
var chap, chapters, i, j, len, len1, ref1, section;
chapters = obj[0].children;
for (i = 0, len = chapters.length; i < len; i++) {
chap = chapters[i];
ref1 = chap.children;
for (j = 0, len1 = ref1.length; j < len1; j++) {
section = ref1[j];
this._sections[section.id] = section;
}
}
return chapters;
},
exports: {
getChapterSection: function(sectionId) {
var ref1;
return ((ref1 = this._sections[sectionId]) != null ? ref1.chapter_section : void 0) || (function() {
throw new Error('BUG: Invalid section');
})();
},
getSectionInfo: function(sectionId) {
return this._sections[sectionId] || (function() {
throw new Error('BUG: Invalid section');
})();
},
getSectionLabel: function(key) {
return _.find(this._sections, function(section) {
return section.chapter_section.toString() === key;
});
}
}
};
extendConfig(TocConfig, new CrudConfig());
ref1 = makeSimpleStore(TocConfig), actions = ref1.actions, store = ref1.store;
module.exports = {
TocActions: actions,
TocStore: store
};
|