Commit a9107863 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Render non editable checkbox field as text

parent b1b7c745
......@@ -13,6 +13,5 @@
</head>
<body>
<div data-gadget-url="gadget_html5_input.html" data-gadget-scope="sub"></div>
</body>
</html>
\ No newline at end of file
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.35638.15944.23620</string> </value>
<value> <string>954.35642.48652.3413</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1476260804.53</float>
<float>1476273705.86</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,7 +5,8 @@
rJS(window)
.setState({
type: 'checkbox'
type: 'checkbox',
tag: 'p'
})
.declareMethod('render', function (options) {
......@@ -16,12 +17,34 @@
name: field_json.key,
title: field_json.title
};
state_dict.text_content = state_dict.checked ? '' : '';
return this.changeState(state_dict);
})
.onStateChange(function () {
var gadget = this;
return this.getDeclaredGadget('sub')
.onStateChange(function (modification_dict) {
var element = this.element,
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) {
return input.render(gadget.state);
});
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.35756.30335.63129</string> </value>
<value> <string>954.35867.63296.32580</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476267648.2</float>
<float>1476274434.41</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -26,6 +26,10 @@
element.removeChild(element.firstChild);
}
element.appendChild(new_element);
})
.declareMethod('getTextContent', function (options) {
return this.state.text_content;
});
}(window, document, rJS));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.22958.59420.56644</string> </value>
<value> <string>954.34618.13218.7202</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476194334.9</float>
<float>1476274252.73</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -29,13 +29,12 @@
.onStateChange(function () {
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.value = this.state.value;
}
if (this.state.checked !== undefined) {
textarea.checked = this.state.checked;
}
textarea.setAttribute('name', this.state.name);
textarea.setAttribute('type', this.state.type);
if (this.state.title) {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.35751.28793.55927</string> </value>
<value> <string>954.35751.60338.24780</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476267355.19</float>
<float>1476274067.85</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