From 9d42b1160a25aa65785b13e19d5d62ad83aac545 Mon Sep 17 00:00:00 2001 From: zefanja Date: Wed, 16 Apr 2014 20:34:21 +0700 Subject: * update biblez.appcache to allow CORS --- source/moduleManager.js | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'source/moduleManager.js') diff --git a/source/moduleManager.js b/source/moduleManager.js index 118e199..d865808 100644 --- a/source/moduleManager.js +++ b/source/moduleManager.js @@ -65,10 +65,14 @@ enyo.kind({ if (!this.started) { this.$.spinner.show(); api.get("repos", enyo.bind(this, function (inError, inData) { - if(!inData) - this.getRepos(); - else - this.setupRepoPicker(inData.repos, inData.currentRepo); + if(!inError) { + if(!inData) + this.getRepos(); + else + this.setupRepoPicker(inData.repos, inData.currentRepo); + } else { + this.handleError(inError); + } })); } this.getInstalledModules(); @@ -115,19 +119,11 @@ enyo.kind({ }, getRepos: function () { - if(navigator.onLine) + if(navigator.onLine) { 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); - }) - ); - + this.saveRepoData(inRepos); } else { this.handleError(inError); } @@ -136,25 +132,30 @@ enyo.kind({ 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) - this.setupRepoPicker(inRepos); - else - this.handleError(inError); - }) - ); + this.saveRepoData(inRepos); }); xhr.error(this, function (inSender, inResponse) { + console.log(inSender, inResponse); this.handleError({message: "Couldn't download MasterList!"}); }); } - else { + } else { this.$.spinner.stop(); this.handleError({message: $L("You need an internet connection to download modules!")}); } }, + saveRepoData: function (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); + }) + ); + }, + setupRepoPicker: function (inRepos, currentRepo) { this.currentRepo = currentRepo; var items = [], -- cgit