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

[erp5_web_renderjs_ui] HTML5 element gadget now correctly display '0' text content

parent 050ad68b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
<script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="gadget_html5_element.js" type="text/javascript"></script> <script src="gadget_html5_element.js" type="text/javascript"></script>
</head> </head>
<body></body> <body></body>
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.3908.27788.61064</string> </value> <value> <string>963.11788.48702.26146</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>1475499589.67</float> <float>1525874132.93</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, document, rJS */ /*global window, document, rJS, getFirstNonEmpty, isEmpty */
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 3 */
(function (window, document, rJS) { (function (window, document, rJS, getFirstNonEmpty, isEmpty) {
"use strict"; "use strict";
rJS(window) rJS(window)
...@@ -18,15 +18,15 @@ ...@@ -18,15 +18,15 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var state_dict = { var state_dict = {
text_content: options.text_content || "", text_content: getFirstNonEmpty(options.text_content, ""),
inner_html: options.inner_html || "", inner_html: getFirstNonEmpty(options.inner_html, ""),
id: options.id, id: options.id,
tag: options.tag || 'div', tag: options.tag || 'div',
src: options.src, src: options.src,
alt: options.alt, alt: options.alt,
name: options.name, name: options.name,
append: options.append || '', append: getFirstNonEmpty(options.append, ""),
prepend: options.prepend || '' prepend: getFirstNonEmpty(options.prepend, "")
}; };
// data are dictionary thus include it only when defined so it appears // data are dictionary thus include it only when defined so it appears
// in modification_dict only when necessary // in modification_dict only when necessary
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
new_element = document.createElement(this.state.tag), new_element = document.createElement(this.state.tag),
content = this.state.text_content, content = this.state.text_content,
data, data_attr; data, data_attr;
if (!isEmpty(this.state.text_content)) {
if (this.state.text_content) {
if (this.state.prepend) { if (this.state.prepend) {
content = this.state.prepend + "&nbsp;" + content; content = this.state.prepend + "&nbsp;" + content;
} }
...@@ -51,7 +50,7 @@ ...@@ -51,7 +50,7 @@
content = content + "&nbsp;" + this.state.append; content = content + "&nbsp;" + this.state.append;
} }
new_element.textContent = content; new_element.textContent = content;
} else if (this.state.inner_html) { } else if (!isEmpty(this.state.inner_html)) {
new_element.innerHTML = this.state.inner_html; new_element.innerHTML = this.state.inner_html;
} }
if (this.state.id) { if (this.state.id) {
...@@ -87,8 +86,14 @@ ...@@ -87,8 +86,14 @@
if (!this.state.name) { if (!this.state.name) {
return data; return data;
} }
data[this.state.name] = this.state.text_content || this.state.inner_html || ""; if (!isEmpty(this.state.text_content)) {
data[this.state.name] = this.state.text_content;
} else if (!isEmpty(this.state.inner_html)) {
data[this.state.name] = this.state.inner_html;
} else {
data[this.state.name] = "";
}
return data; return data;
}); });
}(window, document, rJS)); }(window, document, rJS, getFirstNonEmpty, isEmpty));
\ No newline at end of file \ No newline at end of file
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.20431.18358.64853</string> </value> <value> <string>967.27766.62273.12083</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1517925786.08</float> <float>1525874417.09</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