Commit 1737358e authored by Sven Franck's avatar Sven Franck

app: added dynamic content to panels (same as popup)

parent ed406ac4
...@@ -2623,25 +2623,25 @@ ...@@ -2623,25 +2623,25 @@
// TODO: remove, should be handled by content.set // TODO: remove, should be handled by content.set
/** /**
* Load content into a global or local popup * Load content into a dynamic element
* @method generatePopupContents * @method generatePopupContents
* @param {obj} object Action object (popupbeforeposition) * @param {obj} object Action object (popupbeforeposition)
*/ */
factory.util.generatePopupContents = function (obj) { factory.util.generateDynamicContents = function (obj) {
var i, j, promises, fragment, popup, reference, state; var i, j, promises, fragment, element, reference, state, $el;
popup = obj.gadget; element = obj.gadget;
reference = popup.getAttribute("data-reference"); reference = element.getAttribute("data-reference");
state = popup.getAttribute("data-state"); state = element.getAttribute("data-state");
// don't reload if same popup is opened // don't reload if same element is opened
if (state !== reference) { if (state !== reference) {
if (reference === null) { if (reference === null) {
app.util.error("Global Bindings: No popup handler"); app.util.error("Global Bindings: No element handler");
fragment = factory.element("p", {}, {}, {"text": "No popup handler"}); fragment = factory.element("p", {}, {}, {"text": "No element handler"});
} else { } else {
popup.setAttribute("data-state", reference); element.setAttribute("data-state", reference);
popup.setAttribute("data-reference", reference); element.setAttribute("data-reference", reference);
promises = []; promises = [];
// fetch content // fetch content
...@@ -2652,7 +2652,7 @@ ...@@ -2652,7 +2652,7 @@
"pass": undefined "pass": undefined
}) })
.then(function (reply) { .then(function (reply) {
popup.setAttribute("data-reference", reference); element.setAttribute("data-reference", reference);
if (reply.children) { if (reply.children) {
for (i = 0; i < reply.children.length; i += 1) { for (i = 0; i < reply.children.length; i += 1) {
promises[i] = app.content.set(reply.children[i], {}); promises[i] = app.content.set(reply.children[i], {});
...@@ -2672,13 +2672,19 @@ ...@@ -2672,13 +2672,19 @@
} }
// empty gadget and reload // empty gadget and reload
// TODO: how to replace in javaScript? // TODO: how to replace in javaScript?
popup.innerHTML = ""; element.innerHTML = "";
// append // append
popup.appendChild(fragment); element.appendChild(fragment);
}) })
.then(function () { .then(function () {
// TODO: how to reposition popup right after appending? $el = $(element);
$(popup).popup("reposition", {"positionto": "window"});
// TODO: un-jQuery eventually...
switch ($el.data("role")) {
case "popup":
$el.popup("reposition", {"positionto": "window"});
break;
}
}) })
.fail(app.util.error); .fail(app.util.error);
} }
...@@ -2687,16 +2693,15 @@ ...@@ -2687,16 +2693,15 @@
// Remove, should be handled elsewhere! // Remove, should be handled elsewhere!
/** /**
* Identify popup that will open and set content to be loaded * Set pointer on which content to fetch
* @method setPopupPointer * @method setDynamicPointer
* @param {obj} obj Action Object * @param {obj} obj Action Object
* @param {string} pointer Pointer to set to * @param {string} pointer Pointer to set to
*/ */
factory.util.setPopupPointer = function (obj, pointer) { factory.util.setDynamicPointer = function (obj, pointer) {
// don't do nothing if the popup is already set with this content // don't do nothing if the popup is already set with this content
if (obj.gadget.getAttribute("data-reference") === pointer) { if (obj.gadget.getAttribute("data-reference") === pointer) {
return; return false;
} }
obj.gadget.setAttribute("data-reference", pointer); obj.gadget.setAttribute("data-reference", pointer);
}; };
...@@ -2720,8 +2725,23 @@ ...@@ -2720,8 +2725,23 @@
* Add connection to application standard actions or add own actions here * Add connection to application standard actions or add own actions here
* @object map.actions * @object map.actions
**/ **/
// TODO: this whole thing should be loaded optionally
// TODO: best would be that a widget loads it's actions
map.actions = { map.actions = {
"set_search": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_detail_search");
},
"set_filter": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_categories");
},
"set_sorting": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_sort");
},
// =================================================
/** /**
* POST an object * POST an object
* @method new * @method new
...@@ -3093,7 +3113,7 @@ ...@@ -3093,7 +3113,7 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"browse": function (obj) { "browse": function (obj) {
factory.util.setPopupPointer(obj, "browse"); factory.util.setDynamicPointer(obj, "browse");
}, },
/** /**
...@@ -3102,7 +3122,7 @@ ...@@ -3102,7 +3122,7 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"tasks": function (obj) { "tasks": function (obj) {
factory.util.setPopupPointer(obj, "tasks"); factory.util.setDynamicPointer(obj, "tasks");
}, },
/** /**
...@@ -3111,7 +3131,7 @@ ...@@ -3111,7 +3131,7 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"login": function (obj) { "login": function (obj) {
factory.util.setPopupPointer(obj, "login"); factory.util.setDynamicPointer(obj, "login");
}, },
/** /**
...@@ -3120,7 +3140,7 @@ ...@@ -3120,7 +3140,7 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"export": function (obj) { "export": function (obj) {
factory.util.setPopupPointer(obj, "export"); factory.util.setDynamicPointer(obj, "export");
}, },
/** /**
...@@ -5041,17 +5061,17 @@ ...@@ -5041,17 +5061,17 @@
* @return {object} action object * @return {object} action object
**/ **/
app.parseAction = function (e) { app.parseAction = function (e) {
var element, id, gadget, response; var element, id, current, response;
if (e.type === "popupbeforeposition") { if (e.type === "popupbeforeposition" || e.type === "panelopen") {
return { return {
"id": e.target.id, "id": e.target.id,
"gadget": e.target "gadget": e.target
}; };
} }
// NOTE: currentTarget needed for bubbling (eg tree) // NOTE: currentTarget needed for bubbling (eg tree)
element = (e.currentTarget === document ? undefined : e.currentTarget) current = e.currentTarget;
|| e.target || e; element = (current === document ? undefined : current) || e.target || e;
// NOTE: used to be if no popup/panel, use data-ref or data-url else if // NOTE: used to be if no popup/panel, use data-ref or data-url else if
// no href use data-url else href. Should work if element (button) does // no href use data-url else href. Should work if element (button) does
...@@ -5059,7 +5079,6 @@ ...@@ -5059,7 +5079,6 @@
id = element.getAttribute("data-reference") || id = element.getAttribute("data-reference") ||
(element.href || "").split("#")[1] || (element.href || "").split("#")[1] ||
util.getPage().getAttribute("data-url"); util.getPage().getAttribute("data-url");
gadget = document.getElementById(id);
response = { response = {
"element": element, "element": element,
...@@ -5067,8 +5086,7 @@ ...@@ -5067,8 +5086,7 @@
"gadget": document.getElementById(id) "gadget": document.getElementById(id)
}; };
return util.mergeObject( return util.mergeObject({
{
"form": response.gadget.getElementsByTagName("form")[0], "form": response.gadget.getElementsByTagName("form")[0],
"state": (response.gadget || {}).state "state": (response.gadget || {}).state
}, },
...@@ -5294,10 +5312,9 @@ ...@@ -5294,10 +5312,9 @@
// global actions // global actions
.on("click change keyup input", ".action", function (e) { .on("click change keyup input", ".action", function (e) {
var val, var val, last, element, type;
last, element = e.target;
element = e.target, type = element.type;
type = element.type;
// delay all input field actions allowing user to type/select // delay all input field actions allowing user to type/select
if (element.tagName === "INPUT") { if (element.tagName === "INPUT") {
...@@ -5329,9 +5346,9 @@ ...@@ -5329,9 +5346,9 @@
}) })
// popup content loading // popup content loading
.find("#global-popup") .find(".ui-popup, .ui-panel")
.on("popupbeforeposition", function (e) { .on("popupbeforeposition panelopen", function (e) {
factory.util.generatePopupContents(app.parseAction(e)); factory.util.generateDynamicContents(app.parseAction(e));
}); });
// remove focus from active elements on key-tab switches // remove focus from active elements on key-tab switches
......
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