enyo.kind({
name: "biblez.main",
kind: "FittableRows",
fit: true,
events: {
onOpenModuleManager: "",
onOpenPreferences: "",
onModuleChanged: "",
onOpenBC: "",
onOpenNotes: "",
onOpenDataView: "",
onOpenAbout: ""
},
published: {
passage: ""
},
components:[
//{kind: "Signals", onOrientationChange: "handleOrientation"},
{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"},
{name: "footnotePopup", kind: "biblez.footnotePopup"},
{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: [
{kind: "biblez.bcSelector", name: "bcSelector", onSelect: "passageChanged", onBack: "closePopup"}
]},
{kind: "onyx.Toolbar", showing: false, classes: "main-toolbar", noStretch: true, name: "topTB", layoutKind: "FittableColumnsLayout", components: [
{name: "moduleSelector", kind: "onyx.MenuDecorator", onSelect: "moduleSelected", components: [
{kind: "onyx.Button", name: "btnModules", classes: "tb-button", style: "background-color: #934A15;"},
{kind: "onyx.Menu", maxHeight: "300", name: "moduleMenu"}
]},
{kind: "onyx.Button", name: "btnPassage", classes: "tb-button", ontap: "handleBcSelector"},
{name: "historySelector", kind: "onyx.MenuDecorator", onSelect: "historySelected", components: [
//Clock Icon by Thomas Le Bas from The Noun Project
{kind: "onyx.IconButton", name: "btnHistory", src: "assets/history.png"},
{kind: "onyx.Menu", maxHeight: "300", name: "historyMenu"}
]},
{fit: true},
{classes: "toolbar-spinner", name: "tbSpinner", showing: false},
{name: "actionSelector", kind: "onyx.MenuDecorator", onSelect: "actionSelected", components: [
{kind: "onyx.IconButton", src: "assets/menu.png"},
{kind: "onyx.Menu", name: "actionMenu", maxHeight: "400", style: "width: 200px;", components: [
{action: "bookmarks", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/bookmarks.png"},
{content: $L("Bookmarks"), classes: "menu-label"}
]},
{action: "notes", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/notes.png"},
{content: $L("Notes"), classes: "menu-label"}
]},
{action: "highlights", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/highlights.png"},
{content: $L("Highlights"), classes: "menu-label"}
]},
{classes: "onyx-menu-divider"},
{action: "moduleManager", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/add.png"},
{content: $L("Module Manager"), classes: "menu-label"}
]},
{action: "preferences", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/settings.png"},
{content: $L("Preferences"), classes: "menu-label"}
]},
{action: "font", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/font.png"},
{content: $L("Font"), classes: "menu-label"}
]},
{action: "about", classes: "menu-item", components: [
{kind: "onyx.IconButton", src: "assets/info.png"},
{content: $L("About"), classes: "menu-label"}
]}
]}
]},
//{name: "btFont", kind: "onyx.IconButton", src: "assets/font.png", ontap: "handleFontMenu"}
]},
{name: "mainPanel", kind: "Panels", draggable: false, /*index: 2, */fit: true, ondragfinish: "handleChangeChapter", onTransitionStart: "handlePanelIndex", arrangerKind: "LeftRightArranger", margin: 0, classes: "background", components: [
{name: "verseList", kind: "VerseList", touch: false, thumb: false, touchOverscroll: false, count: 0, onSetupItem: "setVerses", onScroll: "", onScrollStop: "handleScrolling", classes: "enyo-selectable", components: [
{name: "text", allowHtml: true, style: "display: inline;", ontap: "handleVerseTap", onclick: "handleVerseTap"},
{name: "imgBm", tag: "img", style: "display: inline;", showing: false, src: "assets/bookmark.png"},
{name: "imgNote", tag: "img", type: "note", style: "display: inline; margin: 0 3px;", showing: false, src: "assets/note.png", ontap: "handleVerseTap"}
]}
/*{},
{kind: "FittableColumns", noStretch: true, components: [
{fit: true},
{content: "< Previous", classes: "chapter-nav chapter-nav-left"}
]},*/
/*{name: "verseScroller", kind: "enyo.Scroller", onScrollStop: "handleScrolling", thumb: false, touch: true, touchOverscroll: false, fit: true, components: [
//{classes: "center", components: [{kind: "onyx.Spinner", name: "spinner", classes: "onyx-light center"}]},
//{name: "main", classes: "verse-view", allowHtml: true, onclick: "handleVerseTap"}
]},*/
/*{kind: "FittableColumns", noStretch: true, components: [
{content: "Next >", classes: "chapter-nav chapter-nav-right"},
{fit: true}
]},
{}*/
]},
],
currentModule: null,
passage: {
osisRef: "Matt.1",
label: "Matt 1",
chapter: 1
},
userData: {},
modules: [],
history: [],
panelIndex: 2,
settings: {id: "settings"},
footnotes: {},
verses: [],
reachedTop: false,
reachedBottom: false,
offset: 0,
rowSize: 0,
hasVerseNumber: 0,
timer: null,
create: function () {
this.inherited(arguments);
if(enyo.platform.firefox)
this.$.verseList.onScroll = "handleScrolling";
this.startUp();
//this.$.mainPanel.setIndexDirect(2);
},
startUp: function () {
api.get("settings", enyo.bind(this, function(inError, inSettings) {
if(!inError) {
this.settings = (inSettings) ? inSettings: this.settings;
//console.log(this.settings);
this.getInstalledModules();
if(this.settings.fontSize) {
this.$.fontMenu.setFontSize(this.settings.fontSize);
this.$.verseList.applyStyle("font-size", this.settings.fontSize + "em");
}
if(this.settings.font) {
this.$.fontMenu.setFont(this.settings.font);
if(this.settings.font !== "default")
this.$.verseList.applyStyle("font-family", this.settings.font);
}
if(this.settings.history)
this.history = this.settings.history;
} else {
//console.log(inError);
this.handleError("Couldn't load settings!");
}
}));
},
handleSettings: function (inSender, inEvent) {
api.get("settings", enyo.bind(this, function(inError, inSettings) {
if(!inError) {
this.settings = (inSettings) ? inSettings: this.settings;
this.handlePassage();
} else {
this.handleError("Couldn't load settings!");
}
}));
},
getInstalledModules: function (inSender, inEvent) {
sword.moduleMgr.getModules(enyo.bind(this, function(inError, inModules) {
if (!inError) {
if(inModules.length !== 0) {
this.$.mainPanel.selectPanelByName("verseList");
this.$.mainPanel.draggable = true;
this.$.topTB.show();
this.modules = inModules;
this.renderModuleMenu(this.modules);
if(this.$.firstStart) {
this.$.firstStart.destroy();
this.$.endPlaceholder.destroy();
}
} else {
this.$.topTB.hide();
this.$.mainPanel.draggable = false;
this.$.mainPanel.createComponent({name: "firstStart", classes: "center", style: "margin-top: 20px;", components: [
{tag: "img", src: "assets/biblez128.png", style: "margin: 20px;"},
{content: $L("You have no modules installed. Open the Module Manager to install one."), style: "font-weight: bold; margin-bottom: 20px;"},
{kind: "onyx.Button", classes: "onyx-affirmative", content: $L("Open Module Manager"), ontap: "doOpenModuleManager"}
]}, {owner: this}).render();
this.$.mainPanel.createComponent({name: "endPlaceholder"}, {owner: this}).render();
this.$.mainPanel.selectPanelByName("firstStart");
this.$.mainPanel.resized();
}
this.reflow();
} else {
this.handleError(inError);
}
}));
},
renderModuleMenu: function (inModules) {
var lastModule = null;
if(!inModules)
inModules = this.modules;
if(this.settings.lastModule)
lastModule = this.settings.lastModule;
this.$.moduleMenu.destroyClientControls();
var mods = [];
this.currentModule = null;
this.modules.forEach(enyo.bind(this, function (mod, idx) {
if ((lastModule && lastModule === mod.modKey)) {
this.$.btnModules.setContent(lastModule);
mods.push({active: true, components: [
{content: mod.config.moduleKey, index: idx},
{kind: "onyx.IconButton", src: "assets/checkmark.png", style: "float: right;"}
]});
this.currentModule = mod;
} else
mods.push({content: mod.config.moduleKey, index: idx});
}));
if(this.currentModule === null) {
this.currentModule = this.modules[0];
mods[0]["active"] = true;
mods[0]["components"] = [
{content: this.currentModule.modKey, index: 0},
{kind: "onyx.IconButton", src: "assets/checkmark.png", style: "float: right;"}
];
this.$.btnModules.setContent(this.currentModule.modKey);
this.settings["lastModule"] = this.currentModule.modKey;
}
this.$.moduleMenu.createComponents(mods, {owner: this.$.moduleMenu});
this.$.moduleMenu.render();
this.doModuleChanged({module: this.currentModule});
if(enyo.platform.firefox || enyo.platform.androidFirefox)
this.$.bcSelector.setModule(this.currentModule);
//Load the verses
//console.log(this.passage, this.settings);
if(this.passage === this.settings.lastRead || !this.settings.lastRead)
this.handlePassage(this.passage);
if(this.settings)
this.setPassage((this.settings.lastRead) ? this.settings.lastRead : this.passage);
},
moduleSelected: function (inSender, inEvent) {
//console.log(inEvent.originator.index, this.settings);
if (!isNaN(inEvent.originator.index)) {
this.currentModule = this.modules[inEvent.originator.index];
this.settings["lastModule"] = this.currentModule.modKey;
//api.putSetting("lastModule", this.currentModule.modKey);
this.renderModuleMenu();
}
},
passageChanged: function (inSender, inEvent) {
this.$.bcPopup.hide();
if (!inEvent.offsetRef) {
delete inEvent.originator;
delete inEvent.delegate;
delete inEvent.type;
this.passage = inEvent;
} else {
if (inEvent.offsetRef.hasOwnProperty("osisRef"))
this.passage = inEvent.offsetRef;
else {
inOsis = (inEvent.offsetRef.split(".").length > 2) ? inEvent.offsetRef.slice(0, inEvent.offsetRef.lastIndexOf(".")): inEvent.offsetRef;
this.passage = {
osisRef: inOsis,
label: inOsis.replace(".", " "),
chapter: parseInt(inOsis.split(".")[1], 10)
};
}
}
if (!this.reachedBottom && !this.reachedTop && !inEvent.offsetRef)
this.handlePassage(this.passage);
//Persist current passage
this.addToHistory(this.passage);
this.renderHistory();
this.settings["lastRead"] = this.passage;
api.put(this.settings);
this.$.btnPassage.setContent((this.passage.label) ? this.passage.label : api.formatOsis(this.passage.osisRef));
//Adjust the TB Icons
this.$.topTB.resized();
return true;
},
handlePassage: function (inOsis) {
//console.log("handlePassage", inOsis, this.passage);
this.verses = [];
this.$.verseList.setCount(this.verses.length);
this.$.verseList.refresh();
var verseNumber = this.passage.verseNumber ? this.passage.verseNumber : 0;
if (typeof inOsis === "string") {
//BibleZ currently supports only Book.Chapter Osis passages in the mainView
if(inOsis.split(".").length > 2) {
verseNumber = parseInt(inOsis.slice(inOsis.lastIndexOf(".")+1, inOsis.length), 10);
inOsis = inOsis.slice(0, inOsis.lastIndexOf("."));
} else
verseNumber = 0;
this.passage = {
osisRef: inOsis,
label: inOsis.replace(".", " "),
chapter: parseInt(inOsis.split(".")[1], 10)
};
}
this.$.btnPassage.setContent((this.passage.label) ? this.passage.label : api.formatOsis(this.passage.osisRef));
this.loadText(this.passage.osisRef, enyo.bind(this, function (inError, inResult) {
if(!inError) {
this.footnotes = inResult.footnotes;
this.verses = inResult.verses;
var caps = "";
if(inResult.rtol) {
this.$.verseList.applyStyle("text-align", "right");
caps = "