[gen] Positioned checkboxes on the left.

This commit is contained in:
Gaetan Delannay 2014-07-29 19:21:37 +02:00
parent dda894089a
commit 302d54c7ce
4 changed files with 36 additions and 27 deletions

View file

@ -251,6 +251,11 @@ class Ref(Field):
field.shownInfo, dir)"> field.shownInfo, dir)">
<tr if="field.showHeaders"> <tr if="field.showHeaders">
<th if="not inPickList and numbered" width=":numbered"></th> <th if="not inPickList and numbered" width=":numbered"></th>
<th if="checkboxes" class="cbCell">
<img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')"
onclick=":'toggleAllCbs(%s)' % q(ajaxHookId)"/>
</th>
<th for="column in columns" width=":column.width" <th for="column in columns" width=":column.width"
align=":column.align" var2="refField=column.field"> align=":column.align" var2="refField=column.field">
<span>:_(refField.labelId)</span> <span>:_(refField.labelId)</span>
@ -258,11 +263,6 @@ class Ref(Field):
<x var="className=tiedClassName; <x var="className=tiedClassName;
field=refField">:tool.pxShowDetails</x> field=refField">:tool.pxShowDetails</x>
</th> </th>
<th if="checkboxes" class="cbCell">
<img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')"
onclick=":'toggleAllCbs(%s)' % q(ajaxHookId)"/>
</th>
</tr> </tr>
<!-- Loop on every (tied or selectable) object. --> <!-- Loop on every (tied or selectable) object. -->
<tr for="tied in objects" valign="top" <tr for="tied in objects" valign="top"
@ -271,6 +271,10 @@ class Ref(Field):
objectIndex=field.getIndexOf(zobj, tiedUid)|None; objectIndex=field.getIndexOf(zobj, tiedUid)|None;
mayView=tied.o.mayView()"> mayView=tied.o.mayView()">
<td if="not inPickList and numbered">:field.pxNumber</td> <td if="not inPickList and numbered">:field.pxNumber</td>
<td if="checkboxes" class="cbCell">
<input if="mayView" type="checkbox" name=":ajaxHookId" checked="checked"
value=":tiedUid" onclick="toggleCb(this)"/>
</td>
<td for="column in columns" width=":column.width" align=":column.align" <td for="column in columns" width=":column.width" align=":column.align"
var2="refField=column.field"> var2="refField=column.field">
<!-- The "title" field --> <!-- The "title" field -->
@ -290,16 +294,11 @@ class Ref(Field):
if="field.isShowable(zobj, 'result')">:field.pxRender</x> if="field.isShowable(zobj, 'result')">:field.pxRender</x>
</x> </x>
</td> </td>
<td if="checkboxes" class="cbCell">
<input if="mayView" type="checkbox" name=":ajaxHookId" checked="checked"
value=":tiedUid" onclick="toggleCb(this)"/>
</td>
</tr> </tr>
</table> </table>
<!-- Global actions --> <!-- Global actions -->
<div if="mayEdit and (totalNumber &gt; 1)" <div if="mayEdit and checkboxes">:field.pxGlobalActions</div>
align=":dright">:field.pxGlobalActions</div>
<!-- (Bottom) navigation --> <!-- (Bottom) navigation -->
<x>:tool.pxNavigate</x> <x>:tool.pxNavigate</x>

View file

@ -33,10 +33,10 @@ class BaseMixin:
return self return self
o = property(get_o) o = property(get_o)
def getInitiatorInfo(self): def getInitiatorInfo(self, appy=False):
'''Gets information about a potential initiator object from the request. '''Gets information about a potential initiator object from the request.
Returns a 3-tuple (initiator, pageName, field): Returns a 3-tuple (initiator, pageName, field):
* initiator is the initiator (Zope) object; * initiator is the initiator (Zope or Appy) object;
* pageName is the page on the initiator where the origin of the Ref * pageName is the page on the initiator where the origin of the Ref
field lies; field lies;
* field is the Ref instance. * field is the Ref instance.
@ -46,7 +46,9 @@ class BaseMixin:
splitted = rq['nav'].split('.') splitted = rq['nav'].split('.')
initiator = self.getTool().getObject(splitted[1]) initiator = self.getTool().getObject(splitted[1])
fieldName, page = splitted[2].split(':') fieldName, page = splitted[2].split(':')
return initiator, page, initiator.getAppyType(fieldName) field = initiator.getAppyType(fieldName)
if appy: initiator = initiator.appy()
return initiator, page, field
def createOrUpdate(self, created, values, def createOrUpdate(self, created, values,
initiator=None, initiatorField=None): initiator=None, initiatorField=None):
@ -96,7 +98,8 @@ class BaseMixin:
obj.historizeData(previousData) obj.historizeData(previousData)
# Manage potential link with an initiator object # Manage potential link with an initiator object
if created and initiator: initiator.appy().link(initiatorField.name,obj) if created and initiator:
initiator.appy().link(initiatorField.name, obj.appy())
# Call the custom "onEdit" if available # Call the custom "onEdit" if available
msg = None # The message to display to the user. It can be set by onEdit msg = None # The message to display to the user. It can be set by onEdit

View file

@ -377,6 +377,11 @@ class ToolWrapper(AbstractWrapper):
<table class="list" width="100%"> <table class="list" width="100%">
<!-- Headers, with filters and sort arrows --> <!-- Headers, with filters and sort arrows -->
<tr if="showHeaders"> <tr if="showHeaders">
<th if="checkboxes" class="cbCell" style=":cbDisplay">
<img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')"
onclick=":'toggleAllCbs(%s)' % q(checkboxesId)"/>
</th>
<th for="column in columns" <th for="column in columns"
var2="field=column.field; var2="field=column.field;
sortable=ztool.isSortable(field.name, className, 'search'); sortable=ztool.isSortable(field.name, className, 'search');
@ -385,11 +390,6 @@ class ToolWrapper(AbstractWrapper):
<x>::ztool.truncateText(_(field.labelId))</x> <x>::ztool.truncateText(_(field.labelId))</x>
<x>:tool.pxSortAndFilter</x><x>:tool.pxShowDetails</x> <x>:tool.pxSortAndFilter</x><x>:tool.pxShowDetails</x>
</th> </th>
<th if="checkboxes" class="cbCell" style=":cbDisplay">
<img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')"
onclick=":'toggleAllCbs(%s)' % q(checkboxesId)"/>
</th>
</tr> </tr>
<!-- Results --> <!-- Results -->
@ -401,19 +401,19 @@ class ToolWrapper(AbstractWrapper):
obj=zobj.appy(); mayView=zobj.mayView(); obj=zobj.appy(); mayView=zobj.mayView();
cbId='%s_%s' % (checkboxesId, currentNumber)" cbId='%s_%s' % (checkboxesId, currentNumber)"
class=":loop.zobj.odd and 'even' or 'odd'"> class=":loop.zobj.odd and 'even' or 'odd'">
<td for="column in columns"
var2="field=column.field" id=":'field_%s' % field.name"
width=":column.width"
align=":column.align">:tool.pxQueryField</td>
<!-- A checkbox if required --> <!-- A checkbox if required -->
<td if="checkboxes" class="cbCell" id=":cbId" style=":cbDisplay"> <td if="checkboxes" class="cbCell" id=":cbId" style=":cbDisplay">
<input type="checkbox" name=":checkboxesId" checked="checked" <input type="checkbox" name=":checkboxesId" checked="checked"
value=":zobj.id" onclick="toggleCb(this)"/> value=":zobj.id" onclick="toggleCb(this)"/>
</td> </td>
<td for="column in columns"
var2="field=column.field" id=":'field_%s' % field.name"
width=":column.width"
align=":column.align">:tool.pxQueryField</td>
</tr> </tr>
</table> </table>
<!-- The button for selecting objects and closing the popup. --> <!-- The button for selecting objects and closing the popup. -->
<div if="inPopup and cbShown" align=":dright"> <div if="inPopup and cbShown" align=":dleft">
<input type="button" class="button" <input type="button" class="button"
var="label=_('object_link_many')" var="label=_('object_link_many')"
value=":label" value=":label"

View file

@ -705,8 +705,7 @@ class AbstractWrapper(object):
def __setattr__(self, name, value): def __setattr__(self, name, value):
appyType = self.o.getAppyType(name) appyType = self.o.getAppyType(name)
if not appyType: if not appyType: raise Exception('Attribute "%s" does not exist.' %name)
raise 'Attribute "%s" does not exist.' % name
appyType.store(self.o, value) appyType.store(self.o, value)
def __getattribute__(self, name): def __getattribute__(self, name):
@ -737,6 +736,7 @@ class AbstractWrapper(object):
elif name == 'user': return self.o.getTool().getUser() elif name == 'user': return self.o.getTool().getUser()
elif name == 'fields': return self.o.getAllAppyTypes() elif name == 'fields': return self.o.getAllAppyTypes()
elif name == 'siteUrl': return self.o.getTool().getSiteUrl() elif name == 'siteUrl': return self.o.getTool().getSiteUrl()
elif name == 'initiator': return self.o.getInitiatorInfo(True)
# Now, let's try to return a real attribute. # Now, let's try to return a real attribute.
res = object.__getattribute__(self, name) res = object.__getattribute__(self, name)
# If we got an Appy field, return its value for this object # If we got an Appy field, return its value for this object
@ -957,6 +957,13 @@ class AbstractWrapper(object):
if res: return res._len # It is a LazyMap instance if res: return res._len # It is a LazyMap instance
else: return 0 else: return 0
def ids(self, fieldName):
'''Returns the identifiers of the objects linked to this one via field
name p_fieldName. WARNING: do not modify this list, it is the true
list that is stored in the database (excepted if empty). Modifying it
will probably corrupt the database.'''
return getattr(self.o.aq_base, fieldName, ())
def countRefs(self, fieldName): def countRefs(self, fieldName):
'''Counts the number of objects linked to this one via Ref field '''Counts the number of objects linked to this one via Ref field
p_fieldName.''' p_fieldName.'''