Commit d4d7d09d authored by Sven Franck's avatar Sven Franck

breaking global config

parent e4b52a2a
This diff is collapsed.
{
"generate":"gadget",
"type": "setStorage",
[{
"type": "jIO",
"set_on": "storage",
"initializer": "createJIO",
"modernizr": ["blobconstructor", "filereader"],
"property_dict": {
"force_field_definitions": true,
"storage_type": "JIO",
"skip_total_records": true,
"modernizr": ["blobconstructor", "filereader"]
"skip_total_records": true
},
"children": [{
"generate": "gadget",
"type": "makeStorage",
"scheme": [{
"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",
"username": "slapos",
"application_name": "settings"
}
}
}, {
"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
}]
}
"application_name": "items",
"yield": true
}]
}
}]
}
}],
"children": []
}]
\ No newline at end of file
......@@ -2228,7 +2228,7 @@
case "StateMachine":
support_state = true;
if (state.modernizr) {
support_state = util.testBrowserSupport(state.modernizr);
support_state = util.testSupport(state.modernizr);
}
if (!window[state.type]) {
util.error("globalConfig: Missing StateMachine");
......@@ -2252,7 +2252,7 @@
case "hellojs":
// test supported
if (foreign.modernizr) {
supported = util.testBrowserSupport(foreign.modernizr);
supported = util.testSupport(foreign.modernizr);
}
if (supported) {
app.default_dict.state_dict.login_pointer = hello;
......@@ -2393,75 +2393,12 @@
}
document.body.appendChild(target);
}
app.setGlobalBindings();
});
})
.then(app.setGlobalBindings)
.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
* @method pageindex
......@@ -3091,7 +3028,7 @@
};
// 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({
"type": "a",
"direct":{"className":"action", "href":"#"},
......@@ -5896,7 +5833,8 @@
"data": "data",
"home": "home"
},
"state_dict": {}
"state_dict": {},
"empty_array": []
};
/**
......@@ -6501,7 +6439,7 @@
info_field_list = element.querySelectorAll(".info");
info = "";
no_total = total === undefined && storage.skip_total;
no_total = total === undefined && storage.property_dict.skip_total;
generateInfo = function (text, text_i18n) {
return factory.element(
"span",
......@@ -6759,7 +6697,7 @@
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;
obj.select_list = field_list;
}
......@@ -7125,13 +7063,13 @@
// is set, because then we fetch by columns only (not whole docs)
if (storage === undefined ||
(storage && storage.force_fields === undefined)) {
(storage && storage.property_dict.force_fields === undefined)) {
pass.state.query.include_docs = true;
}
pass.state.query.limit = pass.store_limit;
} else {
// 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) {
pass.field_list = storage.makeSelectList(pass.config.scheme);
}
......@@ -7740,7 +7678,7 @@
pass = parcel.pass;
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
......@@ -7765,7 +7703,7 @@
if (select_list && parcel.query.include_docs === undefined) {
convert = "values";
}
console.log(storage)
return storage[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
.then(function (response) {
// TODO: best way?
......@@ -8510,7 +8448,7 @@
* @param testBrowserSupport
* @method {array} property_list Features to be tested
*/
util.testBrowserSupport = function (property_list) {
util.testSupport = function (property_list) {
var j, supported, fail, message, container;
if (Modernizr) {
......@@ -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 */
......@@ -8585,7 +8633,7 @@
"optional": true,
"skip": true
})
.then(app.setContent)
.then(app.init.config)
.then(function () {
return app.loadFile({
"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