Commit bccc1584 authored by Sven Franck's avatar Sven Franck

fixed back to home & setting page title based on stored page config

parent c56accc9
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
*/ */
login: function (obj) { login: function (obj) {
util.setPopupContentPointer(obj, "login"); util.setPopupContentPointer(obj, "login");
}, },
/** /**
* show export popup * show export popup
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
break; break;
} }
}, },
/** /**
* selecting single checkbox * selecting single checkbox
* @method check * @method check
...@@ -1042,7 +1042,7 @@ ...@@ -1042,7 +1042,7 @@
document.getElementById(scope).appendChild(panel); document.getElementById(scope).appendChild(panel);
return undefined; return undefined;
} }
return panel; return panel;
} }
}; };
...@@ -1654,27 +1654,23 @@ ...@@ -1654,27 +1654,23 @@
* @return {object} HTML fragment * @return {object} HTML fragment
*/ */
// NOTE: we are defaulting to fixed toolbars! // NOTE: we are defaulting to fixed toolbars!
factory.generatePage = function (config, layout) { factory.generatePage = function (spec, layout) {
var page = factory.generateElement( return page = factory.generateElement(
"div", "div",
{ {
"id": config.id, "id": spec.id,
"className": "ui-page " + ("ui-page-theme-" + layout.theme || "") + "className": "ui-page " + ("ui-page-theme-" + layout.theme || "") +
" " + ((layout.fix && layout.fix === false) ? "" : " " + ((layout.fix && layout.fix === false) ? "" :
" ui-page-header-fixed ui-page-footer-fixed") " ui-page-header-fixed ui-page-footer-fixed")
}, { }, {
"data-module": config.id, "data-module": spec.id,
"data-role": "page", "data-role": "page",
"data-url": config.url, "data-url": spec.url,
"data-external-page": true, "data-external-page": true,
"tabindex": 0, "tabindex": 0,
"data-enhanced": true "data-enhanced": true
} }
); );
// set state
return page;
}; };
/* ********************************************************************** */ /* ********************************************************************** */
...@@ -2337,7 +2333,7 @@ ...@@ -2337,7 +2333,7 @@
case "name": case "name":
case "value": case "value":
case "data-": case "data-":
case "role": case "role":
case "type": case "type":
case "readonly": case "readonly":
case "size": case "size":
...@@ -2360,7 +2356,7 @@ ...@@ -2360,7 +2356,7 @@
if (typeof setters["options"][0] === "string") { if (typeof setters["options"][0] === "string") {
// TODO: FIX pulling from JIO // TODO: FIX pulling from JIO
// values = priv.get_hardcoded_values[setters["options"][0]]; // values = priv.get_hardcoded_values[setters["options"][0]];
// //
// for (i = 0; i < values.length; i += 1) { // for (i = 0; i < values.length; i += 1) {
// recurse = values[i]; // recurse = values[i];
// element.appendChild(factory.generateElement( // element.appendChild(factory.generateElement(
...@@ -2815,7 +2811,7 @@ ...@@ -2815,7 +2811,7 @@
obj.include_docs = true; obj.include_docs = true;
} }
if (query_input.columns && query_input.columns.length > 0) { if (query_input.columns && query_input.columns.length > 0) {
obj.select_list = query_input.columns; obj.select_list = query_input.columns;
} }
if (query_input.limit) { if (query_input.limit) {
obj.start = query_input.limit[0]; obj.start = query_input.limit[0];
...@@ -2933,7 +2929,7 @@ ...@@ -2933,7 +2929,7 @@
case "popupbeforeposition": case "popupbeforeposition":
element = undefined; element = undefined;
id = e.target.id; id = e.target.id;
gadget = e.target; gadget = e.target;
break; break;
default: default:
element = e.target || e; element = e.target || e;
...@@ -3268,6 +3264,73 @@ ...@@ -3268,6 +3264,73 @@
/* PAGE SETUP */ /* PAGE SETUP */
/* ====================================================================== */ /* ====================================================================== */
/**
* Update a page (which may already be in the DOM)
* @method updatePage
* @param {object} e Event (pagebeforechange)
* @param {object} data Data passed along with this (JQM) event
*/
init.updatePage = function (e, data) {
var page = e.target;
//NOTE: only setting title at the moment
init.fetchPageLayouts("settings", page.id)
.then(function (reply) {
init.setPageTitle(page, util.parseIfNeeded(reply.response[0]));
})
.fail(util.errorHandler);
};
/**
* Set the page title
* @method setPageTitle
* @param {object} page Page
* @param {object} spec Config of page being loaded
*/
init.setPageTitle = function (page, spec) {
var header, title, text, config;
if (page === undefined) {
util.errorHandler({"error": "Set Title: Missing page"});
} else {
// find header
// WARNING: IE8- children() retrieves comments, too
header = document.getElementById("global_header") || page.children()[0];
if (util.testForClass(header.className, "ui-header")) {
title = header.getElementsByTagName("h1")[0];
title.setAttribute("data-i18n", (spec.title_i18n || ""));
title.removeChild(title.childNodes[0]);
title.appendChild(document.createTextNode((spec.title || "\u00A0")));
}
}
};
/**
* Set page bindings
* @method setPageBindings
* @param {object} e Custom event object
*/
init.setPageBindings = function (e) {
$(document)
// disable JQM filters
.find("[data-filter='true']")
.filter(function () {
return this.getAttribute("data-bound") !== true;
})
.each(function (i, element) {
element.setAttribute("data-bound", true);
$(element).on("filterablebeforefilter", function (e) {
e.preventDefault();
});
});
// TODO: FIND local popups!
};
/** /**
* Parse a page for gadgets and run page setup * Parse a page for gadgets and run page setup
* @method parsePage * @method parsePage
...@@ -3276,7 +3339,7 @@ ...@@ -3276,7 +3339,7 @@
*/ */
init.parsePage = function (e, data) { init.parsePage = function (e, data) {
var create, config, raw_url, handle; var create, config, raw_url, handle;
// console.log("pbc")
// TODO:maybe this is the problem??? // TODO:maybe this is the problem???
if (data) { if (data) {
if (data.options.link) { if (data.options.link) {
...@@ -3290,13 +3353,13 @@ ...@@ -3290,13 +3353,13 @@
if (typeof raw_url === "string") { if (typeof raw_url === "string") {
config = util.parseLink(raw_url); config = util.parseLink(raw_url);
if (e) { if (e) {
// console.log(document.getElementById(raw_url.replace("#", ""))) // console.log(document.getElementById(raw_url.replace("#", "")))
// console.log(data.options.role === "popup") // console.log(data.options.role === "popup")
// console.log(raw_url === $.mobile.getDocumentUrl()) // console.log(raw_url === $.mobile.getDocumentUrl())
// console.log($.mobile.getDocumentUrl()) // console.log($.mobile.getDocumentUrl())
if (document.getElementById(raw_url.replace("#", "")) || if (document.getElementById(raw_url.split("#").pop()) ||
raw_url === $.mobile.getDocumentUrl() || raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
// console.log("let JQM go") // console.log("let JQM go")
...@@ -3318,11 +3381,6 @@ ...@@ -3318,11 +3381,6 @@
// $.mobile.navigate.history.initialDst = ""; // $.mobile.navigate.history.initialDst = "";
// } // }
} }
} else {
// once transition done. Update gadgets if going back to page in DOM
if(data.options.fromHashChange) {
init.setPageTitle(data.toPage[0], {});
}
} }
if (e === undefined || handle) { if (e === undefined || handle) {
if (config.deeplink) { if (config.deeplink) {
...@@ -3496,7 +3554,7 @@ ...@@ -3496,7 +3554,7 @@
}) })
.then(function(reply) { .then(function(reply) {
var parsed, baggage = reply.baggage; var parsed, baggage = reply.baggage;
// single item query // single item query
// TODO: more levels? how to generalize and not only search by _id? // TODO: more levels? how to generalize and not only search by _id?
if (config.layout_level > 0) { if (config.layout_level > 0) {
...@@ -3583,9 +3641,6 @@ ...@@ -3583,9 +3641,6 @@
document.body.appendChild(page); document.body.appendChild(page);
} }
// set title after appending
init.setPageTitle(document.getElementById(config.id), layout);
// JQM treatment // JQM treatment
$(document).enhanceWithin(); $(document).enhanceWithin();
// console.log("CHANGING PAGE") // console.log("CHANGING PAGE")
...@@ -3600,53 +3655,7 @@ ...@@ -3600,53 +3655,7 @@
.fail(util.errorHandler); .fail(util.errorHandler);
}; };
/**
* Set the page title
* @method setTitle
* @param {object} page Page object
* @param {object} layout configuration
*/
init.setPageTitle = function (page, layout) {
var header, title, text = layout.title || page.id;
if (text) {
// WARNING: IE8- children() retrieves comments, too
header = document.getElementById("global_header") ||
page.children()[0];
if (util.testForClass(header.className, "ui-header")) {
title = header.getElementsByTagName("h1")[0];
title.innerHTML = text;
title.setAttribute("data-i18n", (layout.title_i18n || ""));
}
}
};
/**
* Set page bindings
* @method setPageBindings
* @param {object} e Custom event object
*/
init.setPageBindings = function (e) {
$(document)
// disable JQM filters
.find("[data-filter='true']")
.filter(function () {
return this.getAttribute("data-bound") !== true;
})
.each(function (i, element) {
element.setAttribute("data-bound", true);
$(element).on("filterablebeforefilter", function (e) {
e.preventDefault();
});
});
// TODO: FIND local popups!
};
/* ====================================================================== */ /* ====================================================================== */
/* APPLICATION SETUP */ /* APPLICATION SETUP */
/* ====================================================================== */ /* ====================================================================== */
...@@ -3661,7 +3670,7 @@ ...@@ -3661,7 +3670,7 @@
* Thx Diego Perini http://javascript.nwbox.com/ContentLoaded/ * Thx Diego Perini http://javascript.nwbox.com/ContentLoaded/
* @method contentLoaded * @method contentLoaded
* @param {object} win Window * @param {object} win Window
* @param {method} fn Callback to run * @param {method} fn Callback to run
*/ */
init.contentLoaded = function (win, fn) { init.contentLoaded = function (win, fn) {
var done = false, var done = false,
...@@ -3820,9 +3829,15 @@ ...@@ -3820,9 +3829,15 @@
init.parsePage(e, data); init.parsePage(e, data);
}) })
// update global elements depending on state
// NOTE: this should work on deeplinks, too, because going back
// to an existing page will still trigger pagebeforeshow
.on("pagebeforeshow", function (e, data) {
init.updatePage(e, data);
})
// clean dynamic pages on hide // clean dynamic pages on hide
// NOTE: alternative would be to hack JQM and call bindRemove on // NOTE: alternative hack JQM and call "bindRemove" on dynamic pages, too
// dynamically generated content/pages, too. Then JQM will remove
.on("pagehide", "div.ui-page", function (e) { .on("pagehide", "div.ui-page", function (e) {
if (this.getAttribute("data-external-page")) { if (this.getAttribute("data-external-page")) {
$(this).page("destroy").remove() $(this).page("destroy").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