Commit 3becf829 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] LinesField are valid when not editable

/reviewed-on nexedi/erp5!551
parent 43a37bab
"""(Re)Sets properties of chosen Fields in Foo_view.
Use this in your tests to alter for example Float Field configuration
instead of copy&pasting new form and changing such property manualy.
Usage: input parameters are supposed to have key <field-name>__<property_name> (please
note double underscore being separator). Those field/property combination will get
propagated into the view IF we already have default value for it.
Example: in your test, call ${base_url}/FooView_setFieldsProperties?my_quantity__precision=2&amp;listbox_quantity__precision=checked
"""
portal = context.getPortalObject()
form = portal.Foo_view
request = context.REQUEST
if not property_dict:
# script called via URL receives its parameters in REQUEST.form
property_dict.update(request.form)
field_default = {
'default': '',
'description': '',
'css_class': '',
'alternate_name': '',
'display_width': '20',
'display_maxwidth': '',
'extra': '',
'external_validator': '',
'enabled': 'checked',
'editable': 'checked',
'required': '',
'hidden': '',
'whitespace_preserve': '',
}
default = {
# feel free to add more fields from the comment bellow or on your own
'my_lines_list': dict(
title='Lines',
view_separator='<br />',
width='40',
height='5',
unicode='',
max_linelength='',
max_lines='',
max_length='',
**field_default
)
}
# For now - control fields only which are needed
# If anyone wishes to control more feel free to move
# the desired field from the comment bellow to the dict above
'''
'my_quantity': dict(
title='Quantity',
input_type='text',
input_style='-1 234.5',
precision='1',
**field_default
),
'listbox': dict(
title='Foo Lines',
lines=3,
columns="""id | ID
title | Title
quantity | Quantity
start_date | Date
catalog.uid | Uid""",
searchable_columns="""id | ID
title | Title
quantity | Quantity
start_date | Date""",
sort="id | id",
list_method="objectValues",
count_method="countFolder",
stat_method="portal_catalog",
selection_name="foo_selection",
portal_types="Foo Line | Foo Line",
search="checked",
select="checked",
editable_columns="""id | ID
title | Title
quantity | quantity
start_date | Date""",
stat_columns="quantity | Foo_statQuantity",
page_navigation_template="ListBox_viewSliderPageNavigationRenderer",
list_action="list",
**field_default
),
'listbox_quantity': dict(
title='Quantity',
input_type='text',
input_style='-1 234.5',
precision='',
**field_default
),
}
'''
# update defaults with user defined values
for composed_key, value in property_dict.items():
field_name, property_name = composed_key.split('__')
# to allow overriding only default values
# throw an exception in case of non-existence of the field/property
assert default[field_name][property_name], 'Uknown field {} and property {}'.format(field_name, property_name)
default[field_name][property_name] = value
# update actual fields
for field_name in default:
field = form.get_field(field_name)
field.manage_edit_xmlrpc(
field.form.validate(
{'field_' + key: value
for key, value in default[field_name].items()}
)
)
return 'Set Successfully.'
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**property_dict</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>FooView_setFieldsProperties</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Set Properties of Fields in Foo_view </string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -51,6 +51,9 @@
})
.declareMethod('checkValidity', function () {
if (!this.state.editable) {
return true;
}
return this.getDeclaredGadget('sub')
.push(function (subgadget) {
return subgadget.checkValidity();
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.41690.30150.51729</string> </value>
<value> <string>964.54328.21867.14506</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1511408348.35</float>
<float>1516015281.65</float>
<string>UTC</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testNonEditableDialogLinesField</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test non-editable lines field in editable form</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test non-editable lines field in editable form</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/PTZuite_CommonTemplate/macros/init" />
<!-- Make lines field non-editable -->
<tr><td>open</td>
<td>${base_url}/FooView_setFieldsProperties?my_lines_list__editable=</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Set Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/Zuite_waitForActivities</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Done.</td><td></td></tr>
<!-- Shortcut for full renderjs url -->
<tr><td>store</td>
<td>${base_url}/web_site_module/renderjs_runner</td>
<td>renderjs_url</td></tr>
<tr><td>open</td>
<td>${renderjs_url}/#/foo_module/1?editable=1</td><td></td></tr>
<!-- Make sure lines render as non-editable -->
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]</td><td></td></tr>
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]//pre</td><td></td></tr>
<tr><td>verifyElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]//pre</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]</td><td></td></tr>
<tr><td>waitForElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]//pre</td><td></td></tr>
<tr><td>verifyElementPresent</td>
<td>//div[@data-gadget-scope="field_my_lines_list"]//pre</td><td></td></tr>
<!-- Reset lines field back to defaults -->
<tr><td>open</td>
<td>${base_url}/FooView_setFieldsProperties</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Set Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/Zuite_waitForActivities</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Done.</td><td></td></tr>
</tbody>
</table>
</body>
</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