Commit 602b041e authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: prevent selecting a domain twice

parent fff89222
......@@ -131,7 +131,8 @@
return domsugar('option', {
selected: !!option.selected,
value: option.value,
text: option.text
text: option.text,
disabled: option.disabled
});
}),
operator_option_list = options.operator_option.map(function (option) {
......@@ -182,7 +183,9 @@
]);
}
function createFilterItemTemplate(gadget, query_dict, translation_dict, column_translation_dict) {
function createFilterItemTemplate(gadget, query_dict, translation_dict,
column_translation_dict,
duplicated_query_key_dict) {
var operator_default_list = DEFAULT,
operator_option_list = [],
column_option_list = [],
......@@ -332,13 +335,18 @@
text: column_translation_dict[gadget.state.search_column_list[i][1]] ||
gadget.state.search_column_list[i][1],
value: gadget.state.search_column_list[i][0],
selected: (query_dict.key === gadget.state.search_column_list[i][0])
selected: (query_dict.key === gadget.state.search_column_list[i][0]),
// Do not allow selecting a domain twice
disabled: ((gadget.state.search_column_list[i][0].indexOf(PREFIX_DOMAIN) === 0) &&
duplicated_query_key_dict.hasOwnProperty(gadget.state.search_column_list[i][0]))
});
}
if (!is_selected) {
throw new Error('SearchEditor: no key found for: ' + query_dict.key);
}
duplicated_query_key_dict[query_dict.key] = true;
return generateFilterItemTemplate({
option: column_option_list,
operator_option: operator_option_list,
......@@ -675,7 +683,8 @@
'Search Expression'
])
.push(function (translation_list) {
var filter_dom_list =
var duplicated_query_key_dict = {},
filter_dom_list =
gadget.state.query_list.map(
function (query) {
return createFilterItemTemplate(
......@@ -693,7 +702,8 @@
{
'Searchable Text': translation_list[14],
'Search Expression': translation_list[15]
}
},
duplicated_query_key_dict
);
}
);
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>981.59395.36158.62156</string> </value>
<value> <string>986.30784.11275.3089</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1582023096.49</float>
<float>1599552227.76</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>testFilterItemSelectableWhenOneDomainItemExist</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 RenderJS UI</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Clean Up -->
<tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<!-- Let's set up domain property on listbox -->
<tr><td>open</td>
<td>${base_url}/FooModule_viewFooList/listbox/ListBox_setPropertyList?field_domain_root_list=foo_category+%7C+FooCat+%0A+foo_domain+%7C+FooDomain</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Set Successfully.</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />
<!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/foo_module</td>
<td></td>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tal:block tal:define="search_query python: 'selection_domain_foo_domain:&#34;a&#34;'">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/search_in_form_list" />
</tal:block>
<!-- Open the panel and submit it. Check that the domain is there -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/triggle_filter_and" />
<tal:block tal:define="filter_domain_section_configuration python: {'key': 'DOMAIN_selection_domain_foo_domain', 'value': 'a', 'index': 0, 'option_list': [['a', 'a'], ['a/a1', '${nbsp}${nbsp}${nbsp}${nbsp}a1'], ['a/a2', '${nbsp}${nbsp}${nbsp}${nbsp}a2'], ['b', 'b']]}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_filter_domain_section" />
</tal:block>
<tr>
<td colspan="3"><b>Add a new filter parameter</b></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//button[@class='plus ui-icon-plus ui-btn-icon-left']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//button[@class='plus ui-icon-plus ui-btn-icon-left']</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]</td>
<td></td>
</tr>
<tr>
<td colspan="3"><b>Check that the domain is selectable for the first filter</b></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[1]//select[1]//option[4][@value='DOMAIN_selection_domain_foo_domain' and text()='FooDomain']</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>//div[@class='filter_item_container']/div[1]//select[1]//option[4][@value='DOMAIN_selection_domain_foo_domain' and text()='FooDomain' and @disabled]</td>
<td></td>
</tr>
<tr>
<td colspan="3"><b>Check that the domain can not be selected</b></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[1][@value='COLUMN_id' and text()='ID']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[2][@value='COLUMN_title' and text()='Title']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[3][@value='DOMAIN_selection_domain_foo_category' and text()='FooCat']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[4][@value='DOMAIN_selection_domain_foo_domain' and text()='FooDomain' and @disabled]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[5][@value='TEXT' and text()='Searchable Text']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[6][@value='RAW' and text()='Search Expression']</td>
<td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]//option[7]</td>
<td></td>
</tr>
<tr>
<td>verifyValue</td>
<td>//div[@class='filter_item_container']/div[2]//select[1]</td>
<td>COLUMN_id</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