Commit 4b237cf9 authored by Sven Franck's avatar Sven Franck

shortened error message, fixed GET response parsing

parent 7b182aa4
......@@ -33,7 +33,7 @@
if (i18n) {
return i18n.t(path);
}
util.error({"error": "Translate NodeList - i18n not defined"});
util.error("Translate NodeList - i18n not defined");
return "";
},
......@@ -47,15 +47,9 @@
**/
// TODO: no solution yet for selectMenu-refesh and input (submit/reset/btn)
"translateNodeList": function (nodeList, single) {
var i,
l,
element,
lookup,
targets,
target,
route_text,
elements = single ? [nodeList] :
nodeList.querySelectorAll(".translate");
var i, l, element, lookup, targets, target, route_text, elements;
elements = single ? [nodeList] : nodeList.querySelectorAll(".translate");
if (i18n) {
for (i = 0; i < elements.length; i += 1) {
......@@ -111,7 +105,7 @@
}
}
} else {
util.error({"error": "Translate NodeList - i18n not defined"});
util.error("Translate NodeList - i18n not defined");
}
},
......@@ -189,8 +183,7 @@
}
// TODO: Try to log out correctly
// http://bit.ly/1aih0UU
// http://bit.ly/1kUUuJz
// http://bit.ly/1aih0UU or http://bit.ly/1kUUuJz
// update login button, so it's back to login
obj.element.parentNode.replaceChild(
......@@ -220,7 +213,7 @@
window.parent.close();
})
.then(function (response) {
//reply = util.parseIfNeeded(response);
//reply = util.parse(response);
if (response.authResponse !== undefined) {
match_string = response.authResponse.state;
......@@ -366,7 +359,7 @@
* @param {string} identifier
**/
"download": function () {
util.error({"error": "Download: Not implemented."});
util.error("Download: Not implemented.");
},
/**
......@@ -561,9 +554,7 @@
// custom cells have text/i18n defined
if (cell.custom === undefined) {
if (field_dict[cell.column] === undefined) {
util.error({
"error": "mapRows: Missing definition for " + cell.column
});
util.error("mapRows: Missing definition for " + cell.column);
}
cell.text = field_dict[cell.column].widget.title;
cell.text_i18n = field_dict[cell.column].widget.title_i18n;
......@@ -594,7 +585,7 @@
}
if (item === undefined) {
util.error({"error": "mapTableRows: include_docs not set"});
util.error("mapTableRows: include_docs not set");
} else {
row = [];
for (m = 0; m < config.length; m += 1) {
......@@ -638,9 +629,7 @@
if (layout.footer && layout.footer.length > 0) {
util.error(
{"error": "mapTableRows: Missing handler for table footer"}
);
util.error("mapTableRows: Missing handler for table footer");
}
return arr;
},
......@@ -679,7 +668,7 @@
// if include_docs is not set, item will be undefined!
if (item === undefined) {
util.error({"error": "mapListItems: missing include_docs"});
util.error("mapListItems: missing include_docs");
}
// radio
......@@ -988,7 +977,7 @@
"clear": clear || undefined
};
} else {
util.error({"error": "mapFormField: Missing field definition"});
util.error("mapFormField: Missing field definition");
}
return config;
......@@ -1043,7 +1032,7 @@
set_login = true;
} else {
util.error({"error": "globalConfig: Missing hellojs"});
util.error("globalConfig: Missing hellojs");
}
}
break;
......@@ -1069,7 +1058,7 @@
}
}
} else {
util.error({"error": "globalConfig: Missing path dict"});
util.error("globalConfig: Missing path dict");
}
// i18n
......@@ -1092,9 +1081,7 @@
return;
});
} else {
util.error(
{"error": "globalConfig: Missing i18n configuration"}
);
util.error("globalConfig: Missing i18n configuration");
}
break;
}
......@@ -1203,7 +1190,7 @@
}
return RSVP.all(promises);
default:
util.error({"error": "setStorage: Missing storage type"});
util.error("setStorage: Missing storage type");
return RSVP.all(promises);
}
},
......@@ -1218,9 +1205,7 @@
storage[content_dict.property_dict.definition.application_name] =
jIO.createJIO(content_dict.property_dict.definition);
} else {
util.error(
{"error": "makeStorage: Missing storage definition"}
);
util.error("makeStorage: Missing storage definition");
}
return RSVP.all([]);
},
......@@ -1237,7 +1222,7 @@
.children[url_dict ? (url_dict.layout_level || 0) : 0];
if (page_dict === undefined) {
util.error({"error": "Pageindex: Missing page definition"});
util.error("Pageindex: Missing page definition");
} else {
// NOTE: 3rd parameter "create" needs to be set to undefined,
......@@ -1496,11 +1481,11 @@
data._id = util.generateUuid();
}
} else if (answer.data.total_rows > 1) {
util.error({"error": "Fieldlist: More than 1 record"});
util.error("Fieldlist: More than 1 record");
} else {
data = answer.data.rows[0].doc;
if (data === undefined) {
util.error({"error": "fieldlist: include_docs missing"});
util.error("fieldlist: include_docs missing");
}
}
}
......@@ -1665,7 +1650,7 @@
// no more way
if (target.length === 0) {
util.error({"error": "updatePageSection: No target found"});
util.error("updatePageSection: No target found");
} else {
for (i = 0; i < target.length; i += 1) {
target[i].setAttribute("data-bound", true);
......@@ -1691,7 +1676,7 @@
// don't reload if same popup is opened
if (state !== reference) {
if (reference === null) {
util.error({"error": "Global Bindings: No popup handler"});
util.error("Global Bindings: No popup handler");
fragment = factory.element("p", {}, {}, {"text": "No popup handler"});
} else {
popup.setAttribute("data-state", reference);
......@@ -1763,7 +1748,7 @@
factory.util.wrapInForm = function (spec) {
if (spec.form) {
if (spec.reference === undefined && spec.id === undefined) {
util.error({"error": "wrapInForm: Missing form id."});
util.error("wrapInForm: Missing form id.");
}
return factory.element(
"form",
......@@ -1816,9 +1801,7 @@
var i, popup, wrap, id, config, container, placeholder;
if (config_dict === undefined) {
util.error({
"error": "GeneratePopup: Missing configuration"
});
util.error("GeneratePopup: Missing configuration");
} else {
container = document.createDocumentFragment();
config = config_dict.property_dict || {};
......@@ -1929,9 +1912,7 @@
target, state;
if (config_dict === undefined) {
util.error({
"error": "Generate Header: Missing configuration"
});
util.error("Generate Header: Missing configuration");
} else {
config = config_dict.property_dict || {};
id = config_dict.id || ((url_dict.id || "global") + "-header");
......@@ -2050,9 +2031,7 @@
var i, element, config, id, panel, closer, target;
if (config_dict === undefined) {
util.error({
"error": "Generate Panel: Missing configuration"
});
util.error("Generate Panel: Missing configuration");
} else {
config = config_dict.property_dict || {};
id = config_dict.id || ((url_dict.id || "global") + "-panel");
......@@ -2150,9 +2129,7 @@
var config, id, footer, i, element, order;
if (config_dict === undefined) {
util.error({
"error": "Generate Footer: Missing config"
});
util.error("Generate Footer: Missing config");
} else {
config = config_dict.property_dict || {};
id = config_dict.id || ((url_dict.id || "global") + "-footer");
......@@ -2397,7 +2374,7 @@
safety_box = wrap(1, true);
fragment.appendChild(safety_box);
} else {
util.error({"error": "Captcha - No public key supplied"});
util.error("Captcha - No public key supplied");
}
}
......@@ -2444,9 +2421,7 @@
var config, group, direction, controls, i, element, order, state;
if (spec === undefined) {
util.error({
"error": "Generate Controlgroup: Missing config"
});
util.error("Generate Controlgroup: Missing config");
} else {
config = spec.property_dict || {};
direction = config.direction || "vertical";
......@@ -2547,9 +2522,7 @@
var navbar, controls, i, element, target, order;
if (spec === undefined) {
util.error({
"error": "Generate Navbar: Missing Configuration"
});
util.error("Generate Navbar: Missing Configuration");
} else {
//config = spec.property_dict || {};
......@@ -2678,9 +2651,7 @@
ribbon_wrap, theme;
if (spec === undefined) {
util.errorHanlder({
"error": "Generate listview: Missing configuration"
});
util.error("Generate listview: Missing configuration");
} else {
fragment = document.createDocumentFragment();
config = spec.property_dict || {};
......@@ -2804,7 +2775,7 @@
// jslint...
// TODO: remove!
if (props.href === undefined) {
util.errorHandler({"error": "JSLINT error, ignore"});
util.error("JSLINT error, ignore");
props.href = url_dict.href;
}
// link
......@@ -2972,9 +2943,7 @@
var fragment, i, element, slot;
if (spec === undefined) {
util.errorHanlder({
"error": "Generate controlbar: Missing configuration"
});
util.error("Generate controlbar: Missing configuration");
} else {
slot = spec.property_dict ? spec.property_dict.slot : undefined;
fragment = factory.element(
......@@ -3034,7 +3003,7 @@
promises[i] = app.setContent(render[i], url_dict, create);
}
} else {
util.error({"error": "factory.page: Missing view"});
util.error("factory.page: Missing view");
}
return RSVP.all(promises)
......@@ -3183,9 +3152,7 @@
var i, container, config, section, method;
if (spec === undefined) {
util.errorHanlder({
"error": "Generate table: Missing configuration"
});
util.error("Generate table: Missing configuration");
} else {
config = spec.property_dict || {};
......@@ -4045,20 +4012,22 @@
* @param {object} config Action Object
**/
storage.remove = function (config) {
var store, items, i;
var store, items, i, kill;
util.loader("", "global_dict.status_dict.removing");
store = storage.items;
kill = config.state.query.last || config.state.query._id;
// TODO: find a generic way to determine the id of the element to
// be removed, in a single item gadget it should be the underlying id,
// in a multi item gadget, we need to select
// last will be id of element displayed
if (config.state.query.last) {
items = [config.state.query.last];
if (kill) {
items = [kill];
} else {
util.error({"error": "No items for deletion defined"});
util.error("No items for deletion defined");
}
if (store && items.length > 0) {
......@@ -4318,7 +4287,7 @@
"pass": {"type": "Person"}
});
}
util.error({"error": "regiser user: need account sync!"});
util.error("Register: need account sync!");
}
})
.fail(util.error);
......@@ -4565,12 +4534,10 @@
.fail(util.error);
} else {
util.error({"Error": "No state information stored for gadget"});
util.error("No state information stored for gadget");
}
} else {
util.error({
"Error": "Action is missing reference gadget"
});
util.error("Action is missing reference gadget");
}
};
......@@ -4740,7 +4707,7 @@
if (url) {
return util.ajax({"url": url})
.then(function (answer) {
auth_response = util.parseIfNeeded(answer.target.response);
auth_response = util.parse(answer.target.response);
if (pass) {
pass.active_login = true;
pass.verified_by = signee;
......@@ -4753,13 +4720,13 @@
.fail(function (event) {
// invalid session > return 400, so we are back on the then-column
if (event.target.status === 400) {
auth_response = util.parseIfNeeded(event.target.response);
auth_response = util.parse(event.target.response);
if (pass) {
return RSVP.resolve(pass);
}
return RSVP.resolve(pass);
}
throw util.parseIfNeeded(event.target);
throw util.parse(event.target);
});
}
// TODO: this should ask to login again!
......@@ -4767,9 +4734,9 @@
pass.active_login = false;
return RSVP.resolve(pass);
}
return RSVP.resolve({"error": "no state found/not logged in"});
return RSVP.resolve("no state found/not logged in");
}
util.error({"error": "loginStatus: Missing login handler."});
util.error("loginStatus: Missing login handler.");
};
/**
......@@ -4923,14 +4890,10 @@
if (handler) {
handler(app.generateActionObject(e), val);
} else {
util.error({
"Error": "Action: No method defined"
});
util.error("Action: No method defined");
}
} else {
util.error({
"Error": "Action: No action defined for element"
});
util.error("Action: No action defined for element");
}
};
......@@ -4946,14 +4909,20 @@
* @return {object} query object
*/
// WARNING: complex_queries dependency!
// TODO: make "foo" = "bar" handle more complexity passed via ... url
app.generateQueryObject = function (query, type, key, value, field_list) {
var property, wrap, query_object, query_clean, default_query, obj,
is_value;
is_value = value && value !== "";
// "id" = "bar" => THIS SHOULD BE A GET!
if (is_value && key && key === "_id") {
obj = {"_id": value};
// allDocs
} else {
default_query = query || {};
obj = {"query": ''};
is_value = value && value !== "";
// query string passed? parse it
if (default_query.query) {
......@@ -4977,7 +4946,7 @@
obj.last = value;
}
// search "foo" = "bar"
// "foo" = "bar"
if (is_value && key) {
obj.query += ' AND (' + key + ':"' + value + '")';
obj.start = 0;
......@@ -5034,6 +5003,8 @@
} else {
obj.wildcard_character = "%";
}
}
return obj;
};
......@@ -5278,14 +5249,12 @@
constructor = map.gadgets[pass.constructor];
if (constructor === undefined) {
return util.error(
{"error": "generateGadgetContent: Missing constructor"}
);
return util.error("generateGadgetContent: Missing constructor");
}
// set data depending on auth
if (pass.no_auth || (pass.auth && pass.active_login)) {
data = reply.response ? util.parseIfNeeded(reply.response) : null;
data = reply.response ? util.parse(reply.response) : null;
data_set = true;
} else {
data = null;
......@@ -5370,7 +5339,7 @@
// single item query
if (reply.response) {
parsed = util.parseIfNeeded(reply.response);
parsed = util.parse(reply.response);
pass.state.total = parsed.data.total_rows;
}
......@@ -5411,8 +5380,10 @@
var pass = reply.pass, reference, last;
if (pass.skip === undefined) {
// create or update state object
if (pass.create === false) {
// TODO: horrible, define a pass API!!!!
reference = document.getElementById(pass.id);
if (reference === null) {
......@@ -5500,11 +5471,11 @@
// TODO: remove once no need for sample data
if (pass.needs_fields) {
delete pass.needs_fields;
pass.fields = util.parseIfNeeded(reply.response);
pass.fields = util.parse(reply.response);
}
store = storage.items;
items = util.parseIfNeeded(reply.response);
items = util.parse(reply.response);
if (store && items.length > 0) {
......@@ -5544,7 +5515,7 @@
if (answer.response) {
validate = true;
} else {
util.error({"error":"store: field definintions not found."});
util.error("store: field definintions not found.");
}
}
......@@ -5558,10 +5529,8 @@
if (answer.response[key]) {
obj[key] = record[key];
} else {
util.error({
"error":"store: field " + key +
" not defined for type =" + pass.type
});
util.error("store: field " + key +
" not defined for type = " + pass.type);
}
} else {
obj[key] = record[key];
......@@ -5626,7 +5595,7 @@
var pass = reply.pass;
if (reply.response) {
if (util.parseIfNeeded(reply.response).data.total_rows === 0) {
if (util.parse(reply.response).data.total_rows === 0) {
return util.ajax(
{"url": "data/" + pass.config.portal_type_title + "_sample.json"}
)
......@@ -5656,7 +5625,7 @@
if (pass.skip === undefined) {
if (reply.response) {
delete pass.needs_fields;
pass.fields = util.parseIfNeeded(reply.response);
pass.fields = util.parse(reply.response);
}
// try to get 1 record
......@@ -5722,7 +5691,7 @@
var parsed, pass = reply.pass;
if (pass.skip === undefined) {
parsed = util.parseIfNeeded(reply.response);
parsed = util.parse(reply.response);
// TODO: WE DON'T NEED ALL OF THIS!
pass.config = parsed;
pass.type = parsed.portal_type_source;
......@@ -5896,10 +5865,40 @@
*/
// NOTE: until we have real data we load fake data on application init!
app.fetchData = function (parcel) {
return storage[parcel.storage].allDocs(parcel.query)
var method, convert, answer;
if (parcel.query._id) {
// TODO: don't set if don't need...
delete parcel.query.limit;
method = "get";
convert = true;
}
return storage[parcel.storage][method || "allDocs"](parcel.query)
.then(function (response) {
// TODO: is this the best way of forcing the allDocs response format
// here?
// TODO: MAKE A CONVERTER HERE
if (convert && response.status === 200) {
answer = {
"data": {
"total_rows": 1,
"rows": [
{
"id": response.id,
"key": response.id,
"value": {},
"doc": response.data
}
]
}
};
} else {
answer = response;
}
return {
"response": response,
"response": answer,
"pass": parcel.pass
};
});
......@@ -5924,13 +5923,13 @@
if (property_dict.optional) {
return RSVP.all([]);
}
util.error({"error": "getFromDisk: URL undefined"});
util.error("getFromDisk: URL undefined");
}
// fetch file
return util.ajax({"url": url})
.then(function (e) {
response = util.parseIfNeeded(e.target.responseText);
response = util.parse(e.target.responseText);
// no need to store? go to next then()
if (property_dict.skip) {
......@@ -5943,7 +5942,7 @@
undefined);
if (storage_location === undefined) {
util.error({"error": "getFromDisk: no storage defined"});
util.error("getFromDisk: no storage defined");
return RSVP.all([]);
}
......@@ -6403,7 +6402,7 @@
$.mobile.loading("hide");
}, 3000);
} else {
util.error({"error": "showStatus: Loader not enabled"});
util.error("showStatus: Loader not enabled");
}
};
......@@ -6586,7 +6585,7 @@
* @param {object/string} data Data to parse
* @return {object} object Parsed object
*/
util.parseIfNeeded = function (data) {
util.parse = function (data) {
if (typeof data === "string") {
return JSON.parse(data);
}
......@@ -6611,9 +6610,7 @@
}
if (supported === false) {
message = fail.splice(0, -1);
util.error(
{"error": "browser: " + message + " not supported"}
);
util.error("browser: " + message + " not supported");
container = factory.element(
"p",
......@@ -6637,7 +6634,7 @@
return true;
}
util.error({"error": "testBrowserSupport: Modernizr undefined"});
util.error("testBrowserSupport: Modernizr undefined");
return false;
};
......@@ -6651,7 +6648,11 @@
*/
// TODO: update global config so we know where to post a ticket to!
util.error = function (err) {
if (typeof err === "string") {
console.log({"error": err});
} else {
console.log(err);
}
};
/* ====================================================================== */
......
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