Commit d4d7d09d authored by Sven Franck's avatar Sven Franck

breaking global config

parent e4b52a2a
This diff is collapsed.
{ [{
"generate":"gadget", "type": "jIO",
"type": "setStorage", "set_on": "storage",
"initializer": "createJIO",
"modernizr": ["blobconstructor", "filereader"],
"property_dict": { "property_dict": {
"force_field_definitions": true, "force_field_definitions": true,
"storage_type": "JIO", "skip_total_records": true
"skip_total_records": true,
"modernizr": ["blobconstructor", "filereader"]
}, },
"children": [{ "scheme": [{
"generate": "gadget",
"type": "makeStorage",
"property_dict": { "property_dict": {
"definition": { "type": "local",
"username": "slapos",
"application_name": "settings"}
}, {
"set_name": "items",
"property_dict": {
"type": "replicate",
"storage_list": [{
"type":"hateoas",
"username":"slapos",
"url": "https://vifib.erp5.net/web_site_module/hateoas",
"application_name": "items"
}, {
"type": "local", "type": "local",
"username": "slapos", "username": "slapos",
"application_name": "settings" "application_name": "items",
} "yield": true
} }]
}, {
"generate": "gadget",
"type": "makeStorage",
"property_dict": {
"set_name": "items",
"definition": {
"type": "replicate",
"storage_list": [{
"type":"hateoas",
"username":"slapos",
"url": "https://vifib.erp5.net/web_site_module/hateoas",
"application_name": "items"
}, {
"type": "local",
"username": "slapos",
"application_name": "items",
"yield": true
}]
}
} }
}] }],
} "children": []
}]
\ No newline at end of file
...@@ -2228,7 +2228,7 @@ ...@@ -2228,7 +2228,7 @@
case "StateMachine": case "StateMachine":
support_state = true; support_state = true;
if (state.modernizr) { if (state.modernizr) {
support_state = util.testBrowserSupport(state.modernizr); support_state = util.testSupport(state.modernizr);
} }
if (!window[state.type]) { if (!window[state.type]) {
util.error("globalConfig: Missing StateMachine"); util.error("globalConfig: Missing StateMachine");
...@@ -2252,7 +2252,7 @@ ...@@ -2252,7 +2252,7 @@
case "hellojs": case "hellojs":
// test supported // test supported
if (foreign.modernizr) { if (foreign.modernizr) {
supported = util.testBrowserSupport(foreign.modernizr); supported = util.testSupport(foreign.modernizr);
} }
if (supported) { if (supported) {
app.default_dict.state_dict.login_pointer = hello; app.default_dict.state_dict.login_pointer = hello;
...@@ -2393,75 +2393,12 @@ ...@@ -2393,75 +2393,12 @@
} }
document.body.appendChild(target); document.body.appendChild(target);
} }
app.setGlobalBindings();
}); });
}) })
.then(app.setGlobalBindings)
.fail(util.error); .fail(util.error);
}, },
/**
* Generate a storage (module) based on the JSON config passed
* @method setStorage
* @param {object} content_dict JSON configuration for storage
**/
"setStorage": function (content_dict) {
var i, supported, props, promises = [];
props = content_dict.property_dict;
// setup JIO or alternative storage system here!
switch (props.storage_type) {
case "JIO":
// test supported
if (props.modernizr) {
supported = util.testBrowserSupport(
props.modernizr
);
}
// set force_field_definitions over include_docs
if (props.force_field_definitions) {
storage.force_fields = true;
}
// skip total_queries
if (props.skip_total_records) {
storage.skip_total = true;
}
if (supported || props.modernizr === undefined) {
// loop children = storages
for (i = 0; i < content_dict.children.length; i += 1) {
promises[i] = app.setContent(content_dict.children[i]);
}
}
return RSVP.all(promises);
default:
util.error("setStorage: Missing storage type");
return RSVP.all(promises);
}
},
/**
* Generate a specific storage
* @method makeStorage
* @param {object} content_dict JSON configuration for specific storage
**/
"makeStorage": function (content_dict) {
var quirk_dict, definition, name;
quirk_dict = content_dict.property_dict;
definition = quirk_dict.definition;
name = definition.application_name || quirk_dict.set_name;
if (!name || !definition) {
util.error("makeStorage: missing storage name/definition");
}
storage[name] = jIO.createJIO(definition);
storage[name].dict = definition;
return RSVP.all([]);
},
/** /**
* Pick page_dict to load based on URL * Pick page_dict to load based on URL
* @method pageindex * @method pageindex
...@@ -3091,7 +3028,7 @@ ...@@ -3091,7 +3028,7 @@
}; };
// only add last button, if total is available // only add last button, if total is available
if (storage.skip_total === undefined) { if (storage.property_dict.skip_total === undefined) {
config.children[0].children.push({ config.children[0].children.push({
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct":{"className":"action", "href":"#"},
...@@ -5896,7 +5833,8 @@ ...@@ -5896,7 +5833,8 @@
"data": "data", "data": "data",
"home": "home" "home": "home"
}, },
"state_dict": {} "state_dict": {},
"empty_array": []
}; };
/** /**
...@@ -6501,7 +6439,7 @@ ...@@ -6501,7 +6439,7 @@
info_field_list = element.querySelectorAll(".info"); info_field_list = element.querySelectorAll(".info");
info = ""; info = "";
no_total = total === undefined && storage.skip_total; no_total = total === undefined && storage.property_dict.skip_total;
generateInfo = function (text, text_i18n) { generateInfo = function (text, text_i18n) {
return factory.element( return factory.element(
"span", "span",
...@@ -6759,7 +6697,7 @@ ...@@ -6759,7 +6697,7 @@
obj.include_docs = true; obj.include_docs = true;
} }
if (field_list && field_list.length > 0 && storage.force_fields) { if (field_list && field_list.length > 0 && storage.property_dict.force_fields) {
delete obj.include_docs; delete obj.include_docs;
obj.select_list = field_list; obj.select_list = field_list;
} }
...@@ -7125,13 +7063,13 @@ ...@@ -7125,13 +7063,13 @@
// is set, because then we fetch by columns only (not whole docs) // is set, because then we fetch by columns only (not whole docs)
if (storage === undefined || if (storage === undefined ||
(storage && storage.force_fields === undefined)) { (storage && storage.property_dict.force_fields === undefined)) {
pass.state.query.include_docs = true; pass.state.query.include_docs = true;
} }
pass.state.query.limit = pass.store_limit; pass.state.query.limit = pass.store_limit;
} else { } else {
// get the columns required based on the gadget config! // get the columns required based on the gadget config!
if (pass.fields && storage && storage.force_fields) { if (pass.fields && storage && storage.property_dict.force_fields) {
if (pass.config.scheme) { if (pass.config.scheme) {
pass.field_list = storage.makeSelectList(pass.config.scheme); pass.field_list = storage.makeSelectList(pass.config.scheme);
} }
...@@ -7740,7 +7678,7 @@ ...@@ -7740,7 +7678,7 @@
pass = parcel.pass; pass = parcel.pass;
query = parcel.query; query = parcel.query;
skip = query && query.limit && query.limit.length === 0 && storage.skip_total; skip = query && query.limit && query.limit.length === 0 && storage.property_dict.skip_total;
// return here, if skipping total query // return here, if skipping total query
...@@ -7765,7 +7703,7 @@ ...@@ -7765,7 +7703,7 @@
if (select_list && parcel.query.include_docs === undefined) { if (select_list && parcel.query.include_docs === undefined) {
convert = "values"; convert = "values";
} }
console.log(storage)
return storage[parcel.storage][method || "allDocs"](parcel.query, hacked_view) return storage[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
.then(function (response) { .then(function (response) {
// TODO: best way? // TODO: best way?
...@@ -8510,7 +8448,7 @@ ...@@ -8510,7 +8448,7 @@
* @param testBrowserSupport * @param testBrowserSupport
* @method {array} property_list Features to be tested * @method {array} property_list Features to be tested
*/ */
util.testBrowserSupport = function (property_list) { util.testSupport = function (property_list) {
var j, supported, fail, message, container; var j, supported, fail, message, container;
if (Modernizr) { if (Modernizr) {
...@@ -8568,6 +8506,116 @@ ...@@ -8568,6 +8506,116 @@
} }
}; };
/**
* Merge object 1 and object 2
* @method merge
* @param {object} Object 1 to merge into object 2 (including overwrites)
* @param {objcet} Object 2
* @return {object} merged object
**/
util.mergeObject = function (a, b) {
var attribute;
for (attribute in a) {
if (a.hasOwnProperty(attribute)) {
b[attribute] = a[attribute];
}
}
return b;
};
/* ====================================================================== */
/* APP INIT */
/* ====================================================================== */
app.init = {
"testSupport" : function (property_list) {
var j, no_support, fail, message;
if (Modernizr) {
fail = "";
for (j = 0; j < property_list.length; j += 1) {
if (Modernizr[property_list[j]] === false) {
no_support = true;
fail += property_list[j] + "|";
}
}
if (no_support) {
message = fail.splice(0, -1);
util.error("browser: " + message + " not supported");
app.noItemsFound({
"message": "Your browser does not support: ",
"message_i18n": null,
"dynamic": message
});
return false;
}
return true;
}
util.error("testSupport: Modernizr requested but undefined");
return true;
},
"config" : function (content_dict) {
var i, j, k, arr, promise_list, len, feature, feature_len, name, dict,
set, child_len, type, nav, language;
set = app.default_dict;
arr = set.empty_array;
promise_list = [];
len = content_dict.length;
for (i = 0; i < len; i += 1) {
feature = content_dict[i];
feature_len = (feature.scheme || arr).length;
type = feature.type;
// support
if (app.init.testSupport(feature.modernizr || [])) {
// TODO: would be nice if generic, without eval()...
switch (feature.set_on) {
case "storage":
set = storage;
util.mergeObject(feature.property_dict, set.property_dict || {});
break;
}
// NOTE: defaulting to setting the global on app.default_dict, so
// there is no need to query against window.xyz
for (j = 0; j < feature_len; j += 1) {
dict = feature.scheme[j];
name = dict.set_name ||
dict.property_dict.application_name || type;
// TODO: not generic, try to remove
switch (feature.handle) {
case "language":
// force browser language in i18n
nav = window.navigator;
language = nav.userLanguage || nav.language;
if (language && feature.property_dict.use_browser_language) {
dict.fallbackLng = dict.lng;
dict.lng = language;
}
break;
}
// set promise
set[name] = promise_list[j] =
window[type][feature.initializer](dict.property_dict) || window[type];
}
}
child_len = (feature.children || arr).length;
for (k = 0; k < child_len; k += 1) {
promise_list[j + k] = app.setContent(content_dict.children[k]);
}
}
return RSVP.all(promise_list);
}
};
/* ====================================================================== */ /* ====================================================================== */
/* ENTRY POINT */ /* ENTRY POINT */
...@@ -8585,7 +8633,7 @@ ...@@ -8585,7 +8633,7 @@
"optional": true, "optional": true,
"skip": true "skip": true
}) })
.then(app.setContent) .then(app.init.config)
.then(function () { .then(function () {
return app.loadFile({ return app.loadFile({
"url": util.fetchPath("data-config") "url": util.fetchPath("data-config")
......
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