Commit 6190e95f authored by Sven Franck's avatar Sven Franck

app: add query params matched to JIO api and lookup in setParam and setSubordinate

parent 52fea96c
...@@ -6011,6 +6011,14 @@ ...@@ -6011,6 +6011,14 @@
// test for auth based access // test for auth based access
pass.grant = true; pass.grant = true;
// update initial query with urlQuery if one was passed
if (pass.url_dict.url_query) {
pass.config_dict.initial_query = util.mergeObject(
pass.url_dict.url_query,
pass.config_dict.initial_query || {}
);
}
// fetch field definitions - why make a query without fieldlist? // fetch field definitions - why make a query without fieldlist?
if (pass.grant || pass.mode === "new") { if (pass.grant || pass.mode === "new") {
app.util.loader("", "status_dict.loading_config"); app.util.loader("", "status_dict.loading_config");
...@@ -6853,22 +6861,25 @@ ...@@ -6853,22 +6861,25 @@
* @param {object} wrapper Wrapping document * @param {object} wrapper Wrapping document
* @returns {object} kid * @returns {object} kid
*/ */
// TODO: clean up, no exceptions (location), clear key + val!
// TODO: make lookup parsing robust!
app.util.setParam = function (kid, wrapper) { app.util.setParam = function (kid, wrapper) {
var i, len, param_list, param, href, loc, splitter, val; var i, len, param_list, param, href, loc, splitter, key, val, lookup, new_val;
param_list = kid.logic.setParam; param_list = kid.logic.setParam;
for (i = 0, len = param_list.length; i < len; i += 1) { for (i = 0, len = param_list.length; i < len; i += 1) {
param = param_list[i]; param = param_list[i];
switch (param[1]) { val = param[1];
key = param[0];
switch (val) {
// NOTE: hacked for oauth redirect url // NOTE: hacked for oauth redirect url
// TODO: remove, not generic!
// TODO: find way to include encoding when setting a href // TODO: find way to include encoding when setting a href
case "location": case "location":
href = kid.direct.href; href = kid.direct.href;
splitter = href.indexOf("?") > 0 ? "&" : "?"; splitter = href.indexOf("?") > 0 ? "&" : "?";
loc = window.location; loc = window.location;
kid.direct.href += splitter + window.encodeURIComponent(param[0]) + kid.direct.href += splitter + window.encodeURIComponent(key) +
"=" + window.encodeURIComponent( "=" + window.encodeURIComponent(
loc.origin + loc.pathname + loc.hash.split("?")[0] loc.origin + loc.pathname + loc.hash.split("?")[0]
); );
...@@ -6876,15 +6887,27 @@ ...@@ -6876,15 +6887,27 @@
// set values or flag for subordination inside map.element // set values or flag for subordination inside map.element
default: default:
if (param[1].split("subordinate_").length > 1) { kid.logic[key] = kid.logic[key] || "";
kid.needs_subordination = true;
} else { if (val.split("subordinate_").length > 1) {
val = param[0];
kid.logic[val] = kid.logic[val] || ""; // NOTE: try to get value from state/URL before flagging
kid.logic[val] += wrapper.property_dict.data.doc[param[1]]; // NOTE: must check for equality, otherwise id foo > foofoo
if (val === "href") { lookup = wrapper.property_dict.state.query.query;
kid.logic[val] = window.encodeURIComponent(kid.logic[val]); if (lookup && lookup.indexOf(val) > -1) {
new_val = lookup.split(val)[1].split("+")[0]
.replace(":=", "").replace(")","");
if (kid.logic[key] !== new_val) {
kid.logic[key] += new_val;
}
} else {
kid.needs_subordination = true;
} }
} else {
kid.logic[key] += wrapper.property_dict.data.doc[val];
// if (key === "href") {
// kid.logic[key] = window.encodeURIComponent(kid.logic[key]);
// }
delete kid.logic.setParam[i]; delete kid.logic.setParam[i];
} }
} }
...@@ -6892,6 +6915,56 @@ ...@@ -6892,6 +6915,56 @@
return kid; return kid;
}; };
/**
* Parse url query parameter into storage query object
* Expects the following URL format:
*
* #foo&
* query:id=bar+foo=baz&
* limit:start=0+items=5&
* sort:id=ascending+foo=descending&
* select:id+foo+baz+cous
*
* @method parseUrlQuery
* @param {string} str String to parse
* @returns {object} Query to run based on parameters
*/
app.util.parseQueryParameter = function (str) {
var i, param_list, param_len, param, initial_query, indicator,
value_list;
param_list = str.split("&");
initial_query = {};
for (i = 0, param_len = param_list.length; i < param_len; i += 1) {
param = param_list[i].split(":");
indicator = param[0];
value_list = param[1];
switch (indicator) {
case "query":
initial_query.query = param[1].replace("=", ":=", "g")
.replace("+", " AND ", "g");
break;
case "limit":
// NOTE: Thanks Tristan!
initial_query.limit = param[1].split("+")
.map(function (part) { return part.split("=")[1]; });
break;
case "sort":
initial_query.sort_on = param[1].split("+").map(function (part) {
var s = part.split("=");
return [s[0], s[1]];
});
break;
case "select":
initial_query.select_list = param[1].replace("+", ",", "g");
break;
}
}
return initial_query;
};
/** /**
* Parse a clicked link to determine which page to load * Parse a clicked link to determine which page to load
* @method parseLink * @method parseLink
...@@ -6899,7 +6972,8 @@ ...@@ -6899,7 +6972,8 @@
* @return {object} navigation object * @return {object} navigation object
**/ **/
app.util.parseLink = function (url) { app.util.parseLink = function (url) {
var i, hash, path, clean_hash, decode, root, last; var i, hash, path, clean_hash, decode, root, last, stripped, url_query,
strip;
hash = $.mobile.path.parseUrl( hash = $.mobile.path.parseUrl(
url.replace($.mobile.dialogHashKey, "") url.replace($.mobile.dialogHashKey, "")
...@@ -6914,7 +6988,15 @@ ...@@ -6914,7 +6988,15 @@
clean_hash = hash; clean_hash = hash;
} }
if (clean_hash === "") { // query parameters
strip = clean_hash.split("&");
stripped = strip[0];
if (strip.length > 1) {
url_query = app.util.parseQueryParameter(strip[1]);
}
if (stripped === "") {
root = util.getPage().getAttribute("data-url"); root = util.getPage().getAttribute("data-url");
return { return {
"data_url": root, "data_url": root,
...@@ -6922,12 +7004,13 @@ ...@@ -6922,12 +7004,13 @@
}; };
} }
// check for mode // check for mode
path = clean_hash.split("/"); path = stripped.split("/");
last = path.length -1; last = path.length -1;
return { return {
"mode": path[last], "mode": path[last],
"fragment_list": path, "fragment_list": path,
"url_query": url_query,
"data_url": clean_hash, "data_url": clean_hash,
"layout_level": last, "layout_level": last,
"deeplink": true, "deeplink": true,
......
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