aboutsummaryrefslogtreecommitdiffstats
path: root/source/moduleManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'source/moduleManager.js')
-rw-r--r--source/moduleManager.js176
1 files changed, 127 insertions, 49 deletions
diff --git a/source/moduleManager.js b/source/moduleManager.js
index 44995de..77cb32f 100644
--- a/source/moduleManager.js
+++ b/source/moduleManager.js
@@ -16,7 +16,7 @@ enyo.kind({
{name: "panel", arrangerKind: "CollapsingArranger", fit: true, kind: "Panels", classes: "app-panels", components: [
{name: "panelLang", kind: "enyo.FittableRows", components: [
{classes: "center", components: [{kind: "onyx.Spinner", name: "spinner", classes: "onyx-light center"}]},
- {name: "langList", kind: "List", fit: true, touch: true, onSetupItem: "setupLangItem", components: [
+ {name: "langList", kind: "List", fit: true, onSetupItem: "setupLangItem", components: [
{classes: "item", ontap: "handleLanguage", components: [
{kind: "enyo.FittableColumns", components: [
{name: "langShort", classes: "item-left"},
@@ -27,14 +27,14 @@ enyo.kind({
]}
]},
{name: "panelModules", kind: "enyo.FittableRows", components: [
- {name: "modList", kind: "List", fit: true, touch: true, onSetupItem: "setupModItem", components: [
+ {name: "modList", kind: "List", fit: true, onSetupItem: "setupModItem", components: [
{classes: "item", ontap: "handleModule", components: [
{name: "modName"}
]}
]}
]},
{name: "panelDescription", kind: "enyo.FittableRows", components: [
- {kind: enyo.Scroller, touch: true, fit: true, components: [
+ {kind: enyo.Scroller, fit: true, components: [
{name: "detailsContainer", showing: false, classes: "content-container", components: [
{name: "detailsName", classes: "title"},
//{kind: "onyx.ProgressBar", name: "progressBar", progress: 0, showing: false, showStripes: false},
@@ -64,7 +64,6 @@ enyo.kind({
start: function () {
if (!this.started) {
- //this.$.scrim.show();
this.$.spinner.show();
api.get("repos", enyo.bind(this, function (inError, inData) {
if(!inData)
@@ -118,8 +117,26 @@ enyo.kind({
getRepos: function () {
if(navigator.onLine)
- sword.installMgr.getRepositories(enyo.bind(this, function (inError, inRepos) {
- if (!inError) {
+ if(enyo.platform.firefoxOS) {
+ sword.installMgr.getRepositories(enyo.bind(this, function (inError, inRepos) {
+ if (!inError) {
+ 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);
+ }
+ }));
+ } else {
+ var xhr = new enyo.Ajax({url: "http://zefanjas.de/apps/biblezMasterlist.php"});
+ xhr.go();
+ xhr.response(this, function (inSender, inRepos) {
api.put({id: "repos", repos: inRepos, lastRepoUpdate: {time: new Date().getTime()}},
enyo.bind(this, function (inError, inId) {
if(!inError)
@@ -128,11 +145,11 @@ enyo.kind({
this.handleError(inError);
})
);
-
- } else {
- this.handleError(inError);
- }
- }));
+ });
+ xhr.error(this, function (inSender, inResponse) {
+ this.handleError({message: "Couldn't download MasterList!"});
+ });
+ }
else {
this.$.spinner.stop();
this.handleError({message: $L("You need an internet connection to download modules!")});
@@ -140,26 +157,28 @@ enyo.kind({
},
setupRepoPicker: function (inRepos, currentRepo) {
+ this.currentRepo = currentRepo;
var items = [],
cw = null;
- inRepos.forEach(function(repo, idx) {
- if ((currentRepo && repo.name === currentRepo.name) || repo.name === "CrossWire") {
+ inRepos.forEach(enyo.bind(this, function(repo, idx) {
+ if ((this.currentRepo && repo.name === this.currentRepo.name) || repo.name === "CrossWire") {
items.push({content: repo.name, index: idx, active: true});
cw = repo;
} else items.push({content: repo.name, index: idx});
- });
+ }));
this.repos = inRepos;
this.$.repoPicker.createComponents(items, {owner: this});
this.$.repoPicker.render();
- if (currentRepo)
- this.getRemoteModules(currentRepo);
+ if (this.currentRepo)
+ this.getRemoteModules(this.currentRepo);
else
this.getRemoteModules(cw);
},
getRemoteModules: function (inRepo) {
+ this.currentRepo = inRepo;
//console.log(inRepo);
api.get("downloadedModules", enyo.bind(this, function (inError, allModules) {
//console.log(inRepo, allModules, this.repos);
@@ -169,22 +188,42 @@ enyo.kind({
this.prepareLangList(this.modules);
} else {
if (navigator.onLine)
- sword.installMgr.getModules(inRepo, enyo.bind(this, function (inError, inModules) {
- //enyo.log(inError, inModules, inModules.length);
- if(!inError) {
- if(!allModules) allModules = {id: "downloadedModules"};
- allModules[inRepo.name.replace(" ", "")] = {modules: inModules, name: inRepo.name};
- api.put(allModules, enyo.bind(this, function (inError, inId) {
- if(inError)
- this.handleError(inError);
- }));
- this.modules = inModules;
- this.prepareLangList(this.modules);
+ if(enyo.platform.firefoxOS) {
+ sword.installMgr.getModules(inRepo, enyo.bind(this, function (inError, inModules) {
+ //enyo.log(inError, inModules, inModules.length);
+ if(!inError) {
+ if(!allModules) allModules = {id: "downloadedModules"};
+ allModules[inRepo.name.replace(" ", "")] = {modules: inModules, name: inRepo.name};
+ api.put(allModules, 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.message) ? inError.message : inError);
+ }
+ }));
+ } else {
+ var xhr = new enyo.Ajax({url: "http://zefanjas.de/apps/biblezModules.php"});
+ xhr.go({modUrl: inRepo.url});
+ xhr.response(this, function (inSender, inModules) {
+ inModules = api.cleanArray(inModules).sort(api.dynamicSortMultiple("Lang", "moduleKey"));
+ if(!allModules) allModules = {id: "downloadedModules"};
+ allModules[inRepo.name.replace(" ", "")] = {modules: inModules, name: inRepo.name};
+ api.put(allModules, enyo.bind(this, function (inError, inId) {
+ if(inError)
+ this.handleError(inError);
+ }));
+ this.modules = inModules;
+ this.prepareLangList(this.modules);
+ });
+ xhr.error(this, function (inSender, inResponse) {
+ //console.log(inSender, inResponse);
+ this.handleError({message: "Couldn't download Modules!"});
+ });
+ }
else {
this.$.spinner.stop();
this.handleError({message: $L("You need an internet connection to download modules!")});
@@ -263,24 +302,63 @@ enyo.kind({
this.$.btnInstall.setDisabled(true);
this.$.progressBar.show();
this.$.bottomTB.render();
- sword.installMgr.installModule(this.currentModule.url, enyo.bind(this, function (inError, inModule) {
- if (!inError) {
- this.doInstalled();
- this.getInstalledModules();
- } else {
- console.log(inError);
- this.handleError(inError);
- }
- //console.log(inError, inModule);
- this.$.progressBar.hide();
- this.$.progressBar.setProgress(0);
- this.$.btnInstall.setDisabled(false);
- this.$.btnInstall.hide();
- this.$.btnRemove.show();
- }),
- enyo.bind(this, function (inEvent) {
- this.$.progressBar.animateProgressTo(inEvent.loaded/inEvent.total*100);
- }));
+ if(enyo.platform.firefoxOS) {
+ sword.installMgr.installModule(this.currentModule.url, enyo.bind(this, function (inError, inModule) {
+ if (!inError) {
+ this.doInstalled();
+ this.getInstalledModules();
+ this.$.btnInstall.hide();
+ this.$.btnRemove.show();
+ } else {
+ console.log(inError);
+ this.handleError(inError);
+ this.$.btnInstall.show();
+ this.$.btnRemove.hide();
+ }
+ //console.log(inError, inModule);
+
+
+ }),
+ enyo.bind(this, function (inEvent) {
+ this.$.progressBar.animateProgressTo(inEvent.loaded/inEvent.total*100);
+ }));
+ } else {
+ var xhr = new XMLHttpRequest({mozSystem: true, mozAnon: true});
+ var url = "http://zefanjas.de/apps/biblezGetModule.php?modKey="+this.currentModule.moduleKey+"&type="+this.currentRepo.type;
+ xhr.open('GET', url, true);
+ xhr.responseType = "blob";
+ xhr.onreadystatechange = enyo.bind(this, function (evt) {
+ //console.log(xhr.readyState, evt, xhr.status);
+ if (xhr.readyState == 4) {
+ if(xhr.status === 200)
+ sword.installMgr.installModule(xhr.response, enyo.bind(this, function (inError, inModule) {
+ if (!inError) {
+ this.doInstalled();
+ this.getInstalledModules();
+ this.$.btnInstall.hide();
+ this.$.btnRemove.show();
+ } else {
+ this.handleError((inError.message) ? inError.message : inError);
+ }
+ this.$.progressBar.hide();
+ this.$.progressBar.setProgress(0);
+ this.$.btnInstall.setDisabled(false);
+ }));
+ else
+ this.handleError({message: "Couldn't download module.", error: xhr.status});
+ }
+ });
+ xhr.onprogress = enyo.bind(this, function (inEvent) {
+ this.$.progressBar.animateProgressTo(inEvent.loaded/4000000*100);
+ });
+ xhr.onerror = enyo.bind(this, function (inError) {
+ this.handleError({message: "Couldn't download Module!"});
+ this.$.btnInstall.show();
+ this.$.btnRemove.hide();
+ });
+ xhr.send(null);
+ }
+
},
removeModule: function (inSender, inEvent) {