[gen] Allow to show checkboxes for search results.

This commit is contained in:
Gaetan Delannay 2014-07-19 13:42:39 +02:00
parent b2a2aa5210
commit 792db32f27
4 changed files with 83 additions and 42 deletions

View file

@ -241,7 +241,7 @@ class Ref(Field):
<th if="checkboxes" class="cbCell">
<img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')"
onclick=":'toggleAllRefCbs(%s)' % q(ajaxHookId)"/>
onclick=":'toggleAllCbs(%s)' % q(ajaxHookId)"/>
</th>
</tr>
<!-- Loop on every (tied or selectable) object. -->
@ -272,7 +272,7 @@ class Ref(Field):
</td>
<td if="checkboxes" class="cbCell">
<input if="mayView" type="checkbox" name=":ajaxHookId" checked="checked"
value=":tiedUid" onclick="toggleRefCb(this)"/>
value=":tiedUid" onclick="toggleCb(this)"/>
</td>
</tr>
</table>
@ -286,7 +286,7 @@ class Ref(Field):
<!-- Init checkboxes if present. -->
<script if="checkboxes"
type="text/javascript">:'initRefCbs(%s)' % q(ajaxHookId)
type="text/javascript">:'initCbs(%s)' % q(ajaxHookId)
</script>''')
# PX that displays the list of objects the user may select to insert into a
@ -608,7 +608,10 @@ class Ref(Field):
# NOTE that when a method is defined in field "masterValue" (see parent
# class "Field"), it will be used instead of select (or sselect below).
self.select = select
if isinstance(select, Search): self.select.name = '_field_'
if isinstance(select, Search):
select.name = '_field_'
select.checkboxes = True
select.checkboxesDefault = False
# If you want to specify, for the search screen, a list of objects that
# is different from the one produced by self.select, define an
# alternative method in field "sselect" below.
@ -1145,7 +1148,7 @@ class Ref(Field):
and may hold "unchecked" (initial semantics) or "checked" (inverted
semantics). Inverting semantics allows to keep the array small even
when checking/unchecking all checkboxes.
The mentioned JS arrays and variables are stored as attributes of the
DOM node representing this field.'''
# The initial semantics depends on the checkboxes default value.

View file

@ -26,7 +26,8 @@ class Search:
'''Used for specifying a search for a given class.'''
def __init__(self, name, group=None, sortBy='', sortOrder='asc', limit=None,
default=False, colspan=1, translated=None, show=True,
translatedDescr=None, **fields):
translatedDescr=None, checkboxes=False, checkboxesDefault=True,
**fields):
self.name = name
# Searches may be visually grouped in the portlet.
self.group = Group.get(group)
@ -46,6 +47,10 @@ class Search:
# In the dict below, keys are indexed field names or names of standard
# indexes, and values are search values.
self.fields = fields
# Do we need to display checkboxes for every object of the query result?
self.checkboxes = checkboxes
# Default value for checkboxes
self.checkboxesDefault = checkboxesDefault
@staticmethod
def getIndexName(fieldName, usage='search'):
@ -140,6 +145,14 @@ class Search:
return gutils.callMethod(tool, self.show, klass=klass)
return self.show
def getCbJsInit(self, hookId):
'''Returns the code that creates JS data structures for storing the
status of checkboxes for every result of this search.'''
default = self.checkboxesDefault and 'unchecked' or 'checked'
return '''var node=document.getElementById('%s');
node['_appy_objs_cbs'] = {};
node['_appy_objs_sem'] = '%s';''' % (hookId, default)
class UiSearch:
'''Instances of this class are generated on-the-fly for manipulating a
Search from the User Interface.'''