Commit f4e03d67 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] LinesField works in non-editable mode

/#/bug_module/20171103-82F24A

/reviewed-on nexedi/erp5!489
parent 4c925ae7
...@@ -8,79 +8,53 @@ ...@@ -8,79 +8,53 @@
return lines; return lines;
} }
function listToBR(lines) {
if (Array.isArray(lines)) {return lines.join("<br/>\n"); }
return lines;
}
rJS(window) rJS(window)
.setState({
.declareMethod('render', function (options) { gadget_rendered: false
return this.changeState(options.field_json);
}) })
.onStateChange(function (modification_dict) { .declareMethod('render', function (options) {
var gadget = this, var gadget = this,
url, new_state = {
value; "default": listToNewlines(options.field_json.default),
"editable": options.field_json.editable,
if (modification_dict.hasOwnProperty('editable')) { "required": options.field_json.required,
if (gadget.state.editable) { "hidden": options.field_json.hidden,
url = 'gadget_html5_textarea.html'; "title": options.field_json.title,
value = listToNewlines(gadget.state.value || gadget.state.default || []); "key": options.field_json.key
} else { };
url = 'gadget_html5_element.html';
value = listToBR(gadget.state.value || gadget.state.default || []); if (this.state.gadget_rendered === false) {
} return gadget.declareGadget("gadget_erp5_field_textarea.html", {scope: 'sub'})
return this.declareGadget(url, {scope: 'sub'}) .push(function (subgadget) {
.push(function (sub_gadget) { gadget.element.appendChild(subgadget.element);
// Clear first to DOM, append after to reduce flickering/manip new_state.gadget_rendered = true;
while (gadget.element.firstChild) { return gadget.changeState(new_state);
gadget.element.removeChild(gadget.element.firstChild);
}
gadget.element.appendChild(sub_gadget.element);
// Use full-blown render when the widget is new
return sub_gadget.render({
value: value,
name: gadget.state.key,
editable: gadget.state.editable,
required: gadget.state.required,
title: gadget.state.title,
hidden: gadget.state.hidden
});
}); });
} }
return this.changeState(new_state);
})
return gadget.getDeclaredGadget('sub') .onStateChange(function () {
.push(function (input) { var gadget = this;
if (modification_dict.hasOwnProperty("value")) { return this.getDeclaredGadget('sub')
if (gadget.state.editable) { .push(function (subgadget) {
modification_dict.value = listToNewlines(modification_dict.value); return subgadget.render({field_json: gadget.state});
} else {
modification_dict.value = listToBR(modification_dict.value);
}
}
// when we only receive changes we can simply pass (minimaly modified) modification dictionary
return input.render(modification_dict);
}); });
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
var gadget = this; return this.getDeclaredGadget('sub')
return gadget.getDeclaredGadget('sub')
.push(function (sub_gadget) { .push(function (sub_gadget) {
return sub_gadget.getContent(); return sub_gadget.getContent();
}); });
}) })
.declareMethod('checkValidity', function () { .declareMethod('checkValidity', function () {
if (this.state.editable) {
return this.getDeclaredGadget('sub') return this.getDeclaredGadget('sub')
.push(function (gadget) { .push(function (subgadget) {
return gadget.checkValidity(); return subgadget.checkValidity();
}); });
}
return true;
}); });
}(window, rJS)); }(window, 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>961.56527.16709.20804</string> </value> <value> <string>963.41690.30150.51729</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>1510071879.23</float> <float>1511408348.35</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -50,6 +50,13 @@ ...@@ -50,6 +50,13 @@
}); });
}) })
.declareMethod('checkValidity', function () {
return this.getDeclaredGadget('sub')
.push(function (subgadget) {
return subgadget.checkValidity();
});
})
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
if (this.state.editable) { if (this.state.editable) {
return this.getDeclaredGadget('sub') return this.getDeclaredGadget('sub')
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value> <value> <string>960.5523.58984.43537</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1479375229.95</float> <float>1511311791.54</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_field_lines.html"]//textarea</td><td></td></tr> <td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_field_lines.html"]//textarea</td><td></td></tr>
<tr><td>type</td> <tr><td>type</td>
<td>field_my_lines_list</td> <td>field_my_lines_list</td>
<td>foo<br/>bar</td></tr> <td>foo<br/><!-- tags and comments get stripped away -->
bar</td></tr>
<!-- Change sorting of the listbox --> <!-- Change sorting of the listbox -->
<tr><td>waitForElementPresent</td> <tr><td>waitForElementPresent</td>
...@@ -32,7 +33,8 @@ ...@@ -32,7 +33,8 @@
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr><td>assertValue</td> <tr><td>assertValue</td>
<td>//textarea[@name='field_my_lines_list']</td> <td>//textarea[@name='field_my_lines_list']</td>
<td>foo<br/>bar</td></tr> <td>foo<br/>
bar</td></tr>
<!-- Save and force unloading of Form and its content from the memory by going back --> <!-- Save and force unloading of Form and its content from the memory by going back -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
...@@ -49,10 +51,12 @@ ...@@ -49,10 +51,12 @@
<!-- Assert value still holds and change it --> <!-- Assert value still holds and change it -->
<tr><td>assertValue</td> <tr><td>assertValue</td>
<td>//textarea[@name='field_my_lines_list']</td> <td>//textarea[@name='field_my_lines_list']</td>
<td>foo<br/>bar</td></tr> <td>foo<br/>
bar</td></tr>
<tr><td>assertValue</td> <tr><td>assertValue</td>
<td>//textarea[@name='field_my_lines_list']</td> <td>//textarea[@name='field_my_lines_list']</td>
<td>foo<br/>bar</td></tr> <td>foo<br/>
bar</td></tr>
<tr><td>type</td> <tr><td>type</td>
<td>//textarea[@name='field_my_lines_list']</td> <td>//textarea[@name='field_my_lines_list']</td>
<td>foo bar</td></tr> <td>foo bar</td></tr>
...@@ -68,7 +72,6 @@ ...@@ -68,7 +72,6 @@
<!-- Save and force unloading of Form and its content from the memory by going back --> <!-- Save and force unloading of Form and its content from the memory by going back -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<tr><td>click</td> <tr><td>click</td>
<td>//div[@data-role='header']//h1/a</td><td></td></tr> <td>//div[@data-role='header']//h1/a</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
......
...@@ -25,12 +25,7 @@ ...@@ -25,12 +25,7 @@
<td>a <td>a
b b
</td></tr> </td></tr>
<tr><td>waitForElementPresent</td> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<td>//button[@data-i18n='Save']</td><td></td></tr>
<tr><td>click</td>
<td>//button[@data-i18n='Save']</td><td></td></tr>
<tr><td>waitForTextPresent</td>
<td>Data updated.</td><td></td></tr>
<!-- Force unloading of Form and its content from the memory by going back --> <!-- Force unloading of Form and its content from the memory by going back -->
<tr><td>click</td> <tr><td>click</td>
<td>//div[@data-role='header']//h1/a</td><td></td></tr> <td>//div[@data-role='header']//h1/a</td><td></td></tr>
...@@ -46,5 +41,18 @@ b ...@@ -46,5 +41,18 @@ b
<td>a <td>a
b b
</td></tr> </td></tr>
<tr><td>click</td>
<td>//button[@name='panel']</td><td></td></tr>
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_panel.html"]//input[@name='editable' and @type='checkbox']</td><td></td></tr>
<tr><td>click</td>
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_panel.html"]//input[@name='editable' and @type='checkbox']</td><td></td></tr>
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_field_lines.html"]//div[@data-gadget-url="${renderjs_url}/gadget_html5_element.html"]/pre</td><td></td></tr>
<tr><td>assertText</td>
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_field_lines.html"]//div[@data-gadget-url="${renderjs_url}/gadget_html5_element.html"]/pre</td>
<td>a
b</td></tr>
</body> </body>
</html> </html>
\ No newline at end of file
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