Commit 9fa1ea05 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: use domsugar in the panel

parent 7409a2cc
/*jslint nomen: true, indent: 2, maxerr: 3, unparam: true */ /*jslint nomen: true, indent: 2, maxerr: 3, unparam: true */
/*global window, document, rJS, RSVP, Node, asBoolean , ensureArray, /*global window, document, rJS, RSVP, Node, asBoolean , ensureArray,
mergeGlobalActionWithRawActionList*/ mergeGlobalActionWithRawActionList, domsugar*/
(function (window, document, rJS, RSVP, Node, asBoolean, ensureArray, (function (window, document, rJS, RSVP, Node, asBoolean, ensureArray,
mergeGlobalActionWithRawActionList) { mergeGlobalActionWithRawActionList, domsugar) {
"use strict"; "use strict";
function appendDt(fragment, dt_title, dt_icon, function appendDt(fragment, dt_title, dt_icon,
...@@ -13,26 +13,24 @@ ...@@ -13,26 +13,24 @@
// <a class="{{class_name}}" href="{{href}}">{{title}}</a> // <a class="{{class_name}}" href="{{href}}">{{title}}</a>
// </dd> // </dd>
// {{/each}} // {{/each}}
var dt_element = document.createElement('dt'), //////////////////////
dd_element, var element_list = [
a_element, domsugar('dt', {
text: dt_title,
'class': 'ui-btn-icon-left ui-icon-' + dt_icon
})
],
i; i;
dt_element.textContent = dt_title;
dt_element.setAttribute('class', 'ui-btn-icon-left ui-icon-' + dt_icon);
fragment.appendChild(dt_element);
for (i = 0; i < action_list.length; i += 1) { for (i = 0; i < action_list.length; i += 1) {
dd_element = document.createElement('dd'); element_list.push(domsugar('dd', {'class': 'document-listview'}, [
dd_element.setAttribute('class', 'document-listview'); domsugar('a', {
a_element = document.createElement('a'); href: href_list[index + i],
if (action_list[i].class_name) { text: action_list[i].title,
// Avoid add class='undefined' in HTML 'class': action_list[i].class_name || null
a_element.setAttribute('class', action_list[i].class_name); })
} ]));
a_element.href = href_list[index + i];
a_element.textContent = action_list[i].title;
dd_element.appendChild(a_element);
fragment.appendChild(dd_element);
} }
fragment.appendChild(domsugar(null, element_list));
} }
rJS(window) rJS(window)
...@@ -145,7 +143,6 @@ ...@@ -145,7 +143,6 @@
clone_list, clone_list,
jump_list, jump_list,
dl_fragment, dl_fragment,
dl_element,
queue = new RSVP.Queue(); queue = new RSVP.Queue();
if (modification_dict.hasOwnProperty("visible")) { if (modification_dict.hasOwnProperty("visible")) {
...@@ -202,9 +199,7 @@ ...@@ -202,9 +199,7 @@
}) })
.push(function (result_list) { .push(function (result_list) {
var editable_value = [], var editable_value = [],
ul_fragment = document.createDocumentFragment(), element_list = [],
a_element,
li_element,
icon_and_key_list = [ icon_and_key_list = [
'home', null, 'home', null,
'puzzle-piece', 'm', 'puzzle-piece', 'm',
...@@ -213,28 +208,22 @@ ...@@ -213,28 +208,22 @@
'search', 's', 'search', 's',
'sliders', null, 'sliders', null,
'power-off', 'o' 'power-off', 'o'
], ];
ul_element = gadget.element.querySelector("ul");
for (i = 0; i < result_list[0].length; i += 1) { for (i = 0; i < result_list[0].length; i += 1) {
// <li><a href="URL" class="ui-btn-icon-left ui-icon-ICON" data-i18n="TITLE" accesskey="KEY"></a></li> // <li><a href="URL" class="ui-btn-icon-left ui-icon-ICON" data-i18n="TITLE" accesskey="KEY"></a></li>
a_element = document.createElement('a'); element_list.push(domsugar('li', [
li_element = document.createElement('li'); domsugar('a', {
a_element.href = result_list[0][i]; href: result_list[0][i],
a_element.setAttribute('class', 'ui-btn-icon-left ui-icon-' + icon_and_key_list[2 * i]); 'class': 'ui-btn-icon-left ui-icon-' + icon_and_key_list[2 * i],
if (icon_and_key_list[2 * i + 1] !== null) { accesskey: icon_and_key_list[2 * i + 1],
a_element.setAttribute('accesskey', icon_and_key_list[2 * i + 1]); text: result_list[1][i + 1]
} })
a_element.textContent = result_list[1][i + 1]; ]));
li_element.appendChild(a_element);
ul_fragment.appendChild(li_element);
} }
while (ul_element.firstChild) { domsugar(gadget.element.querySelector("ul"),
ul_element.removeChild(ul_element.firstChild); [domsugar(null, element_list)]);
}
ul_element.appendChild(ul_fragment);
// Update the checkbox field value // Update the checkbox field value
if (gadget.state.editable) { if (gadget.state.editable) {
editable_value = ['editable']; editable_value = ['editable'];
...@@ -327,11 +316,7 @@ ...@@ -327,11 +316,7 @@
queue queue
.push(function () { .push(function () {
if (dl_fragment) { if (dl_fragment) {
dl_element = gadget.element.querySelector("dl"); domsugar(gadget.element.querySelector("dl"), [dl_fragment]);
while (dl_element.firstChild) {
dl_element.removeChild(dl_element.firstChild);
}
dl_element.appendChild(dl_fragment);
} }
}); });
return queue; return queue;
...@@ -426,4 +411,4 @@ ...@@ -426,4 +411,4 @@
}, /*useCapture=*/false, /*preventDefault=*/true); }, /*useCapture=*/false, /*preventDefault=*/true);
}(window, document, rJS, RSVP, Node, asBoolean, ensureArray, }(window, document, rJS, RSVP, Node, asBoolean, ensureArray,
mergeGlobalActionWithRawActionList)); mergeGlobalActionWithRawActionList, domsugar));
\ No newline at end of file \ No newline at end of file
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>991.63550.23294.43315</string> </value> <value> <string>994.51061.29790.4608</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1620660511.51</float> <float>1631621138.31</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