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,45 +16,24 @@ ...@@ -12,45 +16,24 @@
.getElementById("table-template") .getElementById("table-template")
.innerHTML); .innerHTML);
gadget_klass /** Go recursively up the parent-chain and insert breadcrumbs in the last argument.
///////////////////////////////////////////////////////////////// */
// Acquired methods function modifyBreadcrumbList(gadget, parent_link, breadcrumb_action_list) {
///////////////////////////////////////////////////////////////// if (parent_link === undefined) {
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") return;
.declareAcquiredMethod("getUrlFor", "getUrlFor") }
.declareAcquiredMethod("translateHtml", "translateHtml") var uri = new URI(parent_link.href),
.declareAcquiredMethod("updateHeader", "updateHeader")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var view_list,
tab_list = [],
jump_action_list = [],
breadcrumb_action_list = [],
parent_queue,
gadget = this,
erp5_document,
tab_title = "Views",
tab_icon = "eye",
jump_list;
function handleParent(parent_link) {
parent_queue.push(function () {
var uri,
jio_key;
if (parent_link !== undefined) {
uri = new URI(parent_link.href);
jio_key = uri.segment(2); jio_key = uri.segment(2);
if ((uri.protocol() !== 'urn') || (uri.segment(0) !== 'jio') || (uri.segment(1) !== "get")) { if ((uri.protocol() !== 'urn') || (uri.segment(0) !== 'jio') || (uri.segment(1) !== "get")) {
// Parent is the ERP5 site // Parent is the ERP5 site thus recursive calling ends here
breadcrumb_action_list.unshift({ breadcrumb_action_list.unshift({
title: "ERP5", title: "ERP5",
link: "#" link: "#"
}); });
} else { return;
}
// Parent is an ERP5 document // Parent is an ERP5 document
return gadget.getUrlFor({command: 'display_stored_state', options: {jio_key: jio_key}}) return gadget.getUrlFor({command: 'display_stored_state', options: {jio_key: jio_key}})
.push(function (parent_href) { .push(function (parent_href) {
...@@ -61,15 +44,49 @@ ...@@ -61,15 +44,49 @@
return gadget.jio_getAttachment(jio_key, "links"); return gadget.jio_getAttachment(jio_key, "links");
}) })
.push(function (result) { .push(function (result) {
handleParent(result._links.parent || "#"); return modifyBreadcrumbList(gadget, result._links.parent || "#", breadcrumb_action_list);
}); });
} }
} gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("updateHeader", "updateHeader")
/////////////////////////////////////////////////////////////////
// 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) {
return this.changeState({
jio_key: options.jio_key
}); });
} })
return gadget.jio_getAttachment(options.jio_key, "links") .onStateChange(function (modification_dict) {
var gadget = this,
view_list = [],
tab_list = [],
jump_action_list = [],
breadcrumb_action_list = [],
erp5_document,
tab_title = "Views",
tab_icon = "eye",
jump_list;
return gadget.jio_getAttachment(modification_dict.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