Commit ad323839 authored by Sven Franck's avatar Sven Franck

rewrote dummy-url based navigation

parent e6035e9c
...@@ -614,10 +614,8 @@ ...@@ -614,10 +614,8 @@
if (field.show) { if (field.show) {
if (field.merge === undefined) { if (field.merge === undefined) {
cell = factory.generateElement("td",{},{},{}); cell = factory.generateElement("td",{},{},{});
// TODO: how to enable column based links? // TODO: links should be passed or there is a method to generate
// must be through gadget definitions link = "#" + settings.portal_type_title + "/" + item._id;
link = "object.html?type=" + settings.portal_type_title +
"&mode=edit" + "&item=" + item._id;
// TODO: crap...refactor whole section // TODO: crap...refactor whole section
// fetch non portal_type values // fetch non portal_type values
...@@ -2035,7 +2033,7 @@ ...@@ -2035,7 +2033,7 @@
init.timer = window.setTimeout(function () { init.timer = window.setTimeout(function () {
// update gadgets // update gadgets
init.setPageElements( init.setPageElements(
{}, {"default":{"sections":[{"gadget": config.id}]}}, false {}, {"default":{"section_list":[{"gadget": config.id}]}}, false
); );
init.timer = 0; init.timer = 0;
}, 500); }, 500);
...@@ -2087,7 +2085,7 @@ ...@@ -2087,7 +2085,7 @@
// update gadget // update gadget
init.setPageElements( init.setPageElements(
{}, {"default":{"sections":[{"gadget": config.id}]}}, false {}, {"default":{"section_list":[{"gadget": config.id}]}}, false
); );
}) })
.fail(init.errorHandler); .fail(init.errorHandler);
...@@ -2138,7 +2136,7 @@ ...@@ -2138,7 +2136,7 @@
// update gadget // update gadget
init.setPageElements( init.setPageElements(
{}, {"default":{"sections":[{"gadget": config.id}]}}, false {}, {"default":{"section_list":[{"gadget": config.id}]}}, false
); );
} else { } else {
util.errorHandler({"Error":"No state information stored for gadget"}); util.errorHandler({"Error":"No state information stored for gadget"});
...@@ -2419,41 +2417,21 @@ ...@@ -2419,41 +2417,21 @@
* @param {boolean} hashed Backwards transition * @param {boolean} hashed Backwards transition
* @return {object} pointer object * @return {object} pointer object
*/ */
// TODO: this whole function is crap... works, but refactor!!!! // TODO: replace with renderjs logic
util.parseLink = function (url, back) { util.parseLink = function (url) {
var fragments, var path = $.mobile.path.parseUrl(url),
config = { config = {
"url": url || location.href "url": url
}; };
if (url === undefined) { if (path.hash === "") {
if (location.hash) { config.id = util.getActivePageModule();
// 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 {
// all we can do
config["id"] = util.getActivePageModule();
}
} else { } else {
if (back && location.hash) { config.fragments = path.hash.replace("#","").split("/");
config["id"] = location.hash.replace("#",""); config.id = config.fragments[0];
config["deeplink"] = true; config.deeplink = true;
} else { config.level = config.fragments.length;
fragments = util.removeTrailingSlash(url).split("/");
for (i = 0; i < fragments.length; i += 1) {
fragment = fragments[i];
identifier = fragment.split(";");
if (identifier[1] !== undefined) {
config[identifier[0]] = identifier[1].split("=")[1];
}
}
}
} }
return config; return config;
}; };
...@@ -2478,24 +2456,59 @@ ...@@ -2478,24 +2456,59 @@
/** /**
* Parse a page for gadgets and run page setup * Parse a page for gadgets and run page setup
* @method parsePage * @method parsePage
* @param {object} pointer Parsed link containing info on page to generate * @param {object} e Event (pagebeforechange)
* @param {boolean} create Create a page or not * @param {object} data Data passed along with this (JQM) event
* @param {boolean} hashchange Indicating backwards transition
*/ */
// NOTE: parseLink is called here in case pointers is undefined! init.parsePage = function (e, data) {
init.parsePage = function (url, create, hashchange) { var create, config, raw_url, handle;
var config = util.parseLink(url, hashchange);
if (config.deeplink) { if (data) {
create = true; if (data.options.link) {
raw_url = data.options.link[0].href;
} else {
raw_url = data.toPage;
}
} else {
raw_url = location.href;
} }
init.fetchPageLayouts("settings", config.id) if (typeof raw_url === "string") {
.then(function (layouts) { config = util.parseLink(raw_url);
init.setPageElements(config, layouts, create)
}) if (e) {
.then(init.setPageBindings) if (document.getElementById(raw_url.replace("#", "")) ||
.fail(util.errorHandler); raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") {
return;
}
if (document.getElementById(config.id)) {
e.preventDefault();
return;
} else {
// PASS!
handle = true;
e.preventDefault();
}
}
} else {
// once transition done. Update gadgets if going back to page in DOM
if(data.options.fromHashChange) {
init.setPageTitle(data.toPage[0], {});
}
return;
}
if (e === undefined || handle) {
if (config.deeplink) {
create = true;
}
init.fetchPageLayouts("settings", config.id)
.then(function (layouts) {
init.setPageElements(config, layouts, create)
})
.then(init.setPageBindings)
.fail(util.errorHandler);
}
}; };
/** /**
...@@ -2536,7 +2549,7 @@ ...@@ -2536,7 +2549,7 @@
element, element,
promises = [], promises = [],
fragment = document.createDocumentFragment(), fragment = document.createDocumentFragment(),
layout = layouts[config.layout || "default"]; layout = layouts[config.level || 0];
if (create === true) { if (create === true) {
page = factory.generatePage(config, layout); page = factory.generatePage(config, layout);
...@@ -2549,7 +2562,7 @@ ...@@ -2549,7 +2562,7 @@
} }
} }
gadgets = layout.sections || page.querySelectorAll("[data-gadget-id]"); gadgets = layout.section_list || page.querySelectorAll("[data-gadget-id]");
// generate content // generate content
// NOTE: this may include local header/footer/panel/popups // NOTE: this may include local header/footer/panel/popups
...@@ -2909,37 +2922,9 @@ ...@@ -2909,37 +2922,9 @@
// generate dynamic pages // generate dynamic pages
.on("pagebeforechange", function (e, data) { .on("pagebeforechange", function (e, data) {
var clean_url, init.parsePage(e, data);
raw_url = data.toPage,
hashchange = data.options.fromHashChange;
if (typeof raw_url === "string") {
clean_url = util.parseLink(raw_url, hashchange).id;
// stay idle if...
// 2nd pagebeforechange for this page
if (document.getElementById(raw_url.replace("#","")) ||
// going back to first page
raw_url === $.mobile.getDocumentUrl() ||
// opening a popup
data.options.role === "popup") {
return;
}
if (document.getElementById(clean_url)) {
// page in DOM (with clean_url) Stop, because same page transition
e.preventDefault();
} else {
// generate a new page and transition to it
init.parsePage(raw_url, true, hashchange);
e.preventDefault();
}
} else {
//TODO: this should update the whole layout not only the title
if(data.options.fromHashChange) {
init.setPageTitle(data.toPage[0], {});
}
}
}) })
// clean dynamic pages on hide // clean dynamic pages on hide
// NOTE: alternative would be to hack JQM and call bindRemove on // NOTE: alternative would be to hack JQM and call bindRemove on
// dynamically generated content/pages, too. Then JQM will remove // dynamically generated content/pages, too. Then JQM will remove
......
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