Commit c83cb5e6 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Load the editor panel gadget only if user click on a related button

parent c4d2fe8e
...@@ -8,39 +8,26 @@ ...@@ -8,39 +8,26 @@
// acquired method // acquired method
////////////////////////////////////////////// //////////////////////////////////////////////
.allowPublicAcquisition('trigger', function trigger() { .allowPublicAcquisition('trigger', function trigger() {
return this.toggle(); return this.close();
}) })
.declareMethod('toggle', function toggle() { .declareMethod('toggle', function toggle() {
if (this.state.visible) {
return this.close();
}
return this.changeState({ return this.changeState({
visible: !this.state.visible url: undefined
}); });
}) })
.declareMethod('close', function close() { .declareMethod('close', function close() {
return this.changeState({ return this.changeState({
visible: false, url: undefined
url: undefined,
options: undefined
}); });
}) })
.declareMethod('render', function render(url, options) { .declareMethod('render', function render(url, options) {
// XXX Hack to close the panel if the sort/filter button
// is clicked twice
if (url === this.state.url) {
return this.changeState({ return this.changeState({
visible: false, // Hack to close the panel if the sort/filter button
url: undefined, // is clicked twice
options: undefined url: (url === this.state.url) ? undefined : url,
});
}
return this.changeState({
visible: true,
url: url,
options: options options: options
}); });
}) })
...@@ -48,22 +35,19 @@ ...@@ -48,22 +35,19 @@
.onStateChange(function onStateChange(modification_dict) { .onStateChange(function onStateChange(modification_dict) {
var queue, var queue,
gadget = this; gadget = this;
if (this.state.visible) {
if (!this.element.classList.contains('visible')) {
this.element.classList.toggle('visible');
}
} else {
if (this.element.classList.contains('visible')) {
this.element.classList.remove('visible');
}
}
if (modification_dict.hasOwnProperty('url')) { if (modification_dict.hasOwnProperty('url')) {
if (this.state.url === undefined) { if (this.state.url === undefined) {
if (this.element.classList.contains('visible')) {
this.element.classList.remove('visible');
}
while (this.element.firstChild) { while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild); this.element.removeChild(this.element.firstChild);
} }
} else { } else {
if (!this.element.classList.contains('visible')) {
this.element.classList.toggle('visible');
}
queue = this.declareGadget(this.state.url, queue = this.declareGadget(this.state.url,
{scope: "declared_gadget"}); {scope: "declared_gadget"});
} }
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.11788.48702.26146</string> </value> <value> <string>971.13319.43014.16520</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>1526656627.08</float> <float>1540559107.01</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -466,7 +466,12 @@ ...@@ -466,7 +466,12 @@
}) })
.allowPublicAcquisition('renderEditorPanel', .allowPublicAcquisition('renderEditorPanel',
function renderEditorPanel(param_list) { function renderEditorPanel(param_list) {
return route(this, "editor_panel", 'render', param_list); return this.changeState({
// Force calling editor panel render
editor_panel_render_timestamp: new Date().getTime(),
editor_panel_url: param_list[0],
editor_panel_options: param_list[1]
});
}) })
.allowPublicAcquisition("jio_allDocs", function jio_allDocs(param_list) { .allowPublicAcquisition("jio_allDocs", function jio_allDocs(param_list) {
return callJioGadget(this, "allDocs", param_list); return callJioGadget(this, "allDocs", param_list);
...@@ -525,7 +530,8 @@ ...@@ -525,7 +530,8 @@
}) })
.onStateChange(function onStateChange(modification_dict) { .onStateChange(function onStateChange(modification_dict) {
var gadget = this, var gadget = this,
route_result = gadget.state; route_result = gadget.state,
promise_list;
if (modification_dict.hasOwnProperty('error_text')) { if (modification_dict.hasOwnProperty('error_text')) {
return gadget.dropGadget(MAIN_SCOPE) return gadget.dropGadget(MAIN_SCOPE)
...@@ -546,8 +552,11 @@ ...@@ -546,8 +552,11 @@
}); });
} }
promise_list = [];
// Update the main gadget
if (modification_dict.hasOwnProperty('url')) { if (modification_dict.hasOwnProperty('url')) {
return renderMainGadget( promise_list.push(renderMainGadget(
gadget, gadget,
route_result.url, route_result.url,
route_result.options route_result.options
...@@ -575,11 +584,10 @@ ...@@ -575,11 +584,10 @@
// XXX Drop notification // XXX Drop notification
// return header_gadget.notifyLoaded(); // return header_gadget.notifyLoaded();
} }
}); }));
} } else if (modification_dict.hasOwnProperty('render_timestamp')) {
// Same subgadget // Same subgadget
return gadget.getDeclaredGadget(MAIN_SCOPE) promise_list.push(gadget.getDeclaredGadget(MAIN_SCOPE)
.push(function (page_gadget) { .push(function (page_gadget) {
return page_gadget.render(gadget.state.options); return page_gadget.render(gadget.state.options);
}) })
...@@ -588,7 +596,20 @@ ...@@ -588,7 +596,20 @@
updateHeader(gadget), updateHeader(gadget),
updatePanel(gadget) updatePanel(gadget)
]); ]);
}); }));
}
// Update the editor panel
if (modification_dict.hasOwnProperty('editor_panel_url') ||
modification_dict.hasOwnProperty('editor_panel_render_timestamp')) {
promise_list.push(
route(gadget, 'editor_panel', 'render',
[gadget.state.editor_panel_url,
gadget.state.editor_panel_options])
);
}
return RSVP.all(promise_list);
}) })
// Render the page // Render the page
.declareMethod('render', function render(route_result, keep_message) { .declareMethod('render', function render(route_result, keep_message) {
...@@ -604,7 +625,6 @@ ...@@ -604,7 +625,6 @@
.push(function () { .push(function () {
var promise_list = [ var promise_list = [
route(gadget, 'panel', 'close'), route(gadget, 'panel', 'close'),
route(gadget, 'editor_panel', 'close'),
route(gadget, 'router', 'notify', [{modified : false}]) route(gadget, 'router', 'notify', [{modified : false}])
]; ];
if (keep_message !== true) { if (keep_message !== true) {
...@@ -613,8 +633,13 @@ ...@@ -613,8 +633,13 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function () { .push(function () {
return gadget.changeState({url: route_result.url, return gadget.changeState({
options: route_result.options}); url: route_result.url,
options: route_result.options,
editor_panel_url: undefined,
// Force calling main gadget render
render_timestamp: new Date().getTime()
});
}) })
.push(function () { .push(function () {
return decreaseLoadingCounter(gadget); return decreaseLoadingCounter(gadget);
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>971.13016.8122.59972</string> </value> <value> <string>971.13336.56125.62259</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>1540541176.76</float> <float>1540559619.45</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