Commit 69024c79 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Editor panel: uses gadget state

Ensure a new subgadget is declared when the panel is opened

Editor panel can be closed from the sort/filter buttons
parent f66e9101
/*jslint indent: 2, maxerr: 3, nomen: true, maxlen: 80 */ /*jslint indent: 2, maxerr: 3, nomen: true, maxlen: 80 */
/*global window, rJS */ /*global window, rJS, RSVP */
(function (window, rJS) { (function (window, rJS, RSVP) {
"use strict"; "use strict";
rJS(window) rJS(window)
...@@ -8,44 +8,88 @@ ...@@ -8,44 +8,88 @@
// acquired method // acquired method
////////////////////////////////////////////// //////////////////////////////////////////////
.allowPublicAcquisition('trigger', function () { .allowPublicAcquisition('trigger', function () {
this.element.classList.toggle('visible'); return this.toggle();
}) })
.declareMethod('close', function () { .declareMethod('toggle', function () {
var element = this.element; if (this.state.visible) {
while (element.firstChild) { return this.close();
element.removeChild(element.firstChild);
}
if (element.classList.contains('visible')) {
element.classList.remove('visible');
} }
return this.changeState({
visible: !this.state.visible
});
})
.declareMethod('close', function () {
return this.changeState({
visible: false,
url: undefined,
options: undefined
});
}) })
.declareMethod('render', function (url, options) { .declareMethod('render', function (url, options) {
this.element.classList.toggle('visible'); // XXX Hack to close the panel if the sort/filter button
// is clicked twice
if (url === this.state.url) {
return this.changeState({
visible: false,
url: undefined,
options: undefined
});
}
return this.changeState({ return this.changeState({
visible: true,
url: url, url: url,
options: JSON.stringify(options) options: options
}); });
}) })
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var gadget = this, var queue,
declared_gadget; gadget = this;
if (gadget.state.url && modification_dict.hasOwnProperty('options')) { if (this.state.visible) {
return gadget.declareGadget(gadget.state.url, if (!this.element.classList.contains('visible')) {
{scope: "declared_gadget"}) this.element.classList.toggle('visible');
.push(function (result) { }
declared_gadget = result; } else {
return declared_gadget.render(JSON.parse(gadget.state.options)); if (this.element.classList.contains('visible')) {
}) this.element.classList.remove('visible');
.push(function () { }
return gadget.close(); }
if (modification_dict.hasOwnProperty('url')) {
if (this.state.url === undefined) {
while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
} else {
queue = this.declareGadget(this.state.url,
{scope: "declared_gadget"});
}
} else {
if (this.state.url !== undefined) {
queue = this.getDeclaredGadget("declared_gadget");
}
}
if (queue !== undefined) {
return queue
.push(function (declared_gadget) {
return RSVP.all([
declared_gadget,
declared_gadget.render(gadget.state.options)
]);
}) })
.push(function () { .push(function (result_list) {
gadget.element.appendChild(declared_gadget.element); if (modification_dict.hasOwnProperty('url')) {
gadget.element.classList.toggle('visible'); while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild);
}
gadget.element.appendChild(result_list[0].element);
}
}); });
} }
}); });
}(window, rJS));
\ No newline at end of file }(window, rJS, RSVP));
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.35625.39214.6929</string> </value> <value> <string>955.38199.61252.57992</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>1476259803.78</float> <float>1480349448.29</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