Commit 5354ad8e authored by Sven Franck's avatar Sven Franck

removed setGlobalConfiguration, harmonized module configuration

parent e4c0347e
......@@ -35,6 +35,20 @@
}
}]
},
{
"type": "hello",
"set_on": "login_dict",
"modernizr": ["localStorage"],
"property_dict": {
"use_login": true
},
"scheme": [{
"property_dict": {
"google" : "1028374738607-pg2qqcopjpoc09shlpul3mehu2dv76ln.apps.googleusercontent.com"
}
}],
"children": []
},
{
"type": "i18n",
"set_on": "lang_dict",
......@@ -136,7 +150,9 @@
"property_dict": {
"direction": "horizontal"
},
"children": []
"children": [
{"type":"a", "direct": {"href": "#global-popup", "className":"responsive action"}, "attributes": {"data-depend":"login_state", "data-rel":"popup", "data-action":"login", "data-icon":"user", "data-i18n":"global_dict.login"}, "logic": {"text":"Login"}}
]
}]
}]
}
......
......@@ -4,6 +4,12 @@
"initializer": "createJIO",
"modernizr": ["blobconstructor", "filereader"],
"property_dict": {
"name_dict": {
"gadgets": "gadgets",
"configuration": "configuration",
"data_type": "portal_type",
"settings": "settings"
},
"storage": true,
"force_field_definitions": true,
"skip_total_records": true
......
......@@ -546,7 +546,7 @@
"installed_services": function (reply) {
var config, property, query, fetch, href, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
// access storage
......@@ -589,7 +589,7 @@
"release_list": function (reply) {
var config, property, query, fetch, href, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
// access storage
......@@ -632,7 +632,7 @@
"software_list": function (reply) {
var config, property, query, props, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
config = {
......@@ -683,7 +683,7 @@
"subscription_details": function (reply) {
var config, property, query, fetch, href, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
// access storage
......@@ -726,7 +726,7 @@
"ticketing": function (reply) {
var config, property, query, href, i, reply, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
config = {
......@@ -784,7 +784,7 @@
"ticket_status": function (reply) {
var fetch, config, property, query, href, i, store, reply, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
// access storage
......@@ -827,7 +827,7 @@
"servers": function (reply) {
var config, property, query, href, i, store, reply, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict) {
config = {
......@@ -884,7 +884,7 @@
"invoices": function (reply) {
var config, property, query, href, i, reply, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
config = {
......@@ -941,7 +941,7 @@
"networks": function (reply) {
var config, property, query, href, i, reply, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
config = {
......@@ -999,7 +999,7 @@
"subscriptions": function (reply) {
var config, property, query, href, i, reply, store, pass = reply.pass;
store = app.default_dict.storage_dict;
store = app.storage_dict;
if (store.property_dict.storage) {
config = {
......@@ -1120,7 +1120,7 @@
id = obj.state.fragment_list[1];
formData = new FormData();
store = app.default_dict.storage_dict;
store = app.storage_dict;
valid = storage.validate(obj.gadget);
decode = /^[^\/]*%2[^\/]*$/.test(id);
......@@ -1179,7 +1179,7 @@
id = obj.state.fragment_list[1];
element = obj.element;
store = app.default_dict.storage_dict;
store = app.storage_dict;
formData = new FormData();
decode = /^[^\/]*%2[^\/]*$/.test(id);
......@@ -1214,7 +1214,7 @@
id = obj.state.fragment_list[1];
element = obj.element;
store = app.default_dict.storage_dict;
store = app.storage_dict;
formData = new FormData();
decode = /^[^\/]*%2[^\/]*$/.test(id);
......@@ -1294,7 +1294,7 @@
"download": function (obj) {
var store;
store = app.default_dict.storage_dict;
store = app.storage_dict;
util.loader("", "status_dict.downloading");
store.items.get({"_id": window.decodeURIComponent(obj.element.href.split("/").pop())},{"_view": "web_view"})
......@@ -1637,7 +1637,7 @@
id = obj.state.fragment_list[1];
formData = new FormData();
store = app.default_dict.storage_dict;
store = app.storage_dict;
valid = storage.validate(obj.gadget);
decode = /^[^\/]*%2[^\/]*$/.test(id);
......@@ -2392,205 +2392,6 @@
**/
map.gadgets = {
/**
* Setup global configuration for app
* @method setGlobalConfiguration
* @param {object} content_dict JSON configuration for global setup
**/
"setGlobalConfiguration": function (content_dict) {
var i, j, k, translator, single_path, supported, target, language,
container, foreign, promises, path_flag, status_flag, set_state,
multi_language_flag, force_browser_language, logger, element,
set_login, skip_restore, state, support_state;
promises = [];
path_flag = content_dict.property_dict.path_dict;
status_flag = content_dict.property_dict.status_dict;
multi_language_flag = content_dict.property_dict.i18n;
force_browser_language = content_dict.property_dict
.i18n_force_browser_language;
logger = content_dict.property_dict.login_dict;
// this will manage offline and login states!
state = content_dict.property_dict.state_dict;
// initialize state machine
if (state) {
switch (state.type) {
case "StateMachine":
support_state = true;
if (state.modernizr) {
support_state = util.testSupport(state.modernizr);
}
if (!window[state.type]) {
util.error("globalConfig: Missing StateMachine");
}
if (support_state) {
for (k = 0; k < state.machine_list.length; k += 1) {
app.default_dict.state_dict[state.machine_list[k].machine_name] =
window[state.type].create(state.machine_list[k].property_dict);
}
}
break;
}
}
// make sure login is only setup if needed
if (logger !== undefined) {
app.default_dict.state_dict.login = true;
foreign = logger.third_party;
if (foreign) {
switch (foreign.provider) {
case "hellojs":
// test supported
if (foreign.modernizr) {
supported = util.testSupport(foreign.modernizr);
}
if (supported) {
app.default_dict.state_dict.login_pointer = hello;
app.default_dict.state_dict.no_auth = logger.no_auth;
if (hello) {
// initialize hellojs
hello.init(foreign.initializer_dict, foreign.redirect);
app.default_dict.state_dict.verification_dict =
foreign.verification_dict;
set_login = true;
} else {
util.error("globalConfig: Missing hellojs");
}
}
break;
}
}
}
// setup loader
if (status_flag) {
switch (status_flag.type) {
case "loader":
app.default_dict.property_dict.loader = true;
app.default_dict.property_dict.loader_theme = status_flag.theme;
break;
}
}
// create path dict
if (path_flag) {
for (single_path in path_flag) {
if (path_flag.hasOwnProperty(single_path)) {
app.default_dict.property_dict[single_path] = path_flag[single_path];
}
}
} else {
util.error("globalConfig: Missing path dict");
}
// i18n
if (multi_language_flag) {
language = window.navigator.userLanguage || window.navigator.language;
switch (multi_language_flag) {
case "i18next":
translator = content_dict.property_dict.i18n_dict;
if (translator) {
// overwrite with browser language if specified
if (language && force_browser_language) {
translator.fallbackLng = translator.lng;
translator.lng = language;
}
promises[content_dict.children.length + 1] =
i18n.init(translator, function () {
return;
});
} else {
util.error("globalConfig: Missing i18n configuration");
}
break;
}
}
// start setup
app.checkLoginStatus(set_login)
.then(function (response) {
if (response.error) {
skip_restore = true;
}
// finish, if no login required
if (response && response.pass) {
return;
}
// set login state
if (response && response.user_id) {
set_state = "logoff";
} else {
set_state = "login";
}
return set_state;
})
.then(function (state) {
var open_auth;
// try to register user
if (skip_restore === undefined) {
if (foreign && foreign.initializer_dict) {
for (open_auth in foreign.initializer_dict) {
if (foreign.initializer_dict.hasOwnProperty(open_auth)) {
return app.register(open_auth)
.then(function () {
return state;
});
}
}
}
}
return state;
})
.then(function () {
// global elements
if (content_dict.children) {
for (i = 0; i < content_dict.children.length; i += 1) {
element = content_dict.children[i];
element.set_state = set_state;
promises[i] = app.setContent(element);
}
}
return RSVP.all(promises)
.then(function (promises) {
// create a fragment for promises
target = document.createDocumentFragment();
for (j = 0; j < promises.length; j += 1) {
container = promises[j];
// exclude undefined promises (i18n)
if (container && container.nodeName) {
// translate
if (i18n) {
map.actions.translateNodeList(container);
}
// insert panel as first child into DOM
if (util.testForString("ui-panel", container.className)) {
document.body.insertBefore(
container,
document.body.children[0]
);
} else {
target.appendChild(container);
}
}
document.body.appendChild(target);
}
});
})
.then(app.setGlobalBindings)
.fail(util.error);
},
/**
* Pick page_dict to load based on URL
* @method pageindex
......@@ -2643,7 +2444,7 @@
// no auth
if (answer === null) {
target = factory.util.wrapInForm(spec);
target.appendChild(no_content(app.default_dict.state_dict.no_auth));
target.appendChild(no_content(app.state_dict.no_auth));
return target;
}
......@@ -2805,7 +2606,7 @@
// no auth
if (answer === null) {
target = factory.util.wrapInForm(spec);
target.appendChild(no_content(app.default_dict.state_dict.no_auth));
target.appendChild(no_content(app.state_dict.no_auth));
return target;
}
......@@ -2964,7 +2765,7 @@
spec.reset = reset_state;
spec.depend = update_gadget;
target = factory.util.wrapInForm(spec);
target.appendChild(no_content(app.default_dict.state_dict.no_auth));
target.appendChild(no_content(app.state_dict.no_auth));
return target;
// auth or allow
......@@ -3220,7 +3021,7 @@
};
// only add last button, if total is available
if (!app.default_dict.storage_dict.property_dict.skip_total_records) {
if (!app.storage_dict.property_dict.skip_total_records) {
config.children[0].children.push({
"type": "a",
"direct":{"className":"action", "href":"#"},
......@@ -3401,8 +3202,8 @@
// fetch content
app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"file": app.default_dict.storage_dict.gadgets,
"storage": app.storage_dict.settings,
"file": app.storage_dict.property_dict.name_dict.gadgets,
"attachment": reference,
"pass": undefined
})
......@@ -5935,7 +5736,7 @@
}
util.loader("", "status_dict.saving");
console.log("mh")
// TODO: a post should always include all required fields
// TODO: find a way to set default fields, like timestamp etc
app.store({
......@@ -5951,7 +5752,6 @@
}
})
.then(function (answer) {
console.log("do we get here=")
if (answer.response && answer.response.result === "success") {
pass_id = answer.response.id;
switch (config.gadget.getAttribute("data-reset")) {
......@@ -6011,19 +5811,9 @@
app = {};
/**
* @object {object} Object containing default names, which can be overridden
**/
app.default_dict = {
"storage_dict": {
"settings": "settings",
"configuration": "configuration",
"gadgets": "gadgets",
"data_type": "portal_types"
},
"lang_dict": {},
"state_dict": {},
"empty_array": []
};
* Fallback for undefined arrays (faster to lookup than to create)
*/
app.empty_array = [];
/**
* Timer for 500ms delayed actions
......@@ -6082,8 +5872,8 @@
// need field values for allDocs select_list...
return app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"file": app.default_dict.storage_dict.data_type,
"storage": app.storage_dict.settings,
"file": app.storage_dict.property_dict.name_dict.data_type,
"attachment": "person_fieldlist",
"pass": {"query": query, "profile": profile}
})
......@@ -6519,8 +6309,8 @@
return RSVP.resolve({"pass": skip});
}
logger = app.default_dict.state_dict.login_pointer;
verify = app.default_dict.state_dict.verification_dict;
logger = app.state_dict.login_pointer;
verify = app.state_dict.verification_dict;
if (logger) {
......@@ -6627,7 +6417,7 @@
info_field_list = element.querySelectorAll(".info");
info = "";
no_total = total === undefined && app.default_dict.storage_dict.property_dict.skip_total_records;
no_total = total === undefined && app.storage_dict.property_dict.skip_total_records;
generateInfo = function (text, text_i18n) {
return factory.element(
"span",
......@@ -6885,7 +6675,7 @@
obj.include_docs = true;
}
if (field_list && field_list.length > 0 &&
app.default_dict.storage_dict.property_dict.force_field_definitions) {
app.storage_dict.property_dict.force_field_definitions) {
delete obj.include_docs;
obj.select_list = field_list;
}
......@@ -7042,7 +6832,7 @@
// home
breadcrumb.appendChild(
makeLink(app.default_dict.property_dict.home, undefined, true)
makeLink(app.property_dict.home, undefined, true)
);
// fragments
......@@ -7237,7 +7027,7 @@
app.fetchDataQuery = function (reply) {
var parsed, pass = reply.pass, key, value, force_fields;
force_fields = app.default_dict.storage_dict.property_dict.force_field_definitions;
force_fields = app.storage_dict.property_dict.force_field_definitions;
if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login))) {
......@@ -7427,7 +7217,7 @@
pass.fields = util.parse(reply.response);
}
store = app.default_dict.storage_dict.items;
store = app.storage_dict.items;
items = util.parse(reply.response);
if (store && items.length > 0) {
......@@ -7448,8 +7238,8 @@
// TODO: bad way to set attachment value!!
return app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"file": app.default_dict.storage_dict.data_type,
"storage": app.storage_dict.settings,
"file": app.storage_dict.property_dict.name_dict.data_type,
"attachment": pass.type.toLowerCase() + "_fieldlist",
"pass": pass
})
......@@ -7496,9 +7286,7 @@
// obj.portal_type = pass.type;
// if an object identifier was set in the form, we PUT, else POST
console.log("so.... where is the identifier")
console.log(obj)
console.log(obj.identifier)
if (obj.identifier) {
method = "put";
hacked_view = {"_view": pass.view};
......@@ -7514,10 +7302,9 @@
.fail(util.error);
}
} else {
console.log("here?")
// do it again, Sam...
promises[0] = jIO.util.ajax({
"url": app.default_dict.storage_dict.items.dict.url,
"url": app.storage_dict.items.dict.url,
"type": "GET",
"xhrFields": {
"withCredentials": true
......@@ -7665,8 +7452,8 @@
// TODO: keep this until sample handling is removed
pass.needs_fields = true;
return app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"file": app.default_dict.storage_dict.data_type,
"storage": app.storage_dict.settings,
"file": app.storage_dict.property_dict.name_dict.data_type,
"attachment": pass.config.portal_type_fields,
"pass": pass
});
......@@ -7693,7 +7480,7 @@
pass.type = parsed.portal_type_source;
// if app uses login and gadget requires auth
if (app.default_dict.state_dict.login &&
if (app.state_dict.login &&
parsed.property_dict.requires_authentication) {
pass.auth = parsed.property_dict.requires_authentication;
}
......@@ -7774,10 +7561,10 @@
// and go
return app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"file": pass.href ? app.default_dict.storage_dict.gadgets :
app.default_dict.storage_dict.settings,
"attachment": pass.href || app.default_dict.storage_dict.configuration,
"storage": app.storage_dict.settings,
"file": pass.href ? app.storage_dict.property_dict.name_dict.gadgets :
app.storage_dict.property_dict.name_dict.settings,
"attachment": pass.href || app.storage_dict.property_dict.name_dict.configuration,
"pass": pass
})
.then(app.checkAuth)
......@@ -7873,7 +7660,7 @@
pass = parcel.pass;
query = parcel.query;
skip = query && query.limit && query.limit.length === 0 &&
app.default_dict.storage_dict.property_dict.skip_total_records;
app.storage_dict.property_dict.skip_total_records;
// return here, if skipping total query
......@@ -7899,7 +7686,7 @@
convert = "values";
}
return app.default_dict.storage_dict[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
return app.storage_dict[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
.then(function (response) {
// TODO: best way?
if (convert !== undefined && response.status === 200) {
......@@ -7926,7 +7713,7 @@
app.loadFile = function (property_dict) {
var response, storage_location, url, hacked_view;
url = property_dict.url || app.default_dict.property_dict.data +
url = property_dict.url || app.property_dict.data +
property_dict.attachment + ".json";
// no url... throw error unless optional is set!
......@@ -7949,7 +7736,7 @@
// store file
storage_location = property_dict.store ||
(storage ? app.default_dict.storage_dict.settings : undefined);
(storage ? app.storage_dict.settings : undefined);
// hacked view?
if (property_dict && property_dict.pass && property_dict.pass.config) {
......@@ -7969,7 +7756,7 @@
return storage_location.putAttachment({
"_id": (property_dict.file || "settings"),
"_attachment": (property_dict.attachment ||
app.default_dict.storage_dict.configuration),
app.storage_dict.property_dict.name_dict.configuration),
"_data": JSON.stringify(response),
"_mimetype": "application/json"
});
......@@ -8079,7 +7866,7 @@
}
return app.fetchConfig({
"storage": app.default_dict.storage_dict.settings,
"storage": app.storage_dict.settings,
"file": "pages",
"attachment": destination,
"pass": undefined
......@@ -8427,13 +8214,13 @@
// hm... jQuery... hm string building
// TODO: better way?
if (app.default_dict.property_dict.loader) {
if (app.property_dict.loader) {
$.mobile.loading(
"show",
{
"text": "",
"textVisible": true,
"theme": app.default_dict.property_dict.loader_theme,
"theme": app.property_dict.loader_theme,
"html": "<span class='ui-icon-" +
(icon ? (icon + " loader_icon") : "loading") + "'> </span>" +
"<h1 class='loader_message'>" + text_to_display + "</h1>"
......@@ -8753,8 +8540,7 @@
var i, j, k, arr, promise_list, len, feature, feature_len, name, dict,
set, child_len, type, nav, language, target, initializer, solver;
set = app.default_dict;
arr = set.empty_array;
arr = app.empty_array;
promise_list = [];
len = content_dict.length;
......@@ -8763,10 +8549,12 @@
// test support
if (app.init.testSupport(feature.modernizr || [])) {
set = feature.set_on;
feature_len = (feature.scheme || arr).length;
type = feature.type;
target = set[feature.set_on] || set;
initializer = feature.initializer;
target = (set ? app[feature.set_on] = {} : undefined) || app;
// merge properties on target
target.property_dict = util.mergeObject(
......@@ -8774,7 +8562,7 @@
target.property_dict || {}
);
// NOTE: Set all globals on app.default_dict and reference from there
// NOTE: Set all globals on app and reference from there
for (j = 0; j < feature_len; j += 1) {
dict = feature.scheme[j];
name = dict.set_name || dict.property_dict.application_name || type;
......@@ -8787,7 +8575,7 @@
case "language":
nav = window.navigator;
language = nav.userLanguage || nav.language;
if (language && set.property_dic.use_browser_language) {
if (language && target.property_dict.use_browser_language) {
dict.fallbackLng = dict.lng;
dict.lng = language;
}
......@@ -8809,7 +8597,7 @@
// TODO: remove all this, should be handled by setContent
.then (function (response_list) {
var target, l, container, i18n;
// create a fragment for promises
target = document.createDocumentFragment();
......
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