Commit d313ad41 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Fixed a problem related to the naming of listbox. It is now possible to use...

Fixed a problem related to the naming of listbox. It is now possible to use listboxes with any ID, and change page even if for forms with multiple listboxes.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14502 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 44c371ec
...@@ -34,6 +34,7 @@ from Products.Formulator import Widget, Validator ...@@ -34,6 +34,7 @@ from Products.Formulator import Widget, Validator
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
from Products.Formulator.Errors import FormValidationError, ValidationError from Products.Formulator.Errors import FormValidationError, ValidationError
from Selection import Selection, DomainSelection from Selection import Selection, DomainSelection
from SelectionTool import createFolderMixInPageSelectionMethod
from Products.ERP5Type.Utils import getPath from Products.ERP5Type.Utils import getPath
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
...@@ -1944,6 +1945,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine): ...@@ -1944,6 +1945,9 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
html_list = [] html_list = []
# Generate page selection methods based on the Listbox id
createFolderMixInPageSelectionMethod(field_id)
# Check is there is a validation error at the level of the listbox # Check is there is a validation error at the level of the listbox
# as a whole. This will be required later to decide wherer to # as a whole. This will be required later to decide wherer to
# display values from (ie. from the REQUEST or from the object) # display values from (ie. from the REQUEST or from the object)
......
...@@ -1465,6 +1465,9 @@ from ZPublisher.mapply import mapply ...@@ -1465,6 +1465,9 @@ from ZPublisher.mapply import mapply
method_id_filter_list = [x for x in FolderMixIn.__dict__ if callable(getattr(FolderMixIn, x))] method_id_filter_list = [x for x in FolderMixIn.__dict__ if callable(getattr(FolderMixIn, x))]
candidate_method_id_list = [x for x in SelectionTool.__dict__ if callable(getattr(SelectionTool, x)) and not x.startswith('_') and not x.endswith('__roles__') and x not in method_id_filter_list] candidate_method_id_list = [x for x in SelectionTool.__dict__ if callable(getattr(SelectionTool, x)) and not x.startswith('_') and not x.endswith('__roles__') and x not in method_id_filter_list]
# Monkey patch FolderMixIn with SelectionTool methods
# kept here for compatibility with previous implementations
# of Listbox HTML renderer. See bellow new implementation
for property_id in candidate_method_id_list: for property_id in candidate_method_id_list:
def portal_selection_wrapper(self, wrapper_property_id=property_id, *args, **kw): def portal_selection_wrapper(self, wrapper_property_id=property_id, *args, **kw):
""" """
...@@ -1480,3 +1483,50 @@ for property_id in candidate_method_id_list: ...@@ -1480,3 +1483,50 @@ for property_id in candidate_method_id_list:
security_property = getattr(SelectionTool, security_property_id, None) security_property = getattr(SelectionTool, security_property_id, None)
if security_property is not None: if security_property is not None:
setattr(FolderMixIn, security_property_id, security_property) setattr(FolderMixIn, security_property_id, security_property)
def createFolderMixInPageSelectionMethod(listbox_id):
"""
This method must be called by listbox at rendering time.
It dynamically creates methods on FolderMixIn in line
with the naming of the listbox field. Generated method
are able to convert request parameters in order to
mimic the API of a listbox with ID "listbox". This
approach was required for example to implement
multiple multi-page listboxes in view mode. It also
opens the way towards multiple editable listboxes in the same
page although this is something which we can not recommend.
"""
# Immediately return in the method already exists
test_method_id = "%s_nextPage" % listbox_id
if hasattr(FolderMixIn, test_method_id):
return
# Monkey patch FolderMixIn
for property_id in candidate_method_id_list:
def portal_selection_wrapper(self, wrapper_listbox_id=listbox_id,
wrapper_property_id=property_id, *args, **kw):
"""
Wrapper method for SelectionTool.
"""
portal_selection = getToolByName(self, 'portal_selections')
request = self.REQUEST
selection_name_property_id = "%s_list_selection_name" % listbox_id
listbox_uid_property_id = "%s_uid" % listbox_id
list_start_property_id = "%s_list_start" % listbox_id
# Rename request parameters
if request.has_key(selection_name_property_id):
request.form['list_selection_name'] = request[selection_name_property_id]
if request.has_key(listbox_uid_property_id):
request.form['listbox_uid'] = request[listbox_uid_property_id]
if request.has_key(list_start_property_id):
request.form['list_start'] = request[list_start_property_id]
# Call the wrapper
method = getattr(portal_selection, wrapper_property_id)
return mapply(method, positional=args, keyword=request,
context=self, bind=1)
new_property_id = "%s_%s" % (listbox_id, property_id)
setattr(FolderMixIn, new_property_id, portal_selection_wrapper)
security_property_id = '%s__roles__' % (property_id, )
security_property = getattr(SelectionTool, security_property_id, None)
if security_property is not None:
new_security_property_id = '%s__roles__' % (new_property_id, )
setattr(FolderMixIn, new_security_property_id, security_property)
\ No newline at end of file
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
"> ">
<!-- ListBox starts here. --> <!-- ListBox starts here. -->
<input type="hidden" name="list_selection_name" value="default" tal:attributes="value selection_name" /> <input type="hidden" name="list_selection_name" value="default" tal:attributes="value selection_name" />
<input type="hidden" name="list_selection_name" value="default"
tal:attributes="value selection_name;
name string:${field_id}_list_selection_name" />
<input tal:condition="md5_string" type="hidden" name="md5_object_uid_list" value="checksum" tal:attributes="value md5_string" /> <input tal:condition="md5_string" type="hidden" name="md5_object_uid_list" value="checksum" tal:attributes="value md5_string" />
<tal:replace tal:content="nothing"> <tal:replace tal:content="nothing">
...@@ -144,6 +147,7 @@ ...@@ -144,6 +147,7 @@
id="listbox_previous_page" type="image" src="1leftarrowv.png" id="listbox_previous_page" type="image" src="1leftarrowv.png"
title="Previous Page" name="previousPage:method" title="Previous Page" name="previousPage:method"
tal:attributes="id string:${field_id}_previous_page; tal:attributes="id string:${field_id}_previous_page;
name string:${field_id}_previousPage:method;
src string:${portal_url_string}/images/1leftarrowv.png" src string:${portal_url_string}/images/1leftarrowv.png"
i18n:domain="ui" i18n:attributes="title" /> i18n:domain="ui" i18n:attributes="title" />
</td> </td>
...@@ -151,7 +155,8 @@ ...@@ -151,7 +155,8 @@
<select id="listbox_page_selection" name="list_start" title="Change Page" size="1" <select id="listbox_page_selection" name="list_start" title="Change Page" size="1"
tal:define="lines here/getMaxLineNumber" tal:define="lines here/getMaxLineNumber"
tal:attributes="id string:${field_id}_page_selection; tal:attributes="id string:${field_id}_page_selection;
onChange string:submitAction(this.form, '${context_url}/setPage')" name string:${field_id}_list_start;
onChange string:submitAction(this.form, '${context_url}/${field_id}_setPage')"
i18n:domain="ui" i18n:attributes="title"> i18n:domain="ui" i18n:attributes="title">
<option value="0" <option value="0"
tal:repeat="p python: range(0, here.total_pages)" tal:repeat="p python: range(0, here.total_pages)"
...@@ -165,6 +170,7 @@ ...@@ -165,6 +170,7 @@
id="listbox_next_page" type="image" src="1rightarrowv.png" id="listbox_next_page" type="image" src="1rightarrowv.png"
title="Next Page" name="nextPage:method" title="Next Page" name="nextPage:method"
tal:attributes="id string:${field_id}_next_page; tal:attributes="id string:${field_id}_next_page;
name string:${field_id}_nextPage:method;
src string:${portal_url_string}/images/1rightarrowv.png" src string:${portal_url_string}/images/1rightarrowv.png"
i18n:domain="ui" i18n:attributes="title" /> i18n:domain="ui" i18n:attributes="title" />
</td> </td>
...@@ -192,10 +198,12 @@ ...@@ -192,10 +198,12 @@
name="checkAll:method" value="1" name="checkAll:method" value="1"
src="checkall.png" alt="Check All" title="Check All" src="checkall.png" alt="Check All" title="Check All"
tal:attributes="id string:${field_id}_check_all; tal:attributes="id string:${field_id}_check_all;
name string:${field_id}_checkAll:method;
src string:${portal_url_string}/images/checkall.png" src string:${portal_url_string}/images/checkall.png"
i18n:domain="ui" i18n:attributes="title" />&nbsp;<input id="listbox_uncheck_all" type="image" name="uncheckAll:method" value="1" i18n:domain="ui" i18n:attributes="title" />&nbsp;<input id="listbox_uncheck_all" type="image" name="uncheckAll:method" value="1"
src="%(portal_url_string)s/images/decheckall.png" style="border: 0" alt="Uncheck All" title="Uncheck All" src="%(portal_url_string)s/images/decheckall.png" style="border: 0" alt="Uncheck All" title="Uncheck All"
tal:attributes="id string:${field_id}_uncheck_all; tal:attributes="id string:${field_id}_uncheck_all;
name string:${field_id}_uncheckAll:method;
src string:${portal_url_string}/images/decheckall.png" src string:${portal_url_string}/images/decheckall.png"
i18n:domain="ui" i18n:attributes="title" /> i18n:domain="ui" i18n:attributes="title" />
</td> </td>
......
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