Commit 022e7c58 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Render non editable checkbox field as text

parent 9441a2d2
...@@ -13,6 +13,5 @@ ...@@ -13,6 +13,5 @@
</head> </head>
<body> <body>
<div data-gadget-url="gadget_html5_input.html" data-gadget-scope="sub"></div>
</body> </body>
</html> </html>
\ 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>954.35638.15944.23620</string> </value> <value> <string>954.35642.48652.3413</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>1476260804.53</float> <float>1476273705.86</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
rJS(window) rJS(window)
.setState({ .setState({
type: 'checkbox' type: 'checkbox',
tag: 'p'
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
...@@ -16,12 +17,34 @@ ...@@ -16,12 +17,34 @@
name: field_json.key, name: field_json.key,
title: field_json.title title: field_json.title
}; };
state_dict.text_content = state_dict.checked ? '' : '';
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
.onStateChange(function () { .onStateChange(function (modification_dict) {
var gadget = this; var element = this.element,
return this.getDeclaredGadget('sub') gadget = this,
url,
result;
if (modification_dict.hasOwnProperty('editable')) {
if (gadget.state.editable) {
url = 'gadget_html5_input.html';
} else {
url = 'gadget_html5_element.html';
}
result = this.declareGadget(url, {scope: 'sub'})
.push(function (input) {
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(input.element);
return input;
});
} else {
result = this.getDeclaredGadget('sub');
}
return result
.push(function (input) { .push(function (input) {
return input.render(gadget.state); return input.render(gadget.state);
}); });
......
...@@ -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.35756.30335.63129</string> </value> <value> <string>954.35867.63296.32580</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>1476267648.2</float> <float>1476274434.41</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
element.removeChild(element.firstChild); element.removeChild(element.firstChild);
} }
element.appendChild(new_element); element.appendChild(new_element);
})
.declareMethod('getTextContent', function (options) {
return this.state.text_content;
}); });
}(window, document, rJS)); }(window, document, rJS));
\ 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.22958.59420.56644</string> </value> <value> <string>954.34618.13218.7202</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>1476194334.9</float> <float>1476274252.73</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -29,13 +29,12 @@ ...@@ -29,13 +29,12 @@
.onStateChange(function () { .onStateChange(function () {
var textarea = this.element.querySelector('input'); var textarea = this.element.querySelector('input');
if (this.state.value !== undefined) { if (this.state.type === 'checkbox') {
textarea.checked = this.state.checked;
} else {
textarea.setAttribute('value', this.state.value); textarea.setAttribute('value', this.state.value);
textarea.value = this.state.value; textarea.value = this.state.value;
} }
if (this.state.checked !== undefined) {
textarea.checked = this.state.checked;
}
textarea.setAttribute('name', this.state.name); textarea.setAttribute('name', this.state.name);
textarea.setAttribute('type', this.state.type); textarea.setAttribute('type', this.state.type);
if (this.state.title) { if (this.state.title) {
......
...@@ -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.35751.28793.55927</string> </value> <value> <string>954.35751.60338.24780</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>1476267355.19</float> <float>1476274067.85</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