Commit d759f54c authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

AddApp and AppList pages: App List is taken from Local Url

* Instead of getting the List throught the local storage we get it from
a http get. This allows to edit another domain and still have the app
list functionnal.
* Add mecanism to quickly switch domain edition when updating app list
in order to be able to edit the current app list on the current domain
parent e340e859
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, Handlebars, document, loopEventListener, RSVP,
/*global window, rJS, Handlebars, document, loopEventListener, RSVP, URL,
encodeURIComponent */
(function (window, rJS, jIO) {
"use strict";
......@@ -35,28 +35,46 @@
}
function putNewAppList(gadget, app_list) {
/*
* Add a app in the app list. As the app list is hosted directly on this
* url, we switch back and forth with the current edit site URL in order to
* to set it right.
*
*/
var current_edit_url,
this_edit_url = new URL(
"./crib-enable.html", window.location.href).href;
return RSVP.Queue()
.push(function () {
return gadget.crib_sw_getCribEnableGadgetUrl();
})
.push(function (url) {
current_edit_url = url;
return gadget.crib_sw_setCribEnableGadgetUrl(this_edit_url);
})
.push(function () {
return gadget.crib_sw_put(DEFAULT_APP_LIST_DOC, {
content: JSON.stringify(app_list),
type: "application/json"
});
})
.push(function () {
return gadget.crib_sw_setCribEnableGadgetUrl(current_edit_url);
}, function () {
return gadget.crib_sw_setCribEnableGadgetUrl(current_edit_url);
});
}
function getApplicationList(gadget) {
return RSVP.Queue()
.push(function () {
return gadget.crib_sw_get(DEFAULT_APP_LIST_DOC)
return gadget.fetch(DEFAULT_APP_LIST_DOC)
.push(undefined, function () {
return gadget.crib_sw_get(SAMPLE_APP_LIST_DOC);
return gadget.fetch(SAMPLE_APP_LIST_DOC);
});
})
.push(function (data) {
return jIO.util.readBlobAsText(data, data.type);
})
.push(function (data) {
return JSON.parse(data.target.result);
return JSON.parse(data);
});
}
......@@ -106,6 +124,7 @@
return putNewAppList(gadget, app_list);
})
.push(function () {
logAddApp(gadget, "Redirecting to Editor");
return gadget.redirect({page: "editor", url: redirect_to});
});
}
......@@ -173,6 +192,14 @@
//////////////////////////////////////////////
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("crib_sw_get", "crib_sw_get")
.declareAcquiredMethod(
"crib_sw_setCribEnableGadgetUrl",
"crib_sw_setCribEnableGadgetUrl"
)
.declareAcquiredMethod(
"crib_sw_getCribEnableGadgetUrl",
"crib_sw_getCribEnableGadgetUrl"
)
.allowPublicAcquisition("crib_sw_get", function (argument_list) {
return this.crib_sw_get(argument_list[0]);
})
......@@ -199,6 +226,18 @@
}
return gadget.props.start_deferred.resolve();
})
.declareMethod('fetch', function (url) {
var context = this;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
});
})
.push(function (evt) {
return evt.target.responseText;
});
})
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
......
......@@ -7,16 +7,13 @@
function displayAppList(gadget) {
var app_list = [];
return gadget.crib_sw_get(DEFAULT_APP_LIST_DOC)
return gadget.fetch(DEFAULT_APP_LIST_DOC)
.push(undefined, function () {
return gadget.crib_sw_get(SAMPLE_APP_LIST_DOC);
})
.push(function (data) {
return jIO.util.readBlobAsText(data, data.type);
return gadget.fetch(SAMPLE_APP_LIST_DOC);
})
.push(function (data) {
var promise_list = [];
app_list = JSON.parse(data.target.result);
app_list = JSON.parse(data);
for (var i = 0; i < app_list.length; i += 1) {
promise_list.push(RSVP.all([
gadget.getUrlFor({
......@@ -97,6 +94,18 @@
.declareAcquiredMethod("crib_sw_put", "crib_sw_put")
.declareMethod('render', function (options) {
return displayAppList(this);
})
.declareMethod('fetch', function (url) {
var context = this;
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
});
})
.push(function (evt) {
return evt.target.responseText;
});
});
}(window, rJS, domsugar, jIO));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment