Commit 934722cb authored by Sven Franck's avatar Sven Franck

refactor parse-link to enable deeplinking

parent e1060f36
...@@ -323,7 +323,6 @@ ...@@ -323,7 +323,6 @@
/* ********************************************************************** */ /* ********************************************************************** */
factory.map_buttons = erp5.map_buttons; factory.map_buttons = erp5.map_buttons;
factory.map_info = erp5.map_info; factory.map_info = erp5.map_info;
factory.map_types = erp5.map_portal_types;
factory.map_actions = erp5.map_actions; factory.map_actions = erp5.map_actions;
factory.map_gadgets = erp5.map_gadgets; factory.map_gadgets = erp5.map_gadgets;
factory.map_references = erp5.map_references; factory.map_references = erp5.map_references;
...@@ -2456,7 +2455,7 @@ ...@@ -2456,7 +2455,7 @@
"_mimetype": "application/json" "_mimetype": "application/json"
}); });
}; };
url = "data/" + factory.map_types[attachment] + ".json"; url = "data/" + attachment + ".json";
return jIO.util return jIO.util
.ajax({"url": url, "dataType":'json'}) .ajax({"url": url, "dataType":'json'})
...@@ -2502,6 +2501,7 @@ ...@@ -2502,6 +2501,7 @@
} }
return url; return url;
}; };
/** /**
* parse a link into query-able parameters * parse a link into query-able parameters
* @method parseLink * @method parseLink
...@@ -2509,47 +2509,37 @@ ...@@ -2509,47 +2509,37 @@
* @param {object} location object * @param {object} location object
* @return {object} pointer object * @return {object} pointer object
*/ */
// TODO: map this to URL router! refactor... // TODO: map this to URL router! And... this is crap!
util.parseLink = function (url, location) { util.parseLink = function (url) {
var i, href, pointers, url_fragments, fragment, identifier; var fragments, config;
if (url === undefined) { config = {
// deeplink "url": url || location.href
if (location !== undefined) { };
href = location.href;
pointers = {
"url": href
};
// don't show index.html > / if (url === undefined) {
// WARNING: requires IE8- requires shim if (location.hash) {
// TODO: not sure that id can be used globally!!! // TODO: break this down further e.g. #invoices/1234-56767/1 (map?)
if (href.substr(href.lastIndexOf('/') + 1) === "") { config["id"] = location.hash.replace("#","");
pointers["id"] = util.getActivePageModule(); // flag to generate a deeplinked page dynamically!
return pointers; config["deeplink"] = true;
}
} else { } else {
util.errorHandler({"Error":"parseLink: Missing location object"}); // all we can do
config["id"] = util.getActivePageModule();
} }
} else { } else {
// clicked link fragments = util.removeTrailingSlash(url).split("/");
url_fragments = util.removeTrailingSlash(url).split("/");
pointers = {
"url": url
};
for (i = 0; i < url_fragments.length; i += 1) { for (i = 0; i < fragments.length; i += 1) {
fragment = url_fragments[i]; fragment = fragments[i];
identifier = fragment.split(";"); identifier = fragment.split(";");
if (identifier[1] !== undefined) { if (identifier[1] !== undefined) {
pointers[identifier[0]] = identifier[1].split("=")[1]; config[identifier[0]] = identifier[1].split("=")[1];
} }
} }
return pointers;
} }
return config;
return undefined;
}; };
...@@ -2576,9 +2566,13 @@ ...@@ -2576,9 +2566,13 @@
* @param {object} pointer Parsed link containing info on page to generate * @param {object} pointer Parsed link containing info on page to generate
* @param {boolean} create Create a page or not * @param {boolean} create Create a page or not
*/ */
// TODO: either page id or data-module define what happens. Improve. // NOTE: parseLink is called here in case pointers is undefined!
init.parsePage = function (pointers, create) { init.parsePage = function (url, create) {
var page, config = pointers || util.parseLink(undefined, location); var config = util.parseLink(url);
if (config.deeplink) {
create = true;
}
init.fetchPageLayouts("settings", config.id) init.fetchPageLayouts("settings", config.id)
.then(function (layouts) { .then(function (layouts) {
...@@ -2661,7 +2655,7 @@ ...@@ -2661,7 +2655,7 @@
// no need to fetch field definitions if we are updating? // no need to fetch field definitions if we are updating?
if (create !== false) { if (create !== false) {
return util.fetchConfiguration( return util.fetchConfiguration(
"settings", "portal_types", portal_type "settings", "portal_types", gadget_config.portal_type_fields
); );
} }
return undefined; return undefined;
...@@ -3002,18 +2996,14 @@ ...@@ -3002,18 +2996,14 @@
// generate dynamic pages // generate dynamic pages
.on("pagebeforechange", function (e, data) { .on("pagebeforechange", function (e, data) {
var page;
// TODO: mercy...not merci...
if (typeof data.toPage === "string") { if (typeof data.toPage === "string") {
page = document.getElementById(data.toPage.replace("#","")); // stay calm if...
if (document.getElementById(data.toPage.replace("#","")) ||
if (page ||
data.toPage === $.mobile.getDocumentUrl() || data.toPage === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
return; return;
} }
init.parsePage(util.parseLink(data.toPage), true); init.parsePage(data.toPage, true);
e.preventDefault(); e.preventDefault();
} }
}) })
......
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