aboutsummaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/App.css13
-rw-r--r--source/App.js33
-rw-r--r--source/api.js102
-rw-r--r--source/main.js83
-rw-r--r--source/notes.js88
-rw-r--r--source/package.js1
-rw-r--r--source/popup.js38
-rw-r--r--source/settings.js6
8 files changed, 339 insertions, 25 deletions
diff --git a/source/App.css b/source/App.css
index ce8b96e..0c4a1fb 100644
--- a/source/App.css
+++ b/source/App.css
@@ -69,6 +69,10 @@
padding: 5px;
}
+.menu-label {
+ margin-left: 10px;
+}
+
/* MODULE MANAGER */
.item {
@@ -210,6 +214,15 @@ h3, h1 {
padding: 5px;
}
+/* NOTES */
+.note-input {
+ text-align: left;
+}
+
+.note-popup {
+ max-width: 300px;
+}
+
/* OVERRIDE SOME ONYX SETTINGS */
.onyx-toolbar {
padding: 5px;
diff --git a/source/App.js b/source/App.js
index b07b7f4..f324232 100644
--- a/source/App.js
+++ b/source/App.js
@@ -10,12 +10,13 @@ enyo.kind({
kind: enyo.FittableRows,
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", onOpenBC: "openSelector", onModuleChanged: "handleChangeModule", onOpenPreferences: "openPreferences"},
+ {name: "panel", kind: "Panels", fit: true, animate: false, classes: "app-panels", arrangerKind: "CardArranger", draggable: false, onTransitionFinish: "handlePanels", components: [
+ {name: "main", kind: "biblez.main", onOpenModuleManager: "openModuleManager", onOpenBC: "openSelector", onModuleChanged: "handleChangeModule", onOpenPreferences: "openPreferences", onOpenNotes: "openNotes"},
{name: "moduleManager", kind: "biblez.moduleManager", onBack: "handleBack", onInstalled: "handleInstalledModule"},
{name: "bcSelector", kind: "biblez.bcSelector", onSelect: "handlePassageSelect", onBack: "handleBack"},
{name: "moduleManagerDesktop", kind: "biblez.moduleManagerDesktop", onBack: "handleBack", onInstalled: "handleInstalledModule"},
- {name: "settings", kind: "biblez.settings", onBack: "handleBack", onChange: "handleSettings"}
+ {name: "settings", kind: "biblez.settings", onBack: "handleBack", onChange: "handleSettings"},
+ {name: "notes", kind: "biblez.notes", onBack: "handleBack", onChange: "handleNote"}
]}
],
@@ -56,6 +57,17 @@ enyo.kind({
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);
+ },
+
openPreferences: function (inSender, inEvent) {
this.$.settings.setSettings();
this.$.panel.setIndex(4);
@@ -65,15 +77,16 @@ enyo.kind({
this.$.main.handleSettings(inSender, inEvent);
},
- handleChangeModule: function (inSender, inEvent) {
- this.$.bcSelector.setModule(inEvent.module);
- return true;
+ openNotes: function (inSender, inEvent) {
+ this.$.notes.setOsisRef(inEvent.osisRef);
+ this.$.notes.setNoteId(inEvent.noteId);
+ this.$.notes.setFocus();
+ this.$.panel.setIndex(5);
},
- handlePassageSelect: function (inSender, inEvent) {
- this.$.panel.setIndex(0);
- delete inEvent.originator;
- this.$.main.setPassage(inEvent);
+ handleNote: function (inSender, inEvent) {
+ this.$.main.handleNote(inSender, inEvent);
+ return true;
}
});
diff --git a/source/api.js b/source/api.js
index cea1884..832114c 100644
--- a/source/api.js
+++ b/source/api.js
@@ -79,6 +79,29 @@ var api = {
}
},
+ noteWrapper: function (inCallback) {
+ //console.log("isInitialized...", this.isHlInitialized);
+ if (this.isNoteInitialized) {
+ inCallback(null, this.noteStore);
+ } else {
+ var self = this;
+ this.noteStore = new this.store({
+ storeName: "notes",
+ keyPath: 'id',
+ autoIncrement: true,
+ dbVersion: 1,
+ onStoreReady: function() {
+ self.isNoteInitialized = true;
+ if(inCallback) inCallback(null, self.noteStore);
+ },
+ onError: function(inError) {
+ self.isNoteInitialized = false;
+ if(inCallback) inCallback(inError);
+ }
+ });
+ }
+ },
+
//Put something in the ObjectStores
_put: function (inDB, inObject, inCallback) {
//console.log("Put this:", inDB, inObject);
@@ -141,6 +164,41 @@ var api = {
}));
},
+ putNote: function (inObject, inCallback) {
+ this.noteWrapper(enyo.bind(this, function (inError, inDB) {
+ if(!inError)
+ if(!inObject.id) {
+ //save a new note
+ delete inObject["id"];
+ this._put(inDB, inObject, enyo.bind(this, function(inError, inId) {
+ if(!inError)
+ this.get(inObject.osisRef, enyo.bind(this, function(inError, inOsisObject) {
+ if(!inError) {
+ if(inOsisObject === undefined)
+ inOsisObject = {id: inObject.osisRef};
+ inOsisObject["noteId"] = inId;
+ this.put(inOsisObject, inCallback);
+ } else
+ inCallback(inError);
+ }));
+ else
+ inCallback(inError);
+ }));
+ } else {
+ //Update an existing note
+ this.getNote(inObject.id, enyo.bind(this, function (inError, inNoteObject) {
+ if(!inError) {
+ inNoteObject["text"] = inObject["text"];
+ this._put(inDB, inNoteObject, inCallback);
+ } else {
+ inCallback(inError);
+ }
+ }));
+ }
+ else inCallback(inError);
+ }));
+ },
+
_get: function (inDB, inId, inCallback) {
inDB.get(inId,
function (inObject) {
@@ -209,6 +267,20 @@ var api = {
}));
},
+ getNote: function (inId, inCallback) {
+ this.noteWrapper(enyo.bind(this, function (inError, inDB) {
+ if(!inError) this._get(inDB, inId, inCallback);
+ else inCallback(inError);
+ }));
+ },
+
+ getNotes: function (inIds, inCallback) {
+ this.noteWrapper(enyo.bind(this, function (inError, inDB) {
+ if(!inError) this._getBatch(inDB, inIds, inCallback);
+ else inCallback(inError);
+ }));
+ },
+
getUserData: function(inOsis, inVMax, inCallback) {
var z=1,
userData = {};
@@ -220,6 +292,8 @@ var api = {
userData[inData.id] = inData;
if(inData && inData.highlightId)
userData[inData.id] = inData;
+ if(inData && inData.noteId)
+ userData[inData.id] = inData;
if(z === inVMax) inCallback(null, userData);
else z++;
} else
@@ -283,6 +357,28 @@ var api = {
}));
},
+ removeNote: function (inNote, inCallback) {
+ this.noteWrapper(enyo.bind(this, function (inError, inDB) {
+ if(!inError)
+ this._remove(inDB, inNote.id, enyo.bind(this, function(inError) {
+ if(!inError)
+ this.get(inNote.osisRef, enyo.bind(this, function(inError, inOsisObject) {
+ if(!inError) {
+ if(inOsisObject !== undefined) {
+ delete inOsisObject["noteId"];
+ this.put(inOsisObject, inCallback);
+ } else
+ inCallback({message: "api.removeHighlight: Couldn't remove noteId from osisObject"});
+ } else
+ inCallback(inError);
+ }));
+ else
+ inCallback(inError);
+ }));
+ else inCallback(inError);
+ }));
+ },
+
putSetting: function (inKey, inValue, inCallback) {
this.get("settings", enyo.bind(this, function (inError, inSettings) {
if(!inError) {
@@ -304,5 +400,11 @@ var api = {
this.hlWrapper(function (inError, inDB) {
inDB.clear();
});
+ },
+
+ formatOsis: function (inOsis) {
+ var split = inOsis.split(".");
+ var formatted = split[0] + " " + split[1];
+ return (split[2]) ? formatted + ":" + split[2] : formatted;
}
}; \ No newline at end of file
diff --git a/source/main.js b/source/main.js
index 55cb659..f0cd675 100644
--- a/source/main.js
+++ b/source/main.js
@@ -6,15 +6,17 @@ enyo.kind({
onOpenModuleManager: "",
onOpenPreferences: "",
onModuleChanged: "",
- onOpenBC: ""
+ onOpenBC: "",
+ onOpenNotes: ""
},
published: {
passage: ""
},
components:[
{kind: "Signals", onOrientationChange: "handleOrientation"},
- {kind: "biblez.versePopup", name: "versePopup", onBookmark: "handleBookmark", onHighlight: "handleHighlight"},
+ {kind: "biblez.versePopup", name: "versePopup", onBookmark: "handleBookmark", onHighlight: "handleHighlight", onNoteTap: "handleNoteTap"},
{name: "fontMenu", kind: "biblez.fontMenu", onFontSize: "handleFontSize", onFont: "handleFont"},
+ {name: "notePopup", kind: "biblez.notePopup", onEdit: "handleNoteTap"},
//{kind: "Signals", onbeforeunload: "handleUnload"},
{name: "messagePopup", kind: "onyx.Popup", centered: true, floating: true, classes: "message-popup"},
{name: "bcPopup", classes: "biblez-bc-popup", kind: "onyx.Popup", modal: true, floating: true, components: [
@@ -31,17 +33,26 @@ enyo.kind({
{name: "actionSelector", kind: "onyx.MenuDecorator", onSelect: "actionSelected", components: [
{kind: "onyx.IconButton", src: "assets/menu.png"},
{kind: "onyx.Menu", name: "actionMenu", style: "width: 200px;", components: [
+ {action: "bookmarks", components: [
+ {kind: "onyx.IconButton", src: "assets/bookmarks.png"},
+ {content: $L("Bookmarks"), classes: "menu-label"}
+ ]},
+ {action: "notes", components: [
+ {kind: "onyx.IconButton", src: "assets/notes.png"},
+ {content: $L("Notes"), classes: "menu-label"}
+ ]},
+ {action: "highlights", components: [
+ {kind: "onyx.IconButton", src: "assets/highlights.png"},
+ {content: $L("Highlights"), classes: "menu-label"}
+ ]},
+ {classes: "onyx-menu-divider"},
{action: "moduleManager", components: [
{kind: "onyx.IconButton", src: "assets/add.png"},
- {content: $L("Module Manager")}
+ {content: $L("Module Manager"), classes: "menu-label"}
]},
{action: "preferences", components: [
{kind: "onyx.IconButton", src: "assets/settings.png"},
- {content: $L("Preferences")}
- ]},
- {action: "bookmarks", components: [
- {kind: "onyx.IconButton", src: "assets/bookmarks.png"},
- {content: $L("Bookmarks")}
+ {content: $L("Preferences"), classes: "menu-label"}
]}
]}
]},
@@ -224,10 +235,12 @@ enyo.kind({
handleUserData: function (inOsis) {
var vmax = this.currentModule.getVersesInChapter(inOsis),
- hlKeys = [];
+ hlKeys = [],
+ noteKeys = [];
api.getUserData(inOsis, vmax, enyo.bind(this, function (inError, inUserData) {
if(!inError) {
this.userData = inUserData;
+ //console.log(this.userData);
Object.keys(inUserData).forEach(function (key) {
if(inUserData[key].bookmarkId && !enyo.dom.byId("img"+key)) {
enyo.dom.byId(key).insertAdjacentHTML("beforeend", " <img id='img" + key + "' src='assets/bookmark.png' />");
@@ -235,6 +248,9 @@ enyo.kind({
if(inUserData[key].highlightId) {
hlKeys.push(inUserData[key].highlightId);
}
+ if(inUserData[key].noteId) {
+ noteKeys.push(inUserData[key].noteId);
+ }
});
if (hlKeys.length !== 0) {
api.getHighlights(hlKeys, enyo.bind(this, function (inError, inHighlights) {
@@ -246,6 +262,17 @@ enyo.kind({
this.handleError(inError);
}));
}
+ if (noteKeys.length !== 0) {
+ api.getNotes(noteKeys, enyo.bind(this, function (inError, inNotes) {
+ if(!inError) {
+ inNotes.forEach(enyo.bind(this, function (note) {
+ if(!enyo.dom.byId("note"+note.osisRef))
+ enyo.dom.byId(note.osisRef).insertAdjacentHTML("beforeend", " <a href=?type=note&osisRef=" + note.osisRef + "&id=" + note.id + " id='note" + note.osisRef + "'><img src='assets/note.png' /></a>");
+ }));
+ } else
+ this.handleError(inError);
+ }));
+ }
}
}));
@@ -266,6 +293,22 @@ enyo.kind({
this.handleUserData(this.currentPassage.osis);
},
+ handleNoteTap: function (inSender, inEvent) {
+ //console.log(inEvent);
+ if (this.userData[inEvent.osisRef] && this.userData[inEvent.osisRef].noteId !== undefined)
+ inEvent["noteId"] = this.userData[inEvent.osisRef].noteId;
+ this.doOpenNotes(inEvent);
+ },
+
+ handleNote: function (inSender, inEvent) {
+ //console.log("handleNote", inEvent);
+ if(inEvent.action === "remove") {
+ var oldNoteImg = enyo.dom.byId("note"+inEvent.osisRef);
+ oldNoteImg.parentNode.removeChild(oldNoteImg);
+ }
+ this.handleUserData(this.currentPassage.osis);
+ },
+
handleBcSelector: function (inSender, inEvent) {
if(enyo.platform.firefox) {
this.$.bcPopup.showAtEvent(inEvent);
@@ -309,8 +352,9 @@ enyo.kind({
handleVerseTap: function (inSender, inEvent) {
inEvent.preventDefault();
var attributes = {};
- if(inEvent.target.href) {
- var url = inEvent.target.href;
+ //console.log(inEvent);
+ if(inEvent.target.href || inEvent.target.parentNode.href) {
+ var url = inEvent.target.href || inEvent.target.parentNode.href;
url.split("?")[1].split("&").forEach(function(item) {
item = item.split("=");
attributes[item[0]] = item[1];
@@ -329,13 +373,30 @@ enyo.kind({
this.$.versePopup.setHlId(this.userData[attributes.osisRef].highlightId);
} else
this.$.versePopup.setHlExists(false);
+ if (this.userData[attributes.osisRef].noteId) {
+ this.$.versePopup.setNoteExists(true);
+ this.$.versePopup.setNoteId(this.userData[attributes.osisRef].noteId);
+ } else {
+ this.$.versePopup.setNoteExists(false);
+ this.$.versePopup.setNoteId(null);
+ }
} else {
this.$.versePopup.setBmExists(false);
this.$.versePopup.setHlExists(false);
this.$.versePopup.setNoteExists(false);
+ this.$.versePopup.setNoteId(null);
}
this.$.versePopup.setLabels();
this.$.versePopup.showAtEvent(inEvent);
+ } else if (attributes.type === "note") {
+ api.getNote(parseInt(attributes.id, 10), enyo.bind(this, function (inError, inNote) {
+ if(!inError) {
+ this.$.notePopup.setText(inNote.text);
+ this.$.notePopup.setOsisRef(inNote.osisRef);
+ this.$.notePopup.showAtEvent(inEvent);
+ } else
+ this.handleError(inError);
+ }));
}
return true;
},
diff --git a/source/notes.js b/source/notes.js
new file mode 100644
index 0000000..3507080
--- /dev/null
+++ b/source/notes.js
@@ -0,0 +1,88 @@
+enyo.kind({
+ name: "biblez.notes",
+ kind: "enyo.FittableRows",
+ fit: true,
+ events: {
+ onBack: "",
+ onChange: ""
+ },
+ published: {
+ osisRef: null,
+ noteId: null,
+ noteText: ""
+ },
+ components: [
+ {name: "messagePopup", kind: "onyx.Popup", scrim: true, centered: true, floating: true, classes: "message-popup"},
+ {kind: "onyx.MoreToolbar", components: [
+ {kind: "onyx.IconButton", src: "assets/back.png", ontap: "handleBack"},
+ {name: "label", content: $L("Notes")}
+ ]},
+ {kind: "enyo.Scroller", touch: true, fit: true, style: "text-align: center;", components: [
+ {kind: "onyx.InputDecorator", style: "margin: 10px;", alwaysLooksFocused: true, components: [
+ {name: "noteInput", kind: "onyx.RichText", classes: "note-input", placeholder: "Enter your note here", allowHmtl: false}
+ ]},
+ {tag: "br"},
+ {name: "btDelete", kind: "onyx.Button", content: $L("Delete Note"), disabled: true, classes: "onyx-negative", style: "margin: 10px;", ontap: "removeNote"}
+ ]}
+ ],
+
+ rendered: function () {
+ this.inherited(arguments);
+ this.$.noteInput.applyStyle("width", window.innerWidth > 700 ? 600 + "px" : window.innerWidth-40 + "px");
+ },
+
+ setFocus: function () {
+ //this.$.noteInput.focus();
+ },
+
+ osisRefChanged: function (inSender, inEvent) {
+ this.$.label.setContent($L("Notes for") + " " + api.formatOsis(this.osisRef));
+ },
+
+ noteIdChanged: function () {
+ this.$.noteInput.setValue("");
+ if (this.noteId !== null) {
+ api.getNote(this.noteId, enyo.bind(this, function (inError, inNote) {
+ if(!inError) {
+ this.$.noteInput.setValue(inNote.text);
+ this.$.btDelete.setDisabled(false);
+ } else
+ this.handleError(inError);
+ }));
+ } else {
+ this.$.btDelete.setDisabled(true);
+ }
+ },
+
+ updateNote: function (inSender, inEvent) {
+ api.putNote({id: this.noteId, text: this.$.noteInput.getValue().replace(/"/g, '&quot;'), osisRef: this.osisRef}, enyo.bind(this, function (inError, inId) {
+ if(!inError) {
+ this.doChange({action: "update", osisRef: this.osisRef});
+ } else
+ console.log(inError);
+ }));
+ },
+
+ removeNote: function () {
+ api.removeNote({id: this.noteId, osisRef: this.osisRef}, enyo.bind(this, function (inError) {
+ if(!inError) {
+ this.doChange({action: "remove", osisRef: this.osisRef});
+ this.doBack();
+ } else
+ this.handleError(inError);
+ }));
+ },
+
+ handleBack: function() {
+ if(this.$.noteInput.getValue() !== "")
+ this.updateNote();
+ this.doBack();
+ },
+
+ handleError: function (inMessage) {
+ if (inMessage.message)
+ inMessage = inMessage.message;
+ this.$.messagePopup.setContent(inMessage);
+ this.$.messagePopup.show();
+ }
+}); \ No newline at end of file
diff --git a/source/package.js b/source/package.js
index 4827faa..1ff7f76 100644
--- a/source/package.js
+++ b/source/package.js
@@ -12,5 +12,6 @@ enyo.depends(
"moduleManagerDesktop.js",
"popup.js",
"settings.js",
+ "notes.js",
"App.js"
);
diff --git a/source/popup.js b/source/popup.js
index b0cd1ce..fdca7bc 100644
--- a/source/popup.js
+++ b/source/popup.js
@@ -1,3 +1,4 @@
+// VERSE POPUP //
enyo.kind({
name: "biblez.versePopup",
kind: "onyx.Popup",
@@ -8,7 +9,8 @@ enyo.kind({
events: {
onBookmark: "",
onNote: "",
- onHighlight: ""
+ onHighlight: "",
+ onNoteTap: ""
},
published: {
osisRef: null,
@@ -82,9 +84,16 @@ enyo.kind({
else
console.log(inError);
}));
+ },
+
+ handleNote: function (inSender, inEvent) {
+ this.hide();
+ this.doNoteTap({osisRef: this.osisRef, noteId: this.noteId});
}
});
+// FONT MENU //
+
enyo.kind({
name: "biblez.fontMenu",
kind: "onyx.Popup",
@@ -169,4 +178,31 @@ enyo.kind({
fontChanged: function(inSender, inEvent) {
this.$[this.font].setActive(true);
}
+});
+
+// NOTE VIEW POPUP //
+enyo.kind({
+ name: "biblez.notePopup",
+ kind: "onyx.Popup",
+ classes: "note-popup",
+ events: {
+ onEdit: ""
+ },
+ published: {
+ osisRef: null,
+ text: ""
+ },
+ components:[
+ {kind: "enyo.Scroller", touch: true, fit: true, components: [
+ {name: "noteText", content: "", allowHtml: true, ontap: "handleTap"}
+ ]}
+ ],
+
+ textChanged: function () {
+ this.$.noteText.setContent(this.text);
+ },
+
+ handleTap: function (inSender, inEvent) {
+ this.doEdit({osisRef: this.osisRef});
+ }
}); \ No newline at end of file
diff --git a/source/settings.js b/source/settings.js
index cc8b52f..e7673b1 100644
--- a/source/settings.js
+++ b/source/settings.js
@@ -24,9 +24,9 @@ enyo.kind({
{tag: "br"},
{kind: "onyx.Groupbox", components: [
{kind: "onyx.GroupboxHeader", content: $L("Be careful!")},
- {kind: "enyo.FittableColumns", classes: "settings-row", components: [
- {kind: "onyx.Button", content: "Delete all modules!", style: "margin: 0 2px;", ontap: "deleteModules"},
- {kind: "onyx.Button", content: "Delete all app data!", style: "margin: 0 2px;", ontap: "deleteDatabases"}
+ {kind: "enyo.FittableRows", classes: "settings-row", components: [
+ {kind: "onyx.Button", content: "Delete all modules!", classes: "onyx-negative", style: "margin: 3px;", ontap: "deleteModules"},
+ {kind: "onyx.Button", content: "Delete all app data!", classes: "onyx-negative", style: "margin: 3px;", ontap: "deleteDatabases"}
]}
]},
]}