Commit 5e1e4905 authored by Tomáš Peterka's avatar Tomáš Peterka

[renderjs_ui] Protect page-tabs rendering with mutexes by moving it to changeState

parent 2789ebc9
/*global window, rJS, RSVP, Handlebars, URI, calculatePageTitle */ /*global window, rJS, RSVP, Handlebars, URI, calculatePageTitle */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
/** Page for displaying Views, Jump and BreadCrumb navigation for a document.
*/
(function (window, rJS, RSVP, Handlebars, URI, calculatePageTitle) { (function (window, rJS, RSVP, Handlebars, URI, calculatePageTitle) {
"use strict"; "use strict";
...@@ -12,6 +16,38 @@ ...@@ -12,6 +16,38 @@
.getElementById("table-template") .getElementById("table-template")
.innerHTML); .innerHTML);
/** Go recursively up the parent-chain and insert breadcrumbs in the last argument.
*/
function modifyBreadcrumbList(gadget, parent_link, breadcrumb_action_list) {
if (parent_link === undefined) {
return;
}
var uri = new URI(parent_link.href),
jio_key = uri.segment(2);
if ((uri.protocol() !== 'urn') || (uri.segment(0) !== 'jio') || (uri.segment(1) !== "get")) {
// Parent is the ERP5 site thus recursive calling ends here
breadcrumb_action_list.unshift({
title: "ERP5",
link: "#"
});
return;
}
// Parent is an ERP5 document
return gadget.getUrlFor({command: 'display_stored_state', options: {jio_key: jio_key}})
.push(function (parent_href) {
breadcrumb_action_list.unshift({
title: parent_link.name,
link: parent_href
});
return gadget.jio_getAttachment(jio_key, "links");
})
.push(function (result) {
return modifyBreadcrumbList(gadget, result._links.parent || "#", breadcrumb_action_list);
});
}
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -24,52 +60,33 @@ ...@@ -24,52 +60,33 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/** Render only transforms its arguments and passes them to mutex-protected onStateChange
options:
jio_key: {string} currently viewed document (e.g. foo/1)
page: {string} selected page (always "tab" for page_tab)
view: {string} always "view"
selection, history, selection_index
*/
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var view_list, return this.changeState({
jio_key: options.jio_key
});
})
.onStateChange(function (modification_dict) {
var gadget = this,
view_list = [],
tab_list = [], tab_list = [],
jump_action_list = [], jump_action_list = [],
breadcrumb_action_list = [], breadcrumb_action_list = [],
parent_queue,
gadget = this,
erp5_document, erp5_document,
tab_title = "Views", tab_title = "Views",
tab_icon = "eye", tab_icon = "eye",
jump_list; jump_list;
function handleParent(parent_link) { return gadget.jio_getAttachment(modification_dict.jio_key, "links")
parent_queue.push(function () {
var uri,
jio_key;
if (parent_link !== undefined) {
uri = new URI(parent_link.href);
jio_key = uri.segment(2);
if ((uri.protocol() !== 'urn') || (uri.segment(0) !== 'jio') || (uri.segment(1) !== "get")) {
// Parent is the ERP5 site
breadcrumb_action_list.unshift({
title: "ERP5",
link: "#"
});
} else {
// Parent is an ERP5 document
return gadget.getUrlFor({command: 'display_stored_state', options: {jio_key: jio_key}})
.push(function (parent_href) {
breadcrumb_action_list.unshift({
title: parent_link.name,
link: parent_href
});
return gadget.jio_getAttachment(jio_key, "links");
})
.push(function (result) {
handleParent(result._links.parent || "#");
});
}
}
});
}
return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) { .push(function (result) {
var i, var i,
promise_list = []; promise_list = [];
...@@ -88,7 +105,8 @@ ...@@ -88,7 +105,8 @@
for (i = 0; i < view_list.length; i += 1) { for (i = 0; i < view_list.length; i += 1) {
promise_list.push(gadget.getUrlFor({command: 'change', options: { promise_list.push(gadget.getUrlFor({command: 'change', options: {
view: view_list[i].href, view: view_list[i].href,
page: undefined page: undefined // Views in ERP5 must be forms but because of
// OfficeJS we keep it empty for different default
}})); }}));
} }
for (i = 0; i < jump_list.length; i += 1) { for (i = 0; i < jump_list.length; i += 1) {
...@@ -97,9 +115,11 @@ ...@@ -97,9 +115,11 @@
page: 'search' page: 'search'
}})); }}));
} }
parent_queue = new RSVP.Queue(); promise_list.push(
handleParent(erp5_document._links.parent || "#"); modifyBreadcrumbList(gadget,
promise_list.push(parent_queue); erp5_document._links.parent || "#",
breadcrumb_action_list)
);
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function (all_result) { .push(function (all_result) {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.28347.56387.25600</string> </value> <value> <string>965.39422.59074.24098</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1491225418.18</float> <float>1519114113.71</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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