Commit 5f5aed84 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[json_style] Support manual pagination in ListBoxes when the underlaying...

[json_style] Support manual pagination in ListBoxes when the underlaying script does not support limits
parent 17e5aaf2
...@@ -1026,7 +1026,21 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1026,7 +1026,21 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if listbox_form.has_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1): if listbox_form.has_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1):
editable_field_dict[select] = listbox_form.get_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1) editable_field_dict[select] = listbox_form.get_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1)
for sql_document in sql_list: # handle the case when list-scripts are ignoring `limit` - paginate for them
if limit is not None and isinstance(limit, (tuple, list)):
start, num_items = map(int, limit)
if len(sql_list) <= num_items:
# the limit was most likely taken into account thus we don't need to slice
start, num_items = 0, len(sql_list)
else:
start, num_items = 0, len(sql_list)
for document_index, sql_document in enumerate(sql_list):
if document_index < start:
continue
if document_index >= start + num_items:
break
try: try:
document = sql_document.getObject() document = sql_document.getObject()
except AttributeError: except AttributeError:
......
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<!--
Ensure anything can be paginated even thought the list script does not support it.
Fortunately - `contentValues` which is the base of many listboxes does not give
a damn about limits so it is perfect adept for testing.
-->
<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}/foo_module/ListBoxZuite_reset</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Reset Successfully.</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>store</td>
<td>//div[@data-gadget-url="${renderjs_url}/gadget_erp5_field_listbox.html"]</td>
<td>listbox</td></tr>
<!-- Our listbox displays 3 lines so we want to test pagination twice -->
<tr><td>open</td>
<td>${base_url}/foo_module/FooModule_createObjects?start:int=1&amp;num:int=1&amp;create_line:int=0</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
<tr><td>open</td>
<td>${base_url}/foo_module/1/Foo_createObjects?start:int=1&amp;num:int=8&amp;</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Created Successfully.</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />
<tr><td>open</td>
<td>${renderjs_url}/#/foo_module/1?editable=1</td><td></td></tr>
<tr><td>waitForElementPresent</td><!-- wait explicitely for the first listbox which holds the modification history -->
<td>${listbox}//a[@data-i18n="Next"]</td><td></td></tr>
<tr><td>assertElementNotPresent</td><!-- "Next" link must be enabled -->
<td>${listbox}//a[@data-i18n="Next" and contains(@class, "ui-disabled")]</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Records 1 - 3</td><td></td></tr>
<tr><td>click</td>
<td>${listbox}//a[@data-i18n="Next"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr><td>waitForElementPresent</td>
<td>${listbox}//a[@data-i18n="Next"]</td><td></td></tr>
<tr><td>assertElementNotPresent</td><!-- "Next" link must be enabled -->
<td>${listbox}//a[@data-i18n="Next" and contains(@class, "ui-disabled")]</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Records 4 - 6</td><td></td></tr>
<tr><td>click</td><!-- wait explicitely for the first listbox which holds the modification history -->
<td>${listbox}//a[@data-i18n="Next"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr><td>waitForElementPresent</td><!-- wait explicitely for the first listbox which holds the modification history -->
<td>${listbox}//a[@data-i18n="Next"]</td><td></td></tr>
<tr><td>assertElementPresent</td><!-- "Next" link must be disabled because we are at the end -->
<td>${listbox}//a[@data-i18n="Next" and contains(@class, "ui-disabled")]</td><td></td></tr>
<tr><td>assertTextPresent</td>
<td>Records 7 - 8</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