Commit 12a58176 authored by Sven Franck's avatar Sven Franck

starting to make setPageElements global layout handler

parent f6c066bd
...@@ -5,15 +5,25 @@ ...@@ -5,15 +5,25 @@
(function (window, document, $) { (function (window, document, $) {
"use strict"; "use strict";
var init, app, util, erp5, factory; var init, app, util, erp5, factory, map, storage;
/* ====================================================================== */ /* ====================================================================== */
/* MAPPING ERP5 */ /* STORAGE */
/* ====================================================================== */
/*
* storage object
*/
storage = {};
/* ====================================================================== */
/* MAPPING */
/* ====================================================================== */ /* ====================================================================== */
/* /*
* object containing mappering methods * mapping object for custom (in this case ERP5) backend
*/ */
map = {};
erp5 = {}; erp5 = {};
...@@ -3085,9 +3095,9 @@ ...@@ -3085,9 +3095,9 @@
}; };
/** /**
* sets up JIO based on loaded JSON "recipe" * set up storages based on fetched recipee
* @method createStorages * @method createStorages
* @param {object} response object containing data (jio.util.ajax response) * @param {object} reply Storage recipee
* @return {object} promise object * @return {object} promise object
*/ */
app.createStorages = function (reply) { app.createStorages = function (reply) {
...@@ -3095,13 +3105,11 @@ ...@@ -3095,13 +3105,11 @@
store, store,
promises = []; promises = [];
app.storages = {};
for (i = 0; i < reply.length; i += 1) { for (i = 0; i < reply.length; i += 1) {
store = reply[i].definition; store = reply[i].definition;
promises[i] = promises[i] =
app.storages[store.application_name] = storage[store.application_name] =
jIO.createJIO(store); jIO.createJIO(store);
} }
return RSVP.all(promises); return RSVP.all(promises);
...@@ -3167,7 +3175,7 @@ ...@@ -3167,7 +3175,7 @@
// TODO should be generic, not only JIO based! // TODO should be generic, not only JIO based!
init.fetchConfiguration = function (parcel) { init.fetchConfiguration = function (parcel) {
//storage, file, attachment, baggage //storage, file, attachment, baggage
var reply, store = app.storages[parcel.storage]; var reply, store = storage[parcel.storage];
return store.getAttachment({ return store.getAttachment({
"_id": parcel.file, "_id": parcel.file,
...@@ -3209,7 +3217,7 @@ ...@@ -3209,7 +3217,7 @@
*/ */
// NOTE: until we have real data we load fake data on application init! // NOTE: until we have real data we load fake data on application init!
init.fetchData = function (parcel) { init.fetchData = function (parcel) {
return app.storages[parcel.storage].allDocs(parcel.query) return storage[parcel.storage].allDocs(parcel.query)
.then(function (response) { .then(function (response) {
return { return {
"response": response, "response": response,
...@@ -3584,7 +3592,7 @@ ...@@ -3584,7 +3592,7 @@
init.timer = window.setTimeout(function () { init.timer = window.setTimeout(function () {
// update gadgets // update gadgets
init.setPageElements( init.setPageElements(
{}, [{"children": [{"id": config.id}]}], false [{"children": [{"id": config.id}]}], {}, false
); );
init.timer = 0; init.timer = 0;
}, 500); }, 500);
...@@ -3628,7 +3636,7 @@ ...@@ -3628,7 +3636,7 @@
// update gadget // update gadget
init.setPageElements( init.setPageElements(
{}, [{"children": [{"id": action_dict.id}]}], false [{"children": [{"id": action_dict.id}]}], {}, false
); );
}) })
.fail(util.errorHandler); .fail(util.errorHandler);
...@@ -3884,7 +3892,7 @@ ...@@ -3884,7 +3892,7 @@
// update gadget // update gadget
init.setPageElements( init.setPageElements(
{}, [{"children": [{"id": config.id}]}], false [{"children": [{"id": config.id}]}], {}, false
); );
} else { } else {
util.errorHandler({ util.errorHandler({
...@@ -3917,7 +3925,7 @@ ...@@ -3917,7 +3925,7 @@
.then(function (reply) { .then(function (reply) {
if (!page.querySelectorAll("div.ui-content")[0] if (!page.querySelectorAll("div.ui-content")[0]
.getAttribute("data-bound")) { .getAttribute("data-bound")) {
return init.setPageElements({"id": page.id}, reply, undefined); return init.setPageElements(reply, {"id": page.id}, undefined);
} }
}) })
.fail(util.errorHandler); .fail(util.errorHandler);
...@@ -4088,7 +4096,7 @@ ...@@ -4088,7 +4096,7 @@
init.fetchPageLayouts("settings", destination) init.fetchPageLayouts("settings", destination)
.then(function (reply) { .then(function (reply) {
return init.setPageElements(config, reply, create); return init.setPageElements(reply, config, create);
}) })
.then(init.setPageBindings) .then(init.setPageBindings)
.fail(util.errorHandler); .fail(util.errorHandler);
...@@ -4205,7 +4213,7 @@ ...@@ -4205,7 +4213,7 @@
promises, promises,
record, record,
items, items,
store = app.storages["items"], store = storage["items"],
baggage = reply.baggage; baggage = reply.baggage;
if (reply.response) { if (reply.response) {
...@@ -4393,11 +4401,11 @@ ...@@ -4393,11 +4401,11 @@
/** /**
* Setup/update elements to on the page being shown, generate page * Setup/update elements to on the page being shown, generate page
* @method setupPageElements * @method setupPageElements
* @param {object} config JSON pointers based on parsed link
* @param {object} layouts Layouts to be generated for this page * @param {object} layouts Layouts to be generated for this page
* @param {object} config JSON pointers based on parsed link
* @param {boolean} create Create page/Generate content/Refresh content * @param {boolean} create Create page/Generate content/Refresh content
*/ */
init.setPageElements = function (config, layouts, create) { init.setPageElements = function (layouts, config, create) {
var i, var i,
page, page,
target, target,
...@@ -4922,7 +4930,7 @@ ...@@ -4922,7 +4930,7 @@
window.localStorage.clear(); window.localStorage.clear();
// TODO: modernizr check and shim here // TODO: modernizr check and shim based on app.json
// initalize translations // initalize translations
...@@ -4934,7 +4942,7 @@ ...@@ -4934,7 +4942,7 @@
ns: "dict" ns: "dict"
}); });
// TODO: run this to the normal route! // TODO: get storage run, get config run, get page run
app.setupStorages(util.getPathFromScriptTag("data-storage")) app.setupStorages(util.getPathFromScriptTag("data-storage"))
.then(init.loadGlobalElements) .then(init.loadGlobalElements)
.then(init.setupGlobalElements) .then(init.setupGlobalElements)
......
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