aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
m---------enyo0
m---------lib/layout0
m---------lib/onyx0
m---------lib/sword0
-rw-r--r--manifest.webapp32
-rw-r--r--source/App.js2
-rw-r--r--source/api.js83
-rw-r--r--source/main.js36
-rw-r--r--source/moduleManager.js92
9 files changed, 152 insertions, 93 deletions
diff --git a/enyo b/enyo
-Subproject 18900f707862b2a613a24a968a4ce237fd36c6e
+Subproject 075b2d18d18f6bf28d64a395b8641e1fbb2f29c
diff --git a/lib/layout b/lib/layout
-Subproject 9c704f64440f18565f2141832896eaa820096e2
+Subproject d5e9ec0b325eec48a0d7d79b8d73c9660ec3cec
diff --git a/lib/onyx b/lib/onyx
-Subproject 461c63db09ae717c35ae979d145fd5111a90259
+Subproject 59539a0d5b3c8b344292c5297e3de273a7e6112
diff --git a/lib/sword b/lib/sword
-Subproject b42356245eed77278de3b0a1e495510f4316631
+Subproject 3dfa361f899e86da709ea77dc9f2cf6d7825b40
diff --git a/manifest.webapp b/manifest.webapp
index 7b56689..030977b 100644
--- a/manifest.webapp
+++ b/manifest.webapp
@@ -1,19 +1,19 @@
{
- "name": "BibleZ Debug",
- "description": "Read and study the Bible!",
- "launch_path": "/debug.html",
- "icons": {
- "128": "/assets/biblez128.png"
- },
- "developer": {
- "name": "zefanjas",
- "url": "http://zefanjas.de"
- },
- "default_locale": "en",
- "type": "privileged",
- "permissions": {
- "systemXHR": {
- "description": "Required to download CrossWire's bible modules"
- }
+ "name": "BibleZ Debug",
+ "description": "Read and study the Bible!",
+ "launch_path": "/debug.html",
+ "icons": {
+ "128": "/assets/biblez128.png"
+ },
+ "developer": {
+ "name": "zefanjas",
+ "url": "http://zefanjas.de"
+ },
+ "default_locale": "en",
+ "type": "privileged",
+ "permissions": {
+ "systemXHR": {
+ "description": "Required to download CrossWire's bible modules"
}
+ }
} \ No newline at end of file
diff --git a/source/App.js b/source/App.js
index 3910634..aa3b787 100644
--- a/source/App.js
+++ b/source/App.js
@@ -67,4 +67,4 @@ enyo.kind({
window.screen.onmozorientationchange = function () {
enyo.Signals.send("onOrientationChange");
};
-
+enyo.dispatcher.listen(window, "beforeunload");
diff --git a/source/api.js b/source/api.js
index 1d465da..bcc3c71 100644
--- a/source/api.js
+++ b/source/api.js
@@ -1,42 +1,59 @@
var api = {
- /* Set the value of item[key] to the stringified version of obj. */
- set: function(name, obj){
- localStorage.setItem(name, JSON.stringify(obj));
- },
-
- /* Get the item with the key 'name'. */
- get: function(name){
- var result;
- if(typeof name === "string") {
- result = localStorage.getItem(name);
- }
+ isInitialized: false,
+ db: null,
- if(typeof result === "string"){
- return JSON.parse(result);
- } else if(typeof result === "object" && result !== null) {
- enyo.log("OBJECT: " + result);
- throw "ERROR [Storage.get]: getItem returned an object. Should be a string.";
- } else if(typeof result === "undefined" || result === null){
- //throw "ERROR: [Storage.get]: getItem returned a falsey value. Should be a string.";
- return result;
+ //Wraps the initialization of the IndexedDB Wrapper function
+ wrapper: function (inCallback) {
+ //console.log("isInitialized...", this.isInitialized);
+ if (this.isInitialized) {
+ inCallback(null, db);
+ } else {
+ var store = sword.dataMgr.getIDBWrapper();
+ var self = this;
+ db = new store({
+ storeName: "biblez",
+ dbVersion: 1,
+ /*indexes: [
+ {name: "modules", keyPath: "moduleKey", unique: true}
+ ],*/
+ onStoreReady: function() {
+ //console.log("isInitialized", self.isInitialized);
+ self.isInitialized = true;
+ if(inCallback) inCallback(null, db);
+ },
+ onError: function(inError) {
+ self.isInitialized = false;
+ if(inCallback) inCallback(inError);
+ }
+ });
}
},
- /* Remove the item with the key 'name'. */
- remove: function(name){
- if(typeof name === "string") {
- localStorage.removeItem(name);
- } else {
- throw "ERROR [Storage.remove]: 'name' was not a String.";
- }
+ put: function (inObject, inCallback) {
+ this.wrapper(function (inError, inDB) {
+ inDB.put(inObject,
+ function (inId) {
+ if(inCallback) inCallback(null, inId);
+ },
+ function (inError) {
+ if(inCallback) inCallback(inError);
+ }
+ );
+ });
},
- /* Returns length of all localStorage objects. */
- __getSize: function(){
- var i, count = 0;
- for(i = 0; i < localStorage.length; i++){
- count += localStorage.getItem(localStorage.key()).length;
- }
- return count;
+ get: function (inId, inCallback) {
+ this.wrapper(function (inError, inDB) {
+ inDB.get(inId,
+ function (inObject) {
+ if(inCallback) inCallback(null, inObject);
+ },
+ function (inError) {
+ if(inCallback) inCallback(inError);
+ }
+ );
+ });
}
+
+
}; \ No newline at end of file
diff --git a/source/main.js b/source/main.js
index fe5ec98..f38143a 100644
--- a/source/main.js
+++ b/source/main.js
@@ -12,6 +12,7 @@ enyo.kind({
},
components:[
{kind: "Signals", onOrientationChange: "handleOrientation"},
+ {kind: "Signals", onbeforeunload: "handleUnload"},
{name: "messagePopup", kind: "onyx.Popup", centered: true, floating: true, classes: "message-popup"},
{kind: "onyx.MoreToolbar", name: "topTB", components: [
{kind: "onyx.MenuDecorator", onSelect: "moduleSelected", components: [
@@ -52,11 +53,20 @@ enyo.kind({
currentPassage: "Matt 1",
modules: [],
panelIndex: 2,
+ settings: {id: "settings"},
create: function () {
this.inherited(arguments);
this.$.spinner.stop();
- this.getInstalledModules();
+ api.get("settings", enyo.bind(this, function(inError, inSettings) {
+ //console.log("create", inSettings, this.settings, inError);
+ if(!inError) {
+ this.settings = (inSettings) ? inSettings: this.settings;
+ this.getInstalledModules();
+ } else {
+ this.handleError("Couldn't load settings!");
+ }
+ }));
this.$.mainPanel.setIndexDirect(2);
},
@@ -82,7 +92,8 @@ enyo.kind({
renderModuleMenu: function (inModules) {
if(!inModules)
inModules = this.modules;
- var lastModule = api.get("lastModule");
+ if(this.settings)
+ var lastModule = this.settings.lastModule;
this.$.moduleMenu.destroyClientControls();
var mods = [];
this.modules.forEach(enyo.bind(this, function (mod, idx) {
@@ -104,14 +115,20 @@ enyo.kind({
this.$.moduleMenu.render();
this.doModuleChanged({module: this.currentModule});
+
+ //Load the verses
+ if(this.settings)
+ this.currentPassage = (this.settings.lastRead) ? this.settings.lastRead : this.currentPassage;
this.handlePassage();
},
moduleSelected: function (inSender, inEvent) {
- //console.log(inEvent.originator.index);
+ //console.log(inEvent.originator.index, this.settings);
if (!isNaN(inEvent.originator.index)) {
this.currentModule = this.modules[inEvent.originator.index];
- api.set("lastModule", this.currentModule.modKey);
+ this.settings["lastModule"] = this.currentModule.modKey;
+ console.log(this.settings);
+ this.handleUnload();
this.renderModuleMenu();
//this.doModuleChanged({module: this.currentModule});
//this.handlePassage();
@@ -154,6 +171,12 @@ enyo.kind({
this.$.spinner.start();
this.currentPassage = (!passage) ? this.currentPassage : passage;
+ console.log(this.currentPassage);
+
+ //Persist current passage
+ this.settings["lastRead"] = this.currentPassage;
+ this.handleUnload();
+
this.$.btnPassage.setContent(this.currentPassage.replace(".", " "));
this.currentModule.renderText(this.currentPassage, {oneVersePerLine: true}, enyo.bind(this, function (inError, inText) {
this.$.spinner.stop();
@@ -190,6 +213,11 @@ enyo.kind({
}
},
+ handleUnload: function (inSender, inEvent) {
+ console.log("unload", this.settings);
+ api.put(this.settings);
+ },
+
handleError: function (inMessage) {
this.$.messagePopup.setContent(inMessage);
this.$.messagePopup.show();
diff --git a/source/moduleManager.js b/source/moduleManager.js
index cb83df0..d0a6dfc 100644
--- a/source/moduleManager.js
+++ b/source/moduleManager.js
@@ -61,18 +61,15 @@ enyo.kind({
langModules: [],
currentModule: null,
- rendered: function () {
- this.inherited(arguments);
-
- },
-
start: function () {
if (!this.started) {
this.$.scrim.show();
- if (!api.get("lastRepoUpdate"))
- this.getRepos();
- else
- this.setupRepoPicker();
+ api.get("repos", enyo.bind(this, function (inError, inData) {
+ if(!inData)
+ this.getRepos();
+ else
+ this.setupRepoPicker(inData.repos, inData.currentRepo);
+ }));
}
this.started = true;
},
@@ -92,32 +89,38 @@ enyo.kind({
this.$.modList.setCount(0);
this.$.modList.refresh();
this.$.panel.setIndex(0);
- api.set("currentRepo", this.repos[inEvent.selected.index]);
+ api.get("repos", enyo.bind(this, function(inError, inRepos) {
+ if(!inError) {
+ inRepos["currentRepo"] = this.repos[inEvent.selected.index];
+ api.put(inRepos);
+ } else
+ this.handleError(inError);
+ }));
this.getRemoteModules(this.repos[inEvent.selected.index]);
},
getRepos: function () {
sword.installMgr.getRepositories(enyo.bind(this, function (inError, inRepos) {
if (!inError) {
- api.set("repos", inRepos);
- api.set("lastRepoUpdate", {time: new Date().getTime()});
- this.setupRepoPicker(inRepos);
+ api.put({id: "repos", repos: inRepos, lastRepoUpdate: {time: new Date().getTime()}},
+ enyo.bind(this, function (inError, inId) {
+ if(!inError)
+ this.setupRepoPicker(inRepos);
+ else
+ this.handleError(inError);
+ })
+ );
+
} else {
- this.handleError((inError.message) ? inError.message : inError);
+ this.handleError(inError);
}
}));
},
- setupRepoPicker: function (inRepos) {
- //console.log("setupRepoPicker", inRepos);
- if(!inRepos) {
- inRepos = api.get("repos");
- }
-
+ setupRepoPicker: function (inRepos, currentRepo) {
var items = [],
cw = null;
- var currentRepo = api.get("currentRepo");
- inRepos.forEach(function(repo,idx) {
+ inRepos.forEach(function(repo, idx) {
if ((currentRepo && repo.name === currentRepo.name) || repo.name === "CrossWire") {
items.push({content: repo.name, index: idx, active: true});
cw = repo;
@@ -128,30 +131,39 @@ enyo.kind({
this.$.repoPicker.createComponents(items, {owner: this});
this.$.repoPicker.render();
- if(currentRepo) this.getRemoteModules(currentRepo);
- else this.getRemoteModules(cw);
+ if (currentRepo)
+ this.getRemoteModules(currentRepo);
+ else
+ this.getRemoteModules(cw);
},
getRemoteModules: function (inRepo) {
//console.log(inRepo);
- var currentModules = api.get("currentModules");
- if(currentModules && inRepo.name === currentModules.name) {
- this.modules = currentModules.modules;
- this.prepareLangList(this.modules);
- } else {
- sword.installMgr.getModules(inRepo, enyo.bind(this, function (inError, inModules) {
- //enyo.log(inError, inModules, inModules.length);
- if(!inError) {
- api.set("currentModules", {modules: inModules, name: inRepo.name});
- this.modules = inModules;
- //this.$.langList.setCount(inModules.length);
+ api.get("currentModules", enyo.bind(this, function (inError, currentModules) {
+ if(!inError) {
+ if(currentModules && inRepo.name === currentModules.name) {
+ this.modules = currentModules.modules;
this.prepareLangList(this.modules);
-
} else {
- this.handleError((inError.message) ? inError.message : inError);
+ sword.installMgr.getModules(inRepo, enyo.bind(this, function (inError, inModules) {
+ //enyo.log(inError, inModules, inModules.length);
+ if(!inError) {
+ api.put({id: "currentModules", modules: inModules, name: inRepo.name}, enyo.bind(this, function (inError, inId) {
+ if(inError)
+ this.handleError(inError);
+ }));
+ this.modules = inModules;
+ this.prepareLangList(this.modules);
+
+ } else {
+ this.handleError((inError.message) ? inError.message : inError);
+ }
+ }));
}
- }));
- }
+ } else
+ this.handleError(inError);
+ }));
+
},
prepareLangList: function (inModules) {
@@ -232,6 +244,8 @@ enyo.kind({
},
handleError: function (inMessage) {
+ if (inMessage.message)
+ inMessage = inMessage.message;
this.$.messagePopup.setContent(inMessage);
this.$.messagePopup.show();
}