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

refactor parse-link to enable deeplinking

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