diff options
author | zefanja <zefanja@freenet.de> | 2013-07-17 20:39:35 +0200 |
---|---|---|
committer | zefanja <zefanja@freenet.de> | 2013-07-17 20:39:35 +0200 |
commit | 5b6e0a037365730f161aaebda451671bca4363cf (patch) | |
tree | 5905fe49279b168576f0d64822a66399703c290a /source | |
parent | f544c16ffca8008d9bae5a464cae4f38017aa9e8 (diff) | |
download | biblez-ng-5b6e0a037365730f161aaebda451671bca4363cf.tar.gz |
* added Book and Chapter selector
Diffstat (limited to 'source')
-rw-r--r-- | source/App.css | 19 | ||||
-rw-r--r-- | source/App.js | 28 | ||||
-rw-r--r-- | source/bcSelector.js | 72 | ||||
-rw-r--r-- | source/main.js | 84 | ||||
-rw-r--r-- | source/moduleManager.js | 4 | ||||
-rw-r--r-- | source/package.js | 1 |
6 files changed, 177 insertions, 31 deletions
diff --git a/source/App.css b/source/App.css index e87b7d6..9f17bc1 100644 --- a/source/App.css +++ b/source/App.css @@ -45,4 +45,23 @@ font-weight: bold; font-size: 1.2em; padding: 10px; +} + +/* BOOK CHAPTER SELECTOR */ +.bc-item { + height: 30px; + width: 50px; + margin: 5px; + border: 1px solid #ccc; + padding: 10px 5px 5px 5px; + float: left; + vertical-align: middle; + text-align: center; + font-weight: bold; +} + +/* POPUPs */ +.message-popup { + text-align: center; + padding: 10px; }
\ No newline at end of file diff --git a/source/App.js b/source/App.js index 3bd63fb..9090f99 100644 --- a/source/App.js +++ b/source/App.js @@ -4,33 +4,55 @@ enyo.kind({ fit: true, components: [ {name: "panel", kind: "Panels", fit: true, classes: "app-panels", arrangerKind: "CardArranger", draggable: false, onTransitionFinish: "handlePanels", components: [ - {name: "main", kind: "biblez.main", onOpenModuleManager: "openModuleManager"}, - {name: "moduleManager", kind: "biblez.moduleManager", onBack: "handleBack", onInstalled: "handleInstalledModule"} + {name: "main", kind: "biblez.main", onOpenModuleManager: "openModuleManager", onOpenBC: "openSelector", onModuleChanged: "handleChangeModule"}, + {name: "moduleManager", kind: "biblez.moduleManager", onBack: "handleBack", onInstalled: "handleInstalledModule"}, + {name: "bcSelector", kind: "biblez.bcSelector", onSelect: "handlePassageSelect", onBack: "handleBack"} //{name: "settings"} ]} ], rendered: function () { this.inherited(arguments); - //this.$.panel.setIndex(0); + //this.$.panel.setIndex(1); }, handlePanels: function (inSender, inEvent) { if(inEvent.toIndex === 1) { this.$.moduleManager.start(); } + return true; }, handleBack: function (inSender, inEvent) { this.$.panel.setIndex(0); + return true; }, handleInstalledModule: function (inSender, inEvent) { this.$.main.getInstalledModules(); + return true; }, openModuleManager: function (inSender, inEvent) { this.$.panel.setIndex(1); + return true; + }, + + openSelector: function (inSender, inEvent) { + this.$.panel.setIndex(2); + this.$.bcSelector.setPanel(0); + return true; + }, + + handleChangeModule: function (inSender, inEvent) { + this.$.bcSelector.setModule(inEvent.module); + return true; + }, + + handlePassageSelect: function (inSender, inEvent) { + this.$.panel.setIndex(0); + delete inEvent.originator; + this.$.main.setPassage(inEvent); } }); diff --git a/source/bcSelector.js b/source/bcSelector.js new file mode 100644 index 0000000..d2da696 --- /dev/null +++ b/source/bcSelector.js @@ -0,0 +1,72 @@ +enyo.kind({ + name: "biblez.bcSelector", + kind: "enyo.FittableRows", + events: { + onSelect: "", + onBack: "" + }, + published: { + module: null + }, + components: [ + {name: "bcPanel", kind: "Panels", arrangerKind: "CardArranger", fit: true, components: [ + {name: "bookPanel", kind: "enyo.FittableRows", components: [ + {kind: "onyx.Toolbar", components: [ + {kind: "onyx.IconButton", src: "assets/back.png", ontap: "doBack"}, + {content: $L("Books")} + ]}, + {kind: "enyo.Scroller", fit: true, touch: true, components: [ + {name: "bookRepeater", kind: "Repeater", count: 0, onSetupItem: "setBookItems", components: [ + {name: "bookItem", classes: "bc-item", ontap: "handleBook"} + ]} + ]} + ]}, + {name: "chapterPanel", kind: "enyo.FittableRows", components: [ + {kind: "onyx.Toolbar", components: [ + {kind: "onyx.IconButton", src: "assets/back.png", ontap: "handleBack"}, + {content: $L("Chapters")} + ]}, + {kind: "enyo.Scroller", fit: true, touch: true, components: [ + {name: "chapterRepeater", kind: "Repeater", count: 0, onSetupItem: "setChapterItems", components: [ + {name: "chapterItem", classes: "bc-item", ontap: "handleChapter"} + ]} + ]} + ]} + ]} + + ], + + books: [], + currentBook: null, + + setPanel: function (index) { + this.$.bcPanel.setIndex(index); + }, + + handleBack: function (inSender, inEvent) { + this.$.bcPanel.setIndex(0) + }, + + moduleChanged: function (inSender, inEvent) { + this.books = this.module.getAllBooks(); + this.$.bookRepeater.setCount(this.books.length); + }, + + setBookItems: function (inSender, inEvent) { + inEvent.item.$.bookItem.setContent(this.books[inEvent.index].abbrev.slice(0,4)); + }, + + handleBook: function (inSender, inEvent) { + this.currentBook = this.books[inEvent.index]; + this.$.chapterRepeater.setCount(this.currentBook.maxChapter); + this.$.bcPanel.setIndex(1); + }, + + setChapterItems: function (inSender, inEvent) { + inEvent.item.$.chapterItem.setContent(inEvent.index+1); + }, + + handleChapter: function (inSender, inEvent) { + this.doSelect({book: this.currentBook, chapter: inEvent.index+1, osis: this.currentBook.abbrev + "." + (inEvent.index+1)}); + } +});
\ No newline at end of file diff --git a/source/main.js b/source/main.js index 02f774d..4f25dcb 100644 --- a/source/main.js +++ b/source/main.js @@ -3,18 +3,25 @@ enyo.kind({ kind: "FittableRows", fit: true, events: { - onOpenModuleManager: "" + onOpenModuleManager: "", + onModuleChanged: "", + onOpenBC: "" + }, + published: { + passage: "" }, components:[ //{kind: "Signals", onSwordReady: "getBible"}, + {name: "messagePopup", kind: "onyx.Popup", centered: true, floating: true, classes: "message-popup"}, {kind: "onyx.MoreToolbar", components: [ {kind: "onyx.MenuDecorator", onSelect: "moduleSelected", components: [ {kind: "onyx.IconButton", src: "assets/modules.png"}, {kind: "onyx.Menu", name: "moduleMenu"} ]}, - {kind: "onyx.InputDecorator", components: [ + {kind: "onyx.Button", name: "btnPassage", ontap: "doOpenBC"} + /*{kind: "onyx.InputDecorator", components: [ {kind: "onyx.Input", placeholder: "Enter a passage...", onchange: "handlePassage", name: "passageInput", value: "Matt 1"} - ]} + ]}*/ ]}, {kind: "enyo.Scroller", touch: true, fit: true, components: [ {kind: "onyx.Spinner", name: "spinner", classes: "onyx-light"}, @@ -29,6 +36,7 @@ enyo.kind({ ], currentModule: null, + currentPassage: "Matt 1", modules: [], create: function () { @@ -43,27 +51,32 @@ enyo.kind({ getInstalledModules: function (inSender, inEvent) { sword.moduleMgr.getModules(enyo.bind(this, function(inError, inModules) { - if(inModules.length !== 0) { - this.currentModule = inModules[0]; - this.handlePassage(); - //this.$.moduleLabel.setContent(this.currentModule.config.moduleKey); - this.modules = inModules; - var mods = []; - this.modules.forEach(enyo.bind(this, function (mod, idx) { - if (this.currentModule.modKey === mod.modKey || idx === 0) - mods.push({content: mod.config.moduleKey, index: idx, active: true}); - else - mods.push({content: mod.config.moduleKey, index: idx}); - })); - this.$.moduleMenu.createComponents(mods, {owner: this.$.moduleMenu}); - this.$.moduleMenu.render(); - } + if (!inError) { + if(inModules.length !== 0) { + this.currentModule = inModules[0]; + this.doModuleChanged({module: this.currentModule}); + this.handlePassage(); + //this.$.moduleLabel.setContent(this.currentModule.config.moduleKey); + this.modules = inModules; + var mods = []; + this.modules.forEach(enyo.bind(this, function (mod, idx) { + if (this.currentModule.modKey === mod.modKey || idx === 0) + mods.push({content: mod.config.moduleKey, index: idx, active: true}); + else + mods.push({content: mod.config.moduleKey, index: idx}); + })); + this.$.moduleMenu.createComponents(mods, {owner: this.$.moduleMenu}); + this.$.moduleMenu.render(); + } + } else { + this.handleError(inError); + } })); }, moduleSelected: function (inSender, inEvent) { this.currentModule = this.modules[inEvent.originator.index]; - //this.$.moduleLabel.setContent(this.currentModule.config.moduleKey); + this.doModuleChanged({module: this.currentModule}); this.handlePassage(); }, @@ -84,8 +97,11 @@ enyo.kind({ if(!inError) { self.$.main.setContent(enyo.json.stringify(inModule.config)); self.$.moduleLabel.setContent(inModule.config.moduleKey); - } + } else + this.handleError(inError); }); + else + this.handleError(inError); }); }, @@ -93,13 +109,27 @@ enyo.kind({ sword.dataMgr.clearDatabase(); }, - handlePassage: function (inSender, inEvent) { + passageChanged: function (inSender, inEvent) { + this.currentPassage = inEvent.book.abbrev + " " + inEvent.chapter; + this.handlePassage(inEvent.osis); + }, + + handlePassage: function (passage) { //console.log("PASSAGE", inSender.getValue()); - if(!inSender) - inSender = this.$.passageInput; - this.currentModule.renderText(inSender.getValue(), {oneVersePerLine: true}, enyo.bind(this, function (inError, inText) { - //console.log(inError, inText); - this.$.main.setContent(inText); + if(!passage) + passage = this.currentPassage; + this.$.btnPassage.setContent(this.currentPassage); + this.currentModule.renderText(passage, {oneVersePerLine: true}, enyo.bind(this, function (inError, inText) { + console.log(inError); + if(!inError) + this.$.main.setContent(inText); + else + this.handleError(inError); })); - } + }, + + handleError: function (inMessage) { + this.$.messagePopup.setContent(inMessage); + this.$.messagePopup.show(); + } }); diff --git a/source/moduleManager.js b/source/moduleManager.js index 8efbce7..13f7646 100644 --- a/source/moduleManager.js +++ b/source/moduleManager.js @@ -205,7 +205,9 @@ enyo.kind({ this.$.progressBar.show(); this.$.bottomTB.render(); sword.installMgr.installModule(this.currentModule.url, enyo.bind(this, function (inError, inModule) { - this.doInstalled(); + if (!inError) { + this.doInstalled(); + } //console.log(inError, inModule); this.$.progressBar.hide(); this.$.progressBar.setProgress(0); diff --git a/source/package.js b/source/package.js index 55f9dde..d4fb8c7 100644 --- a/source/package.js +++ b/source/package.js @@ -6,6 +6,7 @@ enyo.depends( "App.css", "api.js", "mapping.js", + "bcSelector.js", "main.js", "moduleManager.js", "App.js" |