Commit b286b8c0 authored by Sven Franck's avatar Sven Franck

jslint

parent a66ebf80
/*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true, todo: true */ /*jslint indent: 2, maxlen: 80, nomen: true, sloppy: true, todo: true */
/*global console, window, jIO, complex_queries, FormData, RSVP, document, /*global console, window, jIO, complex_queries, FormData, RSVP, document,
jQuery, i18n, Recaptcha, XMLHttpRequest, Modernizr */ jQuery, i18n, Recaptcha, XMLHttpRequest, alert, Modernizr */
(function (window, document, $) { (function (window, document, $) {
"use strict"; "use strict";
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
**/ **/
// TODO: optgroup support! // TODO: optgroup support!
factory.element = function (spec) { factory.element = function (spec) {
var element, setter, attribute, logic, item, i, j, mock, recurse, pic; var element, setter, attribute, logic, item, i, mock, recurse, pic;
// element // element
element = document.createElement(spec.type); element = document.createElement(spec.type);
...@@ -379,7 +379,8 @@ ...@@ -379,7 +379,8 @@
} }
// class string: assemble // class string: assemble
container_class_list += (no_validate ? "" : " ui-corner-all ui-shadow-inset") + container_class_list += (no_validate ? "" :
" ui-corner-all ui-shadow-inset") +
disabled + readonly + (action || "") + (clear || "") + disabled + readonly + (action || "") + (clear || "") +
(theme ? (" ui-bar-" + theme + " ") : " ui-body-inherit "); (theme ? (" ui-bar-" + theme + " ") : " ui-body-inherit ");
} }
...@@ -466,7 +467,7 @@ ...@@ -466,7 +467,7 @@
"type": "span", "type": "span",
"direct": {"className": "ui-invalid-label"}, "direct": {"className": "ui-invalid-label"},
"attributes": {}, "attributes": {},
"logic": {"text":"wrong"} "logic": {"text": "wrong"}
})); }));
} }
...@@ -594,7 +595,7 @@ ...@@ -594,7 +595,7 @@
} else { } else {
target = container.querySelector("[data-update]") || target = container.querySelector("[data-update]") ||
container.querySelector("div.ui-content") || container.querySelector("div.ui-content") ||
container container;
} }
// return new page and/or pointer to gadget content container // return new page and/or pointer to gadget content container
...@@ -641,7 +642,7 @@ ...@@ -641,7 +642,7 @@
* @return {object} object including fragment, child-selector, placeholder * @return {object} object including fragment, child-selector, placeholder
**/ **/
factory.widget.collapsibleset = function (spec) { factory.widget.collapsibleset = function (spec) {
var container, fragment, form, obj, prop; var container, form, obj, prop;
// TODO: why spec.set, BS? // TODO: why spec.set, BS?
if (spec.set) { if (spec.set) {
...@@ -736,13 +737,13 @@ ...@@ -736,13 +737,13 @@
**/ **/
// TODO: add dynamic // TODO: add dynamic
factory.widget.collapsible = function (spec) { factory.widget.collapsible = function (spec) {
var container, header, target, link, form, tranlate, collapsed, translate; var container, header, target, link, form, collapsed, translate;
translate = spec.text_i18n ? "translate " : " "; translate = spec.text_i18n ? "translate " : " ";
collapsed = spec.collapsed === false; collapsed = spec.collapsed === false;
container = factory.element({ container = factory.element({
"type": spec.form ? "fieldset": "div", "type": spec.form ? "fieldset" : "div",
"direct": { "direct": {
"className": "ui-collapsible " + (spec.mini ? "ui-mini " : "") + "className": "ui-collapsible " + (spec.mini ? "ui-mini " : "") +
(!spec.inset ? "" : "ui-collapsible-inset ui-corner-all ") + (!spec.inset ? "" : "ui-collapsible-inset ui-corner-all ") +
...@@ -789,7 +790,7 @@ ...@@ -789,7 +790,7 @@
}, },
"logic": { "logic": {
"data-i18n": spec.text_i18n ? ("[node]" + spec.text_i18n) : null, "data-i18n": spec.text_i18n ? ("[node]" + spec.text_i18n) : null,
"data-ajax": spec.href ? "false" : null, "data-ajax": spec.href ? "false" : null
} }
}); });
link.appendChild(document.createTextNode(spec.text || "\u00A0")); link.appendChild(document.createTextNode(spec.text || "\u00A0"));
...@@ -810,7 +811,8 @@ ...@@ -810,7 +811,8 @@
"type": "div", "type": "div",
"direct": { "direct": {
"className": "ui-collapsible-content " + (spec.collapsed === false ? "className": "ui-collapsible-content " + (spec.collapsed === false ?
"" : "ui-collapsible-content-collapsed ") + "ui-body-" + (spec.content_theme || "inherit") "" : "ui-collapsible-content-collapsed ") + "ui-body-" +
(spec.content_theme || "inherit")
}, },
"attributes": { "attributes": {
"aria-hidden": spec.collapsed === false ? false : true "aria-hidden": spec.collapsed === false ? false : true
...@@ -1011,7 +1013,7 @@ ...@@ -1011,7 +1013,7 @@
"direct": {"className": "ui-fieldcontain translate"}, "direct": {"className": "ui-fieldcontain translate"},
"attributes": {"title": spec.label.title}, "attributes": {"title": spec.label.title},
"logic": { "logic": {
"data-i18n": i18n ? ("[title]" + spec.label.title_i18n) : null, "data-i18n": i18n ? ("[title]" + spec.label.title_i18n) : null
} }
}); });
label = factory.element({ label = factory.element({
...@@ -1118,7 +1120,7 @@ ...@@ -1118,7 +1120,7 @@
// add popup // add popup
wrap.appendChild(factory.element({ wrap.appendChild(factory.element({
"type": "div", "type": "div",
"direct":{ "direct": {
"className": "ui-popup ui-body-" + spec.theme + "className": "ui-popup ui-body-" + spec.theme +
(spec.shadow ? " ui-overlay-shadow " : " ") + (spec.shadow ? " ui-overlay-shadow " : " ") +
" ui-corner-all " + spec.class_list, " ui-corner-all " + spec.class_list,
...@@ -1211,9 +1213,9 @@ ...@@ -1211,9 +1213,9 @@
return { return {
"fragment": container, "fragment": container,
"child_selector": container.querySelector("div#" + id), "child_selector": container.querySelector("div#" + id)
};
}; };
}
/* ********************************************************************** */ /* ********************************************************************** */
/* JQM Navbar */ /* JQM Navbar */
...@@ -1241,7 +1243,9 @@ ...@@ -1241,7 +1243,9 @@
target = function (j) { target = function (j) {
return factory.element({ return factory.element({
"type": "li", "type": "li",
"direct": {"className": "ui-block-" + util.toLetter(j + 1).toLowerCase()} "direct": {
"className": "ui-block-" + util.toLetter(j + 1).toLowerCase()
}
}); });
}; };
...@@ -1296,7 +1300,7 @@ ...@@ -1296,7 +1300,7 @@
* @return {object} fragment * @return {object} fragment
*/ */
factory.widget.controlbar = function (spec) { factory.widget.controlbar = function (spec) {
var container, slot, pass, class_list, wrap; var container, slot, pass, class_list;
pass = function (container) { pass = function (container) {
return { return {
...@@ -1304,7 +1308,7 @@ ...@@ -1304,7 +1308,7 @@
"child_selector": container.firstElementChild || container, "child_selector": container.firstElementChild || container,
"add_on_dom": spec.target === "document" "add_on_dom": spec.target === "document"
}; };
} };
container = document.createDocumentFragment(); container = document.createDocumentFragment();
slot = spec.slot; slot = spec.slot;
...@@ -1360,15 +1364,15 @@ ...@@ -1360,15 +1364,15 @@
*/ */
// NOTE: Needs JQM pre-enhancement if outside page! // NOTE: Needs JQM pre-enhancement if outside page!
factory.widget.panel = function (spec) { factory.widget.panel = function (spec) {
var container, id, wrap, fragment, closer, element; var container, id, wrap, closer;
container = document.createDocumentFragment(); container = document.createDocumentFragment();
id = spec.id || ((spec.data_url || "global") + "-panel"); id = spec.id || ((spec.data_url || "global") + "-panel");
// content wrapper with optional close button // content wrapper with optional close button
wrap = function (j, len) { wrap = function (j, len) {
switch (true) { var fragment, element;
case (j === 0): if (j === 0) {
fragment = document.createDocumentFragment(); fragment = document.createDocumentFragment();
element = factory.element({ element = factory.element({
"type": "div", "type": "div",
...@@ -1380,18 +1384,18 @@ ...@@ -1380,18 +1384,18 @@
element.appendChild(closer); element.appendChild(closer);
} }
fragment.appendChild(element); fragment.appendChild(element);
return fragment; } else if (j === len - 1) {
case (j === len - 1): fragment = factory.element({
return factory.element({
"type": "div", "type": "div",
"direct": {"className": "panel_element panel_element_last"} "direct": {"className": "panel_element panel_element_last"}
}); });
default: } else {
return factory.element({ fragment = factory.element({
"type": "div", "type": "div",
"direct": {"className": "panel_element"} "direct": {"className": "panel_element"}
}); });
} }
return fragment;
}; };
// panel // panel
...@@ -1459,7 +1463,7 @@ ...@@ -1459,7 +1463,7 @@
* @return HTML fragment * @return HTML fragment
*/ */
factory.widget.form = function (spec) { factory.widget.form = function (spec) {
var container, form_id, form, item_id, stamp, encode, sauce, captcha, wrap; var container, form_id, form, item_id, stamp, captcha, sauce, wrap;
container = document.createDocumentFragment(); container = document.createDocumentFragment();
form_id = "form_" + util.uuid(); form_id = "form_" + util.uuid();
...@@ -1500,6 +1504,7 @@ ...@@ -1500,6 +1504,7 @@
// TODO: only if shim is available! // TODO: only if shim is available!
//encode = window.btoa || window.shim.Base64.encode; //encode = window.btoa || window.shim.Base64.encode;
//sauce = encode(stamp.toString() + spec.secret_hash); //sauce = encode(stamp.toString() + spec.secret_hash);
sauce = undefined;
form.appendChild(factory.element({ form.appendChild(factory.element({
"type": "input", "type": "input",
...@@ -1556,6 +1561,7 @@ ...@@ -1556,6 +1561,7 @@
// assemble // assemble
container.appendChild(form); container.appendChild(form);
wrap = undefined;
return { return {
"fragment": container, "fragment": container,
"child_selector": container.querySelectorAll("form")[0], "child_selector": container.querySelectorAll("form")[0],
...@@ -1609,13 +1615,12 @@ ...@@ -1609,13 +1615,12 @@
**/ **/
factory.widget.carousel = function (spec) { factory.widget.carousel = function (spec) {
var fragment, generator, empty_string, has_handles, make_handle, is_thumb, var fragment, generator, empty_string, has_handles, make_handle, is_thumb,
controller, control, i, id, radio_id; controller, i, id, radio_id;
// makes carousel elements // makes carousel elements
generator = function (element, wrapper, i) { generator = function (element, wrapper, i) {
var item, config, target, has_link; var item, target, has_link;
config = wrapper.property_dict;
has_link = element.href; has_link = element.href;
item = factory.element({ item = factory.element({
"type": "li", "type": "li",
...@@ -1652,12 +1657,12 @@ ...@@ -1652,12 +1657,12 @@
"href": "#", "href": "#",
"className": "ui-carousel-handle ui-carousel-handle-" + direction + "className": "ui-carousel-handle ui-carousel-handle-" + direction +
" ui-btn ui-btn-icon-notext ui-corner-all ui-icon-carat-" + " ui-btn ui-btn-icon-notext ui-corner-all ui-icon-carat-" +
direction.slice(0,1) + " ui-shadow translate" direction.slice(0, 1) + " ui-shadow translate"
}, },
"attributes": {"data-i18n": "global_dict." + direction}, "attributes": {"data-i18n": "global_dict." + direction},
"logic": {"text": direction} "logic": {"text": direction}
}); });
} };
fragment = document.createDocumentFragment(); fragment = document.createDocumentFragment();
empty_string = ""; empty_string = "";
...@@ -1803,24 +1808,26 @@ ...@@ -1803,24 +1808,26 @@
// TODO: add collapsible support if needed // TODO: add collapsible support if needed
// TODO: dividers? will not be in spec, so can only be listview option! // TODO: dividers? will not be in spec, so can only be listview option!
factory.widget.listview = function (spec) { factory.widget.listview = function (spec) {
var fragment, filter, has_filter, generator; var fragment, has_filter, generator;
// generate list item // generate list item
generator = function (element, wrapper, i) { generator = function (element, wrapper, i) {
var divider, static_item, theme, config, auto, last, item, target, content; var divider, static_item, theme, config, auto, last, item, target, list,
content;
config = wrapper.property_dict; config = wrapper.property_dict;
divider = element.type === "divider" ? true : undefined; divider = element.type === "divider" ? true : undefined;
static_item = (element.href === undefined && !divider) ? true : undefined; static_item = (element.href === undefined && !divider) ? true : undefined;
theme = config.divider_theme || config.theme || "inherit"; theme = config.divider_theme || config.theme || "inherit";
// autodividers (TODO: does this work?) // autodividers (TODO: does this work? NO!!! do with i!)
if (config.autodividers) { if (config.autodividers) {
auto = element.text[0].text.slice(0, 1).toUpperCase(); auto = element.text[0].text.slice(0, 1).toUpperCase();
if (last !== auto) { if (last !== auto) {
list = document.createDocumentFragment();
list.appendChild(factory.element({ list.appendChild(factory.element({
"type": "li", "type": "li",
"direct":{ "direct": {
"className": "ui-li-divider ui-bar-" + theme + "className": "ui-li-divider ui-bar-" + theme +
(i === 0 ? " ui-first-child" : (i === 0 ? " ui-first-child" :
((i === config.length - 1) ? ((i === config.length - 1) ?
...@@ -1838,7 +1845,11 @@ ...@@ -1838,7 +1845,11 @@
target = document.createDocumentFragment(); target = document.createDocumentFragment();
} else { } else {
element.is_main = true; element.is_main = true;
target = factory.util.generateContentElement("link", element, config)[0]; target = factory.util.generateContentElement(
"link",
element,
config
)[0];
} }
// generate contents, split button will return [frag1, frag2, class_list] // generate contents, split button will return [frag1, frag2, class_list]
...@@ -1885,7 +1896,7 @@ ...@@ -1885,7 +1896,7 @@
// NOTE: if input provided, the filter is already there! // NOTE: if input provided, the filter is already there!
if (spec.filter && spec.input === undefined) { if (spec.filter && spec.input === undefined) {
has_filter = true; has_filter = true;
filter = factory.widget.formElement({ fragment.appendChild(factory.widget.formElement({
"type": "input", "type": "input",
"direct": { "direct": {
"id": "filter_" + (spec.id || "items"), "id": "filter_" + (spec.id || "items"),
...@@ -1901,7 +1912,7 @@ ...@@ -1901,7 +1912,7 @@
"logic": { "logic": {
"clear": "true" "clear": "true"
} }
}); }));
} }
fragment.appendChild(factory.element({ fragment.appendChild(factory.element({
...@@ -2033,7 +2044,7 @@ ...@@ -2033,7 +2044,7 @@
}; };
generator = function (element, wrapper, i) { generator = function (element, wrapper, i) {
var item, quirk_dict, row, temp, cell, j, field, link, logic, faux_id, var quirk_dict, row, temp, cell, j, field, link, logic, faux_id,
attributes, property, snippet, title, k, button, group, dict, set, attributes, property, snippet, title, k, button, group, dict, set,
wrap, lookup, item_href; wrap, lookup, item_href;
...@@ -2047,13 +2058,11 @@ ...@@ -2047,13 +2058,11 @@
// checkbox/radio // checkbox/radio
if (!quirk_dict.no_items && (quirk_dict.check || quirk_dict.radio)) { if (!quirk_dict.no_items && (quirk_dict.check || quirk_dict.radio)) {
switch (true) { if (quirk_dict.global_check) {
case (quirk_dict.global_check):
element.action = "check_all"; element.action = "check_all";
break; }
case (quirk_dict.check && !quirk_dict.global_check): if (quirk_dict.check && !quirk_dict.global_check) {
element.action = "check_all_visible"; element.action = "check_all_visible";
break;
} }
cell = factory.element({"type": "th"}); cell = factory.element({"type": "th"});
faux_id = wrap ? element.action : "select_" + element[0].id; faux_id = wrap ? element.action : "select_" + element[0].id;
...@@ -2072,7 +2081,8 @@ ...@@ -2072,7 +2081,8 @@
"type": "input", "type": "input",
"direct": { "direct": {
"id": (wrap ? quirk_dict.reference + "_" : "") + faux_id, "id": (wrap ? quirk_dict.reference + "_" : "") + faux_id,
"name": quirk_dict.check ? faux_id : "radio_" + quirk_dict.reference, "name": quirk_dict.check ? faux_id : "radio_" +
quirk_dict.reference,
"className": element.action ? "action" : "" "className": element.action ? "action" : ""
}, },
"attributes": dict, "attributes": dict,
...@@ -2120,7 +2130,7 @@ ...@@ -2120,7 +2130,7 @@
// action menu (calling widget is cheating...) // action menu (calling widget is cheating...)
if (field.action_list) { if (field.action_list) {
group = factory.widget.controlgroup({"direction":"horizontal"}); group = factory.widget.controlgroup({"direction": "horizontal"});
for (k = 0; k < field.action_list.length; k += 1) { for (k = 0; k < field.action_list.length; k += 1) {
button = field.action_list[k]; button = field.action_list[k];
if (field.id) { if (field.id) {
...@@ -2149,8 +2159,8 @@ ...@@ -2149,8 +2159,8 @@
link = group.fragment; link = group.fragment;
// link/sorting // link/sorting
} else if (quirk_dict.link && field.href || } else if (quirk_dict.link && (field.href ||
(wrap && quirk_dict.sortable && field.sort) (wrap && quirk_dict.sortable && field.sort))
) { ) {
// header link (sorting) or href link // header link (sorting) or href link
link = factory.element({ link = factory.element({
...@@ -2343,7 +2353,7 @@ ...@@ -2343,7 +2353,7 @@
crumb = spec.children[i]; crumb = spec.children[i];
if (typeof crumb === "string") { if (typeof crumb === "string") {
pass = { pass = {
"href": base += (patch + crumb), "href": base + (patch + crumb),
"text": crumb "text": crumb
}; };
patch = "/"; patch = "/";
...@@ -2377,7 +2387,11 @@ ...@@ -2377,7 +2387,11 @@
len = arr.length; len = arr.length;
for (k = 0; k < len; k += 1) { for (k = 0; k < len; k += 1) {
block = arr[k]; block = arr[k];
content = factory.util.generateContentElement(block.type, block, config); content = factory.util.generateContentElement(
block.type,
block,
config
);
class_string += content[1]; class_string += content[1];
if (content[1] === split) { if (content[1] === split) {
...@@ -2403,7 +2417,7 @@ ...@@ -2403,7 +2417,7 @@
// TODO: class_string only works for listview, could be expanded // TODO: class_string only works for listview, could be expanded
// TODO: this is crap though.... // TODO: this is crap though....
factory.util.generateContentElement = function (type, spec, config) { factory.util.generateContentElement = function (type, spec, config) {
var id, is_type, is_main, no_icon, input_dict, container, is_text; var id, is_type, is_main, no_icon, input_dict, container;
switch (type) { switch (type) {
...@@ -2467,15 +2481,16 @@ ...@@ -2467,15 +2481,16 @@
"href": spec.href || "#", "href": spec.href || "#",
"className": "ui-btn " + " ui-btn-" + "className": "ui-btn " + " ui-btn-" +
(config.split_theme || config.theme || "inherit") + (config.split_theme || config.theme || "inherit") +
(no_icon ? " " : (is_main ? " ui-btn-icon-right ": (no_icon ? " " : (is_main ? " ui-btn-icon-right " :
" ui-btn-icon-" + (spec.iconpos || "notext")) + " ui-btn-icon-" + (spec.iconpos || "notext")) +
" ui-icon-" + (config.icon || spec.icon || "carat-r")) " ui-icon-" + (config.icon || spec.icon || "carat-r"))
}, },
"attributes": { "attributes": {
"title": spec.title || "", "title": spec.title || "",
"data-i18n": "[title]" + (spec.title_i18n || "") + ";" + (spec.text_i18n || "") "data-i18n": "[title]" + (spec.title_i18n || "") + ";" +
(spec.text_i18n || "")
}, },
"logic":{ "logic": {
"rel": spec.external ? "external" : null, "rel": spec.external ? "external" : null,
"data-ajax": spec.external ? "false" : null, "data-ajax": spec.external ? "false" : null,
"text": spec.text || null "text": spec.text || null
...@@ -2521,7 +2536,6 @@ ...@@ -2521,7 +2536,6 @@
"className": "ui-li-count ui-body-" + "className": "ui-li-count ui-body-" +
(config.count_theme || config.theme) (config.count_theme || config.theme)
}, },
"attributes": {},
"logic": {"text": spec.count} "logic": {"text": spec.count}
}), "ui-li-has-count"]; }), "ui-li-has-count"];
...@@ -2542,7 +2556,6 @@ ...@@ -2542,7 +2556,6 @@
"data-i18n": spec.text_i18n || spec.title_i18n || null "data-i18n": spec.text_i18n || spec.title_i18n || null
} }
}), ""]; }), ""];
} }
}; };
...@@ -2579,8 +2592,10 @@ ...@@ -2579,8 +2592,10 @@
container.unshift(util.mergeObject( container.unshift(util.mergeObject(
util.cloneObject(item), util.cloneObject(item),
{ {
"text": content_dict.dynamic || content_dict.message || "No items found.", "text": content_dict.dynamic || content_dict.message ||
"text_i18n": content_dict.message_i18n || "validation_dict.no_items_found", "No items found.",
"text_i18n": content_dict.message_i18n ||
"validation_dict.no_items_found",
"colspan": counter || count "colspan": counter || count
} }
)); ));
...@@ -2594,12 +2609,16 @@ ...@@ -2594,12 +2609,16 @@
"center": { "center": {
"text": [{ "text": [{
"type": "h1", "type": "h1",
"text": content_dict.dynamic || content_dict.message || "No items found.", "text": content_dict.dynamic || content_dict.message ||
"text_i18n": content_dict.message_i18n || "validation_dict.no_items_found" "No items found.",
"text_i18n": content_dict.message_i18n ||
"validation_dict.no_items_found"
}] }]
} }
}; };
default: alert("placeholder for no items missing"); break; default:
alert("placeholder for no items missing");
break;
} }
}; };
...@@ -2679,13 +2698,13 @@ ...@@ -2679,13 +2698,13 @@
"data-type": "search", "data-type": "search",
"type": "search" "type": "search"
}, },
"logic":{"clear":"true", "action":"search"} "logic": {"clear": "true", "action": "search"}
}]; }];
for (i = 0; i < spec.info_list.length; i += 1) { for (i = 0; i < spec.info_list.length; i += 1) {
element_list.push({ element_list.push({
"type": "div", "type": "div",
"direct": {"className":"info"}, "direct": {"className": "info"},
"attributes": {"data-info": spec.info_list[i]} "attributes": {"data-info": spec.info_list[i]}
}); });
} }
...@@ -2716,7 +2735,11 @@ ...@@ -2716,7 +2735,11 @@
for (n = 0; n < spec.option_list.length; n += 1) { for (n = 0; n < spec.option_list.length; n += 1) {
option = spec.option_list[n]; option = spec.option_list[n];
option_list.push({"value": option.value, "text": option.text, "text_i18n": option.text_i18n}); option_list.push({
"value": option.value,
"text": option.text,
"text_i18n": option.text_i18n
});
} }
config = { config = {
...@@ -2730,43 +2753,43 @@ ...@@ -2730,43 +2753,43 @@
"property_dict": {"direction": "horizontal"}, "property_dict": {"direction": "horizontal"},
"children": [{ "children": [{
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct": {"className": "action", "href": "#"},
"attributes":{ "attributes": {
"data-i18n": "global_dict.first", "data-i18n": "global_dict.first",
"data-action": "first", "data-action": "first",
"data-icon": "step-backward", "data-icon": "step-backward",
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"First"} "logic": {"text": "First"}
}, { }, {
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct": {"className": "action", "href": "#"},
"attributes":{ "attributes": {
"data-i18n": "global_dict.previous", "data-i18n": "global_dict.previous",
"data-action": "prev", "data-action": "prev",
"data-icon": "backward", "data-icon": "backward",
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"Previous"} "logic": {"text": "Previous"}
}, { }, {
"type":"select", "type": "select",
"direct":{"id": "select_" + util.uuid(), "className": "action"}, "direct": {"id": "select_" + util.uuid(), "className": "action"},
"attributes": { "attributes": {
"data-icon":"bars", "data-icon": "bars",
"data-action":"limit", "data-action": "limit",
"data-iconpos":"notext" "data-iconpos": "notext"
}, },
"logic": {"options":option_list} "logic": {"options": option_list}
}, { }, {
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct": {"className": "action", "href": "#"},
"attributes":{ "attributes": {
"data-i18n": "global_dict.next", "data-i18n": "global_dict.next",
"data-action": "next", "data-action": "next",
"data-icon": "forward", "data-icon": "forward",
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"Next"} "logic": {"text": "Next"}
}] }]
}] }]
}; };
...@@ -2775,14 +2798,14 @@ ...@@ -2775,14 +2798,14 @@
if (!app.storage_dict.property_dict.skip_total_records) { if (!app.storage_dict.property_dict.skip_total_records) {
config.children[0].children.push({ config.children[0].children.push({
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct": {"className": "action", "href": "#"},
"attributes":{ "attributes": {
"data-i18n": "global_dict.last", "data-i18n": "global_dict.last",
"data-action": "last", "data-action": "last",
"data-icon": "step-forward", "data-icon": "step-forward",
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"Last"} "logic": {"text": "Last"}
}); });
} }
...@@ -2798,7 +2821,7 @@ ...@@ -2798,7 +2821,7 @@
* @param {obj} object Action object (popupbeforeposition) * @param {obj} object Action object (popupbeforeposition)
*/ */
factory.util.generateDynamicContents = function (obj) { factory.util.generateDynamicContents = function (obj) {
var i, j, promises, fragment, element, reference, state, $el; var element, reference, state, $el;
element = obj.gadget; element = obj.gadget;
reference = element.getAttribute("data-reference"); reference = element.getAttribute("data-reference");
...@@ -2808,7 +2831,6 @@ ...@@ -2808,7 +2831,6 @@
if (state !== reference) { if (state !== reference) {
if (reference === null) { if (reference === null) {
app.util.error("Global Bindings: No element handler"); app.util.error("Global Bindings: No element handler");
fragment = factory.element("p", {}, {}, {"text": "No element handler"});
} else { } else {
element.setAttribute("data-state", reference); element.setAttribute("data-state", reference);
element.setAttribute("data-reference", reference); element.setAttribute("data-reference", reference);
...@@ -2816,7 +2838,6 @@ ...@@ -2816,7 +2838,6 @@
// empty gadget and reload // empty gadget and reload
// TODO: how to replace in javaScript? // TODO: how to replace in javaScript?
element.innerHTML = ""; element.innerHTML = "";
promises = [];
// fetch content // fetch content
storage.fetchConfigAttachment({ storage.fetchConfigAttachment({
...@@ -2908,230 +2929,6 @@ ...@@ -2908,230 +2929,6 @@
factory.util.setDynamicPointer(obj, "ui_panel_sales"); factory.util.setDynamicPointer(obj, "ui_panel_sales");
}, },
// =================================================
/**
* POST an object
* @method new
* @param {object} obj Action Object
**/
"new": function (obj) {
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.saved", "check");
app.navigate(obj, response);
})
.fail(function (error) {
switch (error.status) {
case 408: app.util.loader("", "status_dict.timeout", "clock-o"); break;
case 400: app.util.loader("", "validation_dict.general", "ban"); break;
default: app.util.loader("", "status_dict.error", "ban"); break;
}
});
},
/**
* PUT an object
* @method update
* @param {object} obj Action Object
**/
"update": function (obj) {
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.saved", "check");
app.navigate(obj, response);
})
.fail(function (error) {
switch (error.status) {
case 408: app.util.loader("", "status_dict.timeout", "clock-o"); break;
case 400: app.util.loader("", "validation_dict.general", "ban"); break;
default: app.util.loader("", "status_dict.error", "ban"); break;
}
});
},
/**
* update server scope - custom action, because my_ not implemented,
* same for ticket status updates
* @method update
* @param {object} obj Action Object
**/
"update_scope": function (obj) {
obj.force_data = true;
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.saved", "check");
app.navigate(obj, response);
})
.fail(function (error) {
switch (error.status) {
case 408: app.util.loader("", "status_dict.timeout", "clock-o"); break;
default: app.util.loader("", "status_dict.error", "ban"); break;
}
});
},
/**
* Install a service on a machine
* @method install
* @param {object} obj Action Object
**/
"install": function (obj) {
// HACK: no good way to refer to the calling server!
obj.state.reference =
window.decodeURIComponent(obj.state.fragment_list[1]);
storage.write(obj);
},
/**
* Revoke a SSL certificate - custom action, so extra entry
* @method revoke_ssl
* @param {object} obj Action Object
**/
"revoke_ssl": function (obj) {
app.util.loader("", "status_dict.updating");
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.ssl_revoked", "check");
})
.fail(function (error) {
app.util.loader("", "status_dict.ssl_no", "ban");
});
},
/**
* Request SSL certificate
* @method request_ssl
* @param {object} obj Action Object
**/
"request_ssl": function (obj) {
app.util.loader("", "status_dict.requesting");
storage.write(obj)
.then(function (response) {
// get certificate!
flux = flux || {};
flux._temp = util.parse(response._temp);
app.util.loader("", "status_dict.ssl_generated", "check");
app.navigate(obj, response);
})
.fail(function (error) {
app.util.loader("", "status_dict.ssl_error", "ban");
});
},
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"destroy": function (obj) {
app.util.loader("", "status_dict.destroying", "trash");
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.success", "check");
app.navigate(obj, response);
})
.fail(app.util.error);
},
/**
* Start a software instance
* @method start
* @param {object} obj Action Object
**/
"start": function (obj) {
app.util.loader("", "status_dict.starting", "signal");
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.success", "check");
})
.fail(app.util.error);
},
/**
* Stop a software instance
* @method stop_instance
* @param {object} obj Action Object
**/
"stop": function (obj) {
app.util.loader("", "status_dict.stopping", "ban");
storage.write(obj)
.then(function (response) {
app.util.loader("", "status_dict.success", "check");
})
.fail(app.util.error);
},
/**
* GET an object
* @method get
* @param {object} obj Action Object
**/
"get": function (obj) {
storage.fetch(obj);
},
/**
* Download a file (as pdf)
* @method download
* @param {object} obj Action Object
**/
"download": function (obj) {
app.util.loader("", "status_dict.downloading");
storage.fetch(obj)
.then(function (response) {
app.util.loader("", "status_dict.rendering");
window.location.href = response.data._links.slapos_jump.href;
})
.fail(app.util.error);
},
// ==============================================
// /**
// * Destroy an installation = service object
// * @method destroy
// * @param {object} obj Action Object
// **/
// "destroy": function (obj) {
// storage.remove(obj);
// },
/**
* Start a software instance
* @method start_instance
* @param {object} obj Action Object
**/
"destroy_installation": function (obj) {
var element = obj.element,
id = obj.state.fragment_list[1],
decode = /^[^\/]*%2[^\/]*$/.test(id);
app.util.loader("", "status_dict.destroying", "trash");
jIO.util.ajax({
"url": window.decodeURIComponent(element.href),
"type": element.getAttribute("data-method"),
"xhrFields": {
"withCredentials": true
}
})
.then(function (answer) {
app.util.loader("", "status_dict.success", "check");
$.mobile.changePage("#servers");
})
.fail(function(error) {
app.util.loader("", "status_dict.success", "check");
app.util.error(error);
if (util.parse(error.target).responseText === "" && id && obj.state.callback) {
$.mobile.changePage(obj.state.callback.replace("__id__", decode ? id : window.encodeURIComponent(id)));
}
});
},
// ==============================================================
/** /**
* Look up single value from dict * Look up single value from dict
* @method translateLookup * @method translateLookup
...@@ -3508,7 +3305,7 @@ ...@@ -3508,7 +3305,7 @@
quirk_dict = wrapper.property_dict; quirk_dict = wrapper.property_dict;
record = item.doc; record = item.doc;
id = record[quirk_dict.link_identifier] || record["_id"] || item["_id"]; id = record[quirk_dict.link_identifier] || record._id || item._id;
new_item = {}; new_item = {};
// id // id
...@@ -3527,11 +3324,18 @@ ...@@ -3527,11 +3324,18 @@
// loop field_list = cells // loop field_list = cells
for (k = 0; k < segment.field_list.length; k += 1) { for (k = 0; k < segment.field_list.length; k += 1) {
cell = util.mergeObject(new_item, util.cloneObject(segment.field_list[k])); cell = util.mergeObject(
new_item,
util.cloneObject(segment.field_list[k])
);
// custom header (!) cells have text/i18n defined // custom header (!) cells have text/i18n defined
if (!cell.custom) { if (!cell.custom) {
cell.text = util.generateText(record[field.value || field.field], cell, record); cell.text = util.generateText(
record[cell.value || cell.field],
cell,
record
);
cell.text_i18n = record.text_i18n || null; cell.text_i18n = record.text_i18n || null;
} }
row.push(cell); row.push(cell);
...@@ -3556,19 +3360,19 @@ ...@@ -3556,19 +3360,19 @@
// TODO: not nice & find better handling for text elements and i18n tags // TODO: not nice & find better handling for text elements and i18n tags
// NOTE: make sure there is no "id" flying through here!!! only _id // NOTE: make sure there is no "id" flying through here!!! only _id
map.listItem = function (item, wrapper, i) { map.listItem = function (item, wrapper, i) {
var quirk_dict, core, section, pos, label, j, k, field, setter, var quirk_dict, section, pos, label, j, k, field, setter, record, new_item,
record, property, source, new_item, id, key, obj, translation_fields; id, key, obj, translation_fields;
translation_fields = "titletextlabel"; translation_fields = "titletextlabel";
quirk_dict = wrapper.property_dict; quirk_dict = wrapper.property_dict;
record = item.doc; record = item.doc;
id = record[quirk_dict.link_identifier] || record["_id"] || item["_id"]; id = record[quirk_dict.link_identifier] || record._id || item._id;
new_item = {}; new_item = {};
// radio // radio
if (quirk_dict.radio) { if (quirk_dict.radio) {
label = true; label = true;
new_item.right = [{"type":"radio", "action": "check"}]; new_item.right = [{"type": "radio", "action": "check"}];
} }
// checkbox // checkbox
...@@ -3630,8 +3434,8 @@ ...@@ -3630,8 +3434,8 @@
// TODO: should we wrap in span_12 here. why do we wrap at all, do with CSS // TODO: should we wrap in span_12 here. why do we wrap at all, do with CSS
map.formItem = function (item, wrapper, i) { map.formItem = function (item, wrapper, i) {
var helper, getHelp, j, k, segment, section, field, setValue, root, veto, var helper, getHelp, j, k, segment, section, field, setValue, root, veto,
textarea_value, override_value, value,field_value, validation_list, textarea_value, override_value, value, field_value, validation_list,
class_list, el, type, clear, alt_name, fetch_items, option_list, pass, class_list, el, type, clear, alt_name, fetch_items, pass,
field_list, l, m, section_list, container, disabled, readonly; field_list, l, m, section_list, container, disabled, readonly;
getHelp = function (prop) { getHelp = function (prop) {
...@@ -3644,24 +3448,25 @@ ...@@ -3644,24 +3448,25 @@
}; };
// TODO: remove this crap or make it generic... // TODO: remove this crap or make it generic...
// set = setter_list ... JSLINT
setValue = function (setter) { setValue = function (setter) {
var i, len, set_value, set_flux, setter_list, lookup_value, set_reference; var n, len, set_value, set_flux, set, val, set_reference;
if (setter.logic) { if (setter.logic) {
set_reference = setter.logic.setReference; set_reference = setter.logic.setReference;
set_value = setter.logic.setValue; set_value = setter.logic.setValue;
lookup_value = setter.logic.lookupValue; val = setter.logic.lookupValue;
setter_list = setter.logic.setters; set = setter.logic.setters;
set_flux = setter.logic.setFlux; set_flux = setter.logic.setFlux;
if (setter_list) { if (set) {
len = setter_list.length; len = set.length;
for (i = 0; i < len; i += 1) { for (n = 0; n < len; n += 1) {
if (lookup_value) { if (val) {
// FU§$%&/NG HAL // FU§$%&/NG HAL
setter.logic[setter_list[i]] = item.doc[lookup_value[i][0]][lookup_value[i][1]][lookup_value[i][2]]; setter.logic[set[n]] = item.doc[val[n][0]][val[n][1]][val[n][2]];
} else { } else {
setter.logic[setter_list[i]] = item.doc[set_value]; setter.logic[set[n]] = item.doc[set_value];
} }
} }
} else if (set_value) { } else if (set_value) {
...@@ -3688,11 +3493,9 @@ ...@@ -3688,11 +3493,9 @@
// NOTE: all children of a form will be passed through here, these can // NOTE: all children of a form will be passed through here, these can
// be ready HTML constructor objects, widgets or form elements // be ready HTML constructor objects, widgets or form elements
// requiring mapping (custom or based on element.field_dict) // requiring mapping (custom or based on element.field_dict)
switch (true) { if (!!item.direct) {
case !!item.direct:
setValue(item); setValue(item);
break; } else if (!!item.generate) {
case !!item.generate:
// we must declare wrap for non-form elements here, because they // we must declare wrap for non-form elements here, because they
// don't belong into any widget // don't belong into any widget
container = getHelp({ container = getHelp({
...@@ -3700,10 +3503,8 @@ ...@@ -3700,10 +3503,8 @@
"class_list": "span_" + (item.property_dict.wrap || 1) "class_list": "span_" + (item.property_dict.wrap || 1)
}); });
container.children.push(item); container.children.push(item);
break; } else {
default:
helper = getHelp({"wrap": "fragment"}); helper = getHelp({"wrap": "fragment"});
break;
} }
// nothing to do, pass back directly // nothing to do, pass back directly
...@@ -3739,8 +3540,8 @@ ...@@ -3739,8 +3540,8 @@
root = item.field_dict[field.field]; root = item.field_dict[field.field];
veto = util.mergeObject( veto = util.mergeObject(
field.overrides || {}, field.overrides || {},
{"properties": {}, "widget": {} {"properties": {}, "widget": {}}
}); );
value = item.doc[field.setValue || field.field]; value = item.doc[field.setValue || field.field];
// flag false/missing field_dict // flag false/missing field_dict
...@@ -3759,9 +3560,8 @@ ...@@ -3759,9 +3560,8 @@
// easy way out if not enabled // easy way out if not enabled
// TODO: should be full field setup with label... and span // TODO: should be full field setup with label... and span
switch (true) { if (veto.properties.enabled === false ||
case (veto.properties.enabled === false || root.properties.enabled === false) {
root.properties.enabled === false):
pass = { pass = {
"push": { "push": {
"type": "span", "type": "span",
...@@ -3770,8 +3570,7 @@ ...@@ -3770,8 +3570,7 @@
"logic": {"text": field_value} "logic": {"text": field_value}
} }
}; };
break; } else if (veto.type === "ImageField" || root.type === "ImageField") {
case (veto.type === "ImageField" || root.type === "ImageField"):
pass = { pass = {
"push": { "push": {
"type": "img", "type": "img",
...@@ -3779,7 +3578,6 @@ ...@@ -3779,7 +3578,6 @@
"attributes": {"skip": true} "attributes": {"skip": true}
} }
}; };
break;
} }
// check for options (select elements), which need to be fetched // check for options (select elements), which need to be fetched
...@@ -3802,7 +3600,9 @@ ...@@ -3802,7 +3600,9 @@
// required fields // required fields
if (root.properties.required === true) { if (root.properties.required === true) {
if (veto.properties.required === undefined || veto.properties.required === true) { if (veto.properties.required === undefined ||
veto.properties.required === true
) {
class_list += "required "; class_list += "required ";
} }
} }
...@@ -3946,8 +3746,8 @@ ...@@ -3946,8 +3746,8 @@
"attachment": fetch_items, "attachment": fetch_items,
"pass": pass "pass": pass
}).then(function (answer) { }).then(function (answer) {
var i, j, value, option, len, loaded_options, el_type, radio_check, var o, p, new_value, option, len, loaded_options, el_type,
clone, clone_opt, group, push, group_id; radio_check, clone, clone_opt, group, push, group_id;
loaded_options = answer.response; loaded_options = answer.response;
...@@ -3956,16 +3756,16 @@ ...@@ -3956,16 +3756,16 @@
push = answer.pass.push; push = answer.pass.push;
push.logic.options = util.parse(loaded_options); push.logic.options = util.parse(loaded_options);
value = push.logic.value; new_value = push.logic.value;
len = loaded_options.length; len = loaded_options.length;
el_type = push.attributes.type; el_type = push.attributes.type;
radio_check = (el_type === "radio" || el_type === "checkbox"); radio_check = (el_type === "radio" || el_type === "checkbox");
// TODO: set value here? this is a mapper??! // TODO: set value here? this is a mapper??!
if (value) { if (new_value) {
for (i = 0; i < len; i += 1) { for (o = 0; o < len; o += 1) {
option = loaded_options[i]; option = loaded_options[o];
if (option.value === value) { if (option.value === new_value) {
option.checked = true; option.checked = true;
option.selected = "selected"; option.selected = "selected";
} }
...@@ -3989,15 +3789,15 @@ ...@@ -3989,15 +3789,15 @@
"children": [] "children": []
}; };
for (j = 0; j < len; j += 1) { for (p = 0; p < len; p += 1) {
clone_opt = loaded_options[j]; clone_opt = loaded_options[p];
clone = { clone = {
"type": "input", "type": "input",
"logic": util.cloneObject(push.logic), "logic": util.cloneObject(push.logic),
"attributes": util.cloneObject(push.attributes), "attributes": util.cloneObject(push.attributes),
"direct": util.cloneObject(push.direct) "direct": util.cloneObject(push.direct)
}; };
clone.direct.id += "_" + j; clone.direct.id += "_" + p;
if (clone_opt.checked) { if (clone_opt.checked) {
clone.direct.checked = true; clone.direct.checked = true;
} }
...@@ -4038,7 +3838,7 @@ ...@@ -4038,7 +3838,7 @@
for (m = 0; m < section_response_list.length; m += 1) { for (m = 0; m < section_response_list.length; m += 1) {
helper.children.push(section_response_list[m]); helper.children.push(section_response_list[m]);
} }
return RSVP.resolve(helper) return RSVP.resolve(helper);
}) })
.fail(app.util.error); .fail(app.util.error);
}; };
...@@ -4066,40 +3866,39 @@ ...@@ -4066,40 +3866,39 @@
// there is no need to look it up in pass.config.property_dict... // there is no need to look it up in pass.config.property_dict...
// TODO: jump is bad, it is the lookup for the data to display. rename! // TODO: jump is bad, it is the lookup for the data to display. rename!
storage.fetch = function (obj) { storage.fetch = function (obj) {
var pass, query, method, map, config, answer, lookup, pointer, action_id, var pass, query, method, mapper, config, answer, lookup, pointer, action_id,
quirk; quirk;
pass = obj.pass; pass = obj.pass;
quirk = obj.state || pass.config_dict; quirk = obj.state || pass.config_dict;
lookup = obj.state || quirk.property_dict || storage.obj; lookup = obj.state || quirk.property_dict || storage.obj;
query = obj.query || lookup.query || storage.obj; query = obj.query || lookup.query || storage.obj;
pointer = (lookup["url_pointer"] || storage.obj).jump; pointer = (lookup.url_pointer || storage.obj).jump;
// TODO: action > id, this should be triggered via form submit not link! // TODO: action > id, this should be triggered via form submit not link!
action_id = ((obj.element || storage.obj).href || "").split("/").pop(); action_id = ((obj.element || storage.obj).href || "").split("/").pop();
if (action_id) { if (action_id) {
pointer = undefined; pointer = undefined;
query = {"_id": window.decodeURIComponent(action_id)} query = {"_id": window.decodeURIComponent(action_id)};
} }
switch (true) { // F%&/() JSLINT...
if (!!pointer) {
// TODO: "hack" for forcing get into allDocs, don't overwrite criteria! // TODO: "hack" for forcing get into allDocs, don't overwrite criteria!
case !!pointer: mapper = "values";
map = "values";
query.select_list = query.select_list || pass.data_dict.field_list; query.select_list = query.select_list || pass.data_dict.field_list;
query.limit = query.limit || pass.config_dict.initial_query.limit; query.limit = query.limit || pass.config_dict.initial_query.limit;
break; } else if ((query.select_list || storage.arr).length > 0 &&
case ((query.select_list || storage.arr).length > 0 && !query.include_docs): !query.include_docs
map = "values"; ) {
break; mapper = "values";
case (!!query._id): } else if (!!query._id) {
map = "single_item"; mapper = "single_item";
method = "get"; method = "get";
config = { config = {
"_view": quirk.view "_view": quirk.view
}; };
break;
} }
// TODO: remove - pass custom query to storage // TODO: remove - pass custom query to storage
...@@ -4116,21 +3915,27 @@ ...@@ -4116,21 +3915,27 @@
if (action_id) { if (action_id) {
return response; return response;
} }
answer = storage.mapResponse(response, map); answer = storage.mapResponse(response, mapper);
} }
return { return {
"response": answer || response, "response": answer || response,
"pass": pass "pass": pass
}; };
}).fail(function(error) { }).fail(function (error) {
switch (error.status) { switch (error.status) {
case 408: app.util.loader("", "status_dict.timeout", "clock-o"); break; case 408:
case 400: app.util.loader("", "validation_dict.general", "ban"); break; app.util.loader("", "status_dict.timeout", "clock-o");
default: app.util.loader("", "status_dict.error", "ban"); break; break;
case 400:
app.util.loader("", "validation_dict.general", "ban");
break;
default:
app.util.loader("", "status_dict.error", "ban");
break;
} }
app.util.error(error) app.util.error(error);
}); });
}, };
/** /**
* Write to storage = POST or PUT * Write to storage = POST or PUT
...@@ -4140,10 +3945,10 @@ ...@@ -4140,10 +3945,10 @@
// TODO: storage.add included prefetch of field_items and validation // TODO: storage.add included prefetch of field_items and validation
// TODO: storage.add deleted identifier if create_new was set // TODO: storage.add deleted identifier if create_new was set
storage.write = function (obj) { storage.write = function (obj) {
var form, data, valid, prefix, config, method, action, pointer, id; var form, data, valid, prefix, config, method, action, pointer;
form = obj.form; form = obj.form;
pointer = (obj.element || storage.span).getAttribute("data-action"), pointer = (obj.element || storage.span).getAttribute("data-action");
action = (obj.state.url_pointer || storage.obj)[pointer]; action = (obj.state.url_pointer || storage.obj)[pointer];
config = {}; config = {};
prefix = obj.id + "_"; prefix = obj.id + "_";
...@@ -4151,7 +3956,7 @@ ...@@ -4151,7 +3956,7 @@
if (valid) { if (valid) {
data = obj.sample_data || storage.parseForm(valid, prefix, true); data = obj.sample_data || storage.parseForm(valid, prefix, true);
// TODO: remove, used for update scope, which does not honor form definition // TODO: remove, used for update scope, doesn't honor form definition
if (obj.force_data) { if (obj.force_data) {
config._force_data = true; config._force_data = true;
} }
...@@ -4180,10 +3985,9 @@ ...@@ -4180,10 +3985,9 @@
return RSVP.resolve( return RSVP.resolve(
app.storage_dict.items[method || "post"](data, config) app.storage_dict.items[method || "post"](data, config)
); );
} else { }
app.util.loader("", "validation_dict.general", "ban"); app.util.loader("", "validation_dict.general", "ban");
return RSVP.reject({"status": 400}); return RSVP.reject({"status": 400});
}
}; };
/** /**
...@@ -4232,54 +4036,7 @@ ...@@ -4232,54 +4036,7 @@
} }
// NOTE: throw to get back in success chain!!! // NOTE: throw to get back in success chain!!!
throw error; throw error;
}
);
};
/**
* Load files from disk (fallback, not using storage)
* @method loadFromDiskAndSave
* @param {object} obj Configuration object (may include pass)
* @return {object} object
*/
// TODO: put/putAttachment should be set somewhere more general!
// TODO: merge with fetch/write - requires attachment and storage handling
storage.oldload = function (obj) {
var url, destination;
// fetch and store if set
return util.ajax({"url": url})
.then(function (event) {
destination = obj.store || app.storage_dict.settings;
if (!destination) {
app.util.error("load: storage not defined");
return RSVP.all([]);
}
return destination.put({"_id": (obj.file || "settings")})
.then(function () {
return destination.putAttachment({
"_id": (obj.file || "settings"),
"_attachment": (obj.attachment ||
app.storage_dict.property_dict.name_dict.configuration),
"_data": JSON.stringify(util.parse(event.target.responseText)),
"_mimetype": "application/json"
}); });
})
.fail(app.util.error);
})
.then(function (response) {
if (obj.pass) {
return {
"response": response,
"pass": obj.pass
};
}
return response;
})
.fail(app.util.error);
}; };
/** /**
...@@ -4355,14 +4112,13 @@ ...@@ -4355,14 +4112,13 @@
*/ */
// WARNING: jIO dependency! // WARNING: jIO dependency!
storage.parseQuery = function (query, type, key, value, field_list, restore) { storage.parseQuery = function (query, type, key, value, field_list, restore) {
var property, wrap, query_object, query_clean, default_query, obj, var wrap, query_object, query_clean, default_query, obj, is_value, i, is_id;
is_value, i, is_id, decode;
is_value = value && value !== ""; is_value = value && value !== "";
is_id = query && query.query && query.query._id; is_id = query && query.query && query.query._id;
// "id" = "bar" => THIS SHOULD BE GET! // "id" = "bar" => THIS SHOULD BE GET!
if (is_value && key && key === "_id" || is_id) { if ((is_value && key && key === "_id") || is_id) {
obj = {"_id": window.decodeURIComponent(is_id ? query.query._id : value)}; obj = {"_id": window.decodeURIComponent(is_id ? query.query._id : value)};
// ALLDOCS // ALLDOCS
...@@ -4418,8 +4174,11 @@ ...@@ -4418,8 +4174,11 @@
wrap = ""; wrap = "";
for (i = 0; i < field_list.length; i += 1) { for (i = 0; i < field_list.length; i += 1) {
if (!util.findKey( if (!util.findKey(
(query_object || {}), "query_list", "key", field_list[i]) query_object || {},
) { "query_list",
"key",
field_list[i]
)) {
wrap += field_list[i] + ': "' + wrap += field_list[i] + ': "' +
obj.wildcard_character + obj.wildcard_character +
value + value +
...@@ -4575,7 +4334,7 @@ ...@@ -4575,7 +4334,7 @@
} }
} }
// TODO: verfiy this is valid! // TODO: verfiy this is valid!
data["_id"] = record.id; data._id = record.id;
answer.data.rows.push(pushit(data, record)); answer.data.rows.push(pushit(data, record));
} }
} }
...@@ -4589,7 +4348,7 @@ ...@@ -4589,7 +4348,7 @@
* @return {object} form fields/errors * @return {object} form fields/errors
**/ **/
storage.validate = function (form_to_test) { storage.validate = function (form_to_test) {
var i, pass, form_to_submit, anti_spam, valid, test_time, test_empty, var i, pass, anti_spam, valid, test_time, test_empty,
test_full, form_element, form_elements; test_full, form_element, form_elements;
pass = false; pass = false;
...@@ -4665,8 +4424,8 @@ ...@@ -4665,8 +4424,8 @@
if (store && items.length > 0) { if (store && items.length > 0) {
for (i = 0; i < items.length; i += 1) { for (i = 0; i < items.length; i += 1) {
store.remove({"_id":items[i]}) store.remove({"_id": items[i]})
.then(function() { .then(function () {
if (config.state.callback) { if (config.state.callback) {
$.mobile.changePage(config.state.callback); $.mobile.changePage(config.state.callback);
} }
...@@ -4718,16 +4477,16 @@ ...@@ -4718,16 +4477,16 @@
* @param {Object} response The action response * @param {Object} response The action response
*/ */
app.navigate = function (obj, response) { app.navigate = function (obj, response) {
var answer, id, goto, decode; var answer, id, goto_page, decode;
if (obj.state.callback) { if (obj.state.callback) {
app.util.loader("", "status_dict.forwarding"); app.util.loader("", "status_dict.forwarding");
answer = util.parse(response); answer = util.parse(response);
id = answer.id; id = answer.id;
decode = /^[^\/]*%2[^\/]*$/.test(id); decode = /^[^\/]*%2[^\/]*$/.test(id);
goto = decode ? id : window.encodeURIComponent(id); goto_page = decode ? id : window.encodeURIComponent(id);
$.mobile.changePage(obj.state.callback.replace("__id__", goto)); $.mobile.changePage(obj.state.callback.replace("__id__", goto_page));
} }
}; };
...@@ -5033,7 +4792,8 @@ ...@@ -5033,7 +4792,8 @@
info_field_list = element.querySelectorAll(".info"); info_field_list = element.querySelectorAll(".info");
info = ""; info = "";
no_total = total === undefined && app.storage_dict.property_dict.skip_total_records; no_total = total === undefined &&
app.storage_dict.property_dict.skip_total_records;
generateInfo = function (text, text_i18n) { generateInfo = function (text, text_i18n) {
return factory.element( return factory.element(
"span", "span",
...@@ -5075,7 +4835,8 @@ ...@@ -5075,7 +4835,8 @@
no_items = options.limit[1] || 0; no_items = options.limit[1] || 0;
zero_no_show = (no_limit === 0 && use_total !== 0) ? 1 : no_limit; zero_no_show = (no_limit === 0 && use_total !== 0) ? 1 : no_limit;
if (no_total) { if (no_total) {
min = ((no_limit + no_items === 0) ? use_total : no_limit + no_items); min = ((no_limit + no_items === 0) ? use_total :
no_limit + no_items);
total_records = ""; total_records = "";
} else { } else {
min = Math.min( min = Math.min(
......
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