aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assets/bookmark.pngbin0 -> 772 bytes
-rw-r--r--assets/bookmarks.pngbin0 -> 1864 bytes
-rw-r--r--assets/footnote.pngbin0 -> 643 bytes
-rw-r--r--assets/highlight.pngbin0 -> 985 bytes
-rw-r--r--assets/highlights.pngbin0 -> 2578 bytes
-rw-r--r--assets/note.pngbin0 -> 539 bytes
-rw-r--r--assets/notes.pngbin0 -> 1229 bytes
-rw-r--r--assets/notes2.pngbin0 -> 3763 bytes
-rw-r--r--source/api.js50
-rw-r--r--source/main.js39
-rw-r--r--source/popup.js43
11 files changed, 117 insertions, 15 deletions
diff --git a/assets/bookmark.png b/assets/bookmark.png
new file mode 100644
index 0000000..f7ed7e8
--- /dev/null
+++ b/assets/bookmark.png
Binary files differ
diff --git a/assets/bookmarks.png b/assets/bookmarks.png
new file mode 100644
index 0000000..31e0b89
--- /dev/null
+++ b/assets/bookmarks.png
Binary files differ
diff --git a/assets/footnote.png b/assets/footnote.png
new file mode 100644
index 0000000..3cccb19
--- /dev/null
+++ b/assets/footnote.png
Binary files differ
diff --git a/assets/highlight.png b/assets/highlight.png
new file mode 100644
index 0000000..6601f53
--- /dev/null
+++ b/assets/highlight.png
Binary files differ
diff --git a/assets/highlights.png b/assets/highlights.png
new file mode 100644
index 0000000..e8a6180
--- /dev/null
+++ b/assets/highlights.png
Binary files differ
diff --git a/assets/note.png b/assets/note.png
new file mode 100644
index 0000000..7ce1b24
--- /dev/null
+++ b/assets/note.png
Binary files differ
diff --git a/assets/notes.png b/assets/notes.png
new file mode 100644
index 0000000..e1b6c60
--- /dev/null
+++ b/assets/notes.png
Binary files differ
diff --git a/assets/notes2.png b/assets/notes2.png
new file mode 100644
index 0000000..0d00a1c
--- /dev/null
+++ b/assets/notes2.png
Binary files differ
diff --git a/source/api.js b/source/api.js
index a442a3a..13842b6 100644
--- a/source/api.js
+++ b/source/api.js
@@ -145,7 +145,55 @@ var api = {
if(!inError) this._getAll(inDB, inCallback);
else inCallback(inError);
}));
- }
+ },
+
+ getUserData: function(inOsis, inVMax, inCallback) {
+ var z=1,
+ userData = {};
+ inOsis = (inOsis.split(".").length === 2) ? inOsis : inOsis.split(".")[0] + "." + inOsis.split(".")[1];
+ for (var i=1;i<inVMax+1;i++) {
+ this.get(inOsis + "." + i, function (inError, inData) {
+ if(!inError) {
+ if(inData && inData.bookmarkId)
+ userData[inData.id] = inData;
+ if(z === inVMax) inCallback(null, userData);
+ else z++;
+ } else
+ inCallback(inError);
+ });
+ }
+ },
+ _remove: function (inDB, inId, inCallback) {
+ inDB.remove(inId,
+ function () {
+ if(inCallback) inCallback(null);
+ },
+ function (inError) {
+ if(inCallback) inCallback(inError);
+ }
+ );
+ },
+ removeBookmark: function (inBookmark, inCallback) {
+ this.bmWrapper(enyo.bind(this, function (inError, inDB) {
+ if(!inError)
+ this._remove(inDB, inBookmark.id, enyo.bind(this, function(inError) {
+ if(!inError)
+ this.get(inBookmark.osisRef, enyo.bind(this, function(inError, inOsisObject) {
+ if(!inError) {
+ if(inOsisObject !== undefined) {
+ delete inOsisObject["bookmarkId"];
+ this.put(inOsisObject, inCallback);
+ } else
+ inCallback({message: "api.removeBookmark: Couldn't remove bookmarkId from osisObject"});
+ } else
+ inCallback(inError);
+ }));
+ else
+ inCallback(inError);
+ }));
+ else inCallback(inError);
+ }));
+ },
}; \ No newline at end of file
diff --git a/source/main.js b/source/main.js
index 4c1fa50..a6ae3bf 100644
--- a/source/main.js
+++ b/source/main.js
@@ -12,7 +12,7 @@ enyo.kind({
},
components:[
{kind: "Signals", onOrientationChange: "handleOrientation"},
- {kind: "biblez.versePopup", name: "versePopup"},
+ {kind: "biblez.versePopup", name: "versePopup", onBookmark: "handleBookmark"},
//{kind: "Signals", onbeforeunload: "handleUnload"},
{name: "messagePopup", kind: "onyx.Popup", centered: true, floating: true, classes: "message-popup"},
{kind: "onyx.MoreToolbar", name: "topTB", components: [
@@ -54,6 +54,7 @@ enyo.kind({
osis: "Matt.1",
label: "Matt 1"
},
+ userData: {},
modules: [],
panelIndex: 2,
settings: {id: "settings"},
@@ -173,7 +174,7 @@ enyo.kind({
} else
this.handleError(inError.message);
}));
- this.handleBookmarks(this.currentPassage.osis);
+ this.handleUserData(this.currentPassage.osis);
//console.log();
/*api.getAll(function (inError, inAll) {
console.log(inAll);
@@ -183,9 +184,27 @@ enyo.kind({
});*/
},
- handleBookmarks: function (inOsis) {
- this.currentModule.getVersesInChapter(inOsis);
+ handleUserData: function (inOsis) {
+ var vmax = this.currentModule.getVersesInChapter(inOsis);
+ api.getUserData(inOsis, vmax, enyo.bind(this, function (inError, inUserData) {
+ if(!inError) {
+ this.userData = inUserData;
+ Object.keys(inUserData).forEach(function (key) {
+ if(inUserData[key].bookmarkId) {
+ enyo.dom.byId(key).insertAdjacentHTML("beforeend", " <img id='img" + key + "' src='assets/bookmark.png' />");
+ }
+ });
+ }
+ }));
+
+ },
+ handleBookmark: function (inSender, inEvent) {
+ if(inEvent.action === "remove") {
+ var oldBmImg = enyo.dom.byId("img"+inEvent.osisRef);
+ oldBmImg.parentNode.removeChild(oldBmImg);
+ }
+ this.handleUserData(this.currentPassage.osis);
},
handleBcSelector: function (inSender, inEvent) {
@@ -223,9 +242,19 @@ enyo.kind({
}
if(attributes.type === "verseNum") {
this.$.versePopup.setOsisRef(attributes.osisRef);
+ if(this.userData.hasOwnProperty(attributes.osisRef))
+ if (this.userData[attributes.osisRef].bookmarkId) {
+ this.$.versePopup.setBmExists(true);
+ this.$.versePopup.setBmId(this.userData[attributes.osisRef].bookmarkId);
+ } else
+ this.$.versePopup.setBmExists(false);
+ else {
+ this.$.versePopup.setBmExists(false);
+ this.$.versePopup.setNoteExists(false);
+ }
+ this.$.versePopup.setLabels();
this.$.versePopup.showAtEvent(inEvent);
}
-
return true;
},
diff --git a/source/popup.js b/source/popup.js
index 24b242c..2cd6974 100644
--- a/source/popup.js
+++ b/source/popup.js
@@ -2,14 +2,24 @@ enyo.kind({
name: "biblez.versePopup",
kind: "onyx.Popup",
classes: "verse-popup",
+ events: {
+ onBookmark: "",
+ onNote: "",
+ onHighlight: ""
+ },
published: {
- osisRef: null
+ osisRef: null,
+ bmExists: false,
+ noteExists: false,
+ bmId: null,
+ noteId: null,
+ hlId: null
},
components: [
{kind: "enyo.FittableRows", components: [
{kind: "enyo.FittableColumns", components: [
- {content: $L("Bookmark"), classes: "verse-popup-cell cell-top-left", ontap: "handleBookmark"},
- {content: $L("Note"), classes: "verse-popup-cell cell-top-right", ontap: "handleNote"},
+ {name: "bmLabel", content: $L("Bookmark"), classes: "verse-popup-cell cell-top-left", ontap: "handleBookmark"},
+ {name: "noteLabel", content: $L("Note"), classes: "verse-popup-cell cell-top-right", ontap: "handleNote"},
]},
{kind: "enyo.FittableColumns", components: [
{content: $L("Highlight"), classes: "verse-popup-cell", ontap: "handleHighlight"},
@@ -18,13 +28,28 @@ enyo.kind({
]}
],
+ setLabels: function () {
+ if(this.bmExists)
+ this.$.bmLabel.setContent($L("Bookmark") + " - ");
+ else
+ this.$.bmLabel.setContent($L("Bookmark") + " + ");
+ },
+
handleBookmark: function (inSender, inEvent) {
this.hide();
- api.putBookmark({osisRef: this.osisRef}, function (inError, inId) {
- if(!inError) {
- console.log("Added Bookmark");
- } else
- console.log(inError);
- });
+ if (!this.bmExists)
+ api.putBookmark({osisRef: this.osisRef}, enyo.bind(this, function (inError, inId) {
+ if(!inError) {
+ this.doBookmark({action: "add"});
+ } else
+ console.log(inError);
+ }));
+ else
+ api.removeBookmark({id: this.bmId, osisRef: this.osisRef}, enyo.bind(this, function (inError) {
+ if(!inError) {
+ this.doBookmark({action: "remove", osisRef: this.osisRef});
+ } else
+ console.log(inError);
+ }));
}
}); \ No newline at end of file