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