[gen] Removed pxViewPickList, replaced by a recursive call pxView->pxView.

This commit is contained in:
Gaetan Delannay 2015-02-17 12:50:44 +01:00
parent 8b90d877a8
commit 0b4e78bf83
2 changed files with 57 additions and 68 deletions

View file

@ -295,39 +295,6 @@ class Ref(Field):
<script if="checkboxes">:'initCbs(%s)' % q(ajaxHookId)</script> <script if="checkboxes">:'initCbs(%s)' % q(ajaxHookId)</script>
</div>''') </div>''')
# PX that displays the list of objects the user may select to insert into a
# ref field with link="list".
pxViewPickList = Px('''
<x var="ajaxHookId=ajaxHookId|'%s_%s_poss' % (zobj.id, field.name);
layoutType='view';
inMenu=False;
inPickList=True;
startNumber=field.getStartNumber('list', req, ajaxHookId);
info=field.getPossibleValues(zobj, startNumber=startNumber, \
someObjects=True, removeLinked=True);
objects=info.objects;
totalNumber=info.totalNumber;
batchSize=info.batchSize;
batchNumber=len(objects);
tiedClassName=tiedClassName|ztool.getPortalType(field.klass);
tiedClassLabel=tiedClassLabel|_(tiedClassName);
backHook=(layoutType == 'cell') and zobj.id or None;
target=ztool.getLinksTargetInfo(field.klass, backHook);
mayEdit=mayEdit|\
not field.isBack and zobj.mayEdit(field.writePermission);
mayAdd=False;
mayLink=False;
mayUnlink=False;
changeOrder=False;
changeNumber=False;
numbered=False;
checkboxes=field.getAttribute(zobj, 'checkboxes') and \
(totalNumber &gt; 1);
showSubTitles=showSubTitles|\
req.get('showSubTitles', 'true') == 'true';
collapse=field.getCollapseInfo(obj, True);
subLabel='selectable_objects'">:field.pxViewList</x>''')
# PX that displays referred objects as dropdown menus. # PX that displays referred objects as dropdown menus.
pxMenu = Px(''' pxMenu = Px('''
<img if="menu.icon" src=":menu.icon" title=":menu.text"/><x <img if="menu.icon" src=":menu.icon" title=":menu.text"/><x
@ -387,19 +354,25 @@ class Ref(Field):
<x var2="infos=[field.getReferenceLabel(obj, o, True) \ <x var2="infos=[field.getReferenceLabel(obj, o, True) \
for o in objects]">:', '.join(infos) or _('no_ref')</x>''') for o in objects]">:', '.join(infos) or _('no_ref')</x>''')
# PX that displays referred objects through this field. In mode link="list", # PX that displays referred objects through this field.
# if, in the request, key "scope" is present and holds value "objs", the # In mode link="list", if request key "scope" is:
# pick list (containing possible values) will not be rendered. # - not in the request, the whole field is shown (both available and already
# tied objects);
# - "objs", only tied objects are rendered;
# - "poss", only available objects are rendered (the pick list).
# ! scope is forced to "objs" on non-view "inner" (cell, buttons) layouts.
pxView = Px(''' pxView = Px('''
<x var="ajaxHookId='%s_%s_objs' % (zobj.id, field.name); <x var="layoutType=layoutType|'view';
layoutType=layoutType|'view';
render=field.getRenderMode(layoutType); render=field.getRenderMode(layoutType);
linkList=field.link == 'list'; linkList=field.link == 'list';
renderAll=req.get('scope') != 'objs'; scope=(layoutType != 'view') and 'objs' or \
inPickList=False; scope|req.get('scope', 'all');
inPickList=(scope == 'poss');
ajaxSuffix=inPickList and 'poss' or 'objs';
ajaxHookId='%s_%s_%s' % (zobj.id, field.name, ajaxSuffix);
inMenu=False; inMenu=False;
startNumber=field.getStartNumber(render, req, ajaxHookId); startNumber=field.getStartNumber(render, req, ajaxHookId);
info=field.getValue(zobj,startNumber=startNumber,someObjects=True); info=field.getViewValues(zobj, startNumber, scope);
objects=info.objects; objects=info.objects;
totalNumber=info.totalNumber; totalNumber=info.totalNumber;
numberWidth=len(str(totalNumber)); numberWidth=len(str(totalNumber));
@ -411,32 +384,33 @@ class Ref(Field):
backHook=(layoutType == 'cell') and zobj.id or None; backHook=(layoutType == 'cell') and zobj.id or None;
target=ztool.getLinksTargetInfo(field.klass, backHook); target=ztool.getLinksTargetInfo(field.klass, backHook);
mayEdit=not field.isBack and zobj.mayEdit(field.writePermission); mayEdit=not field.isBack and zobj.mayEdit(field.writePermission);
mayAdd=mayEdit and field.mayAdd(zobj, checkMayEdit=False); mayEd=not inPickList and mayEdit;
mayLink=mayEdit and field.mayAdd(zobj, mode='link', \ mayAdd=mayEd and field.mayAdd(zobj, checkMayEdit=False);
checkMayEdit=False); mayLink=mayEd and field.mayAdd(zobj, mode='link', \
mayUnlink=mayEdit and field.getAttribute(zobj, 'unlink'); checkMayEdit=False);
mayUnlink=mayEd and field.getAttribute(zobj, 'unlink');
addConfirmMsg=field.addConfirm and \ addConfirmMsg=field.addConfirm and \
_('%s_addConfirm' % field.labelId) or ''; _('%s_addConfirm' % field.labelId) or '';
changeOrder=mayEdit and field.getAttribute(zobj, 'changeOrder'); changeOrder=mayEd and field.getAttribute(zobj, 'changeOrder');
sortConfirm=changeOrder and _('sort_confirm'); sortConfirm=changeOrder and _('sort_confirm');
numbered=field.isNumbered(zobj); numbered=not inPickList and field.isNumbered(zobj);
gotoNumber=numbered; gotoNumber=numbered;
changeNumber=not inPickList and numbered and changeOrder and \ changeNumber=not inPickList and numbered and changeOrder and \
(totalNumber &gt; 3); (totalNumber &gt; 3);
checkboxesEnabled=field.getAttribute(zobj, 'checkboxes') and \ checkboxesEnabled=(layoutType != 'cell') and \
(layoutType != 'cell'); field.getAttribute(zobj, 'checkboxes');
checkboxes=checkboxesEnabled and (totalNumber &gt; 1); checkboxes=checkboxesEnabled and (totalNumber &gt; 1);
collapse=field.getCollapseInfo(obj, False); collapse=field.getCollapseInfo(obj, inPickList);
showSubTitles=req.get('showSubTitles', 'true') == 'true'"> showSubTitles=req.get('showSubTitles', 'true') == 'true'">
<!-- JS tables storing checkbox statuses if checkboxes are enabled --> <!-- JS tables storing checkbox statuses if checkboxes are enabled -->
<script if="checkboxesEnabled and renderAll \ <script if="checkboxesEnabled and (render == 'list') and \
and (render == 'list')">:field.getCbJsInit(zobj)</script> (scope == 'all')">:field.getCbJsInit(zobj)</script>
<x if="linkList and renderAll and mayEdit" <!-- The list of possible values, when relevant -->
var2="ajaxHookId='%s_%s_poss' % \ <x if="linkList and (scope == 'all') and mayEdit"
(zobj.id, field.name)">:field.pxViewPickList</x> var2="scope='poss'; layoutType='view'">:field.pxView</x>
<!-- The list of tied or possible values, depending on scope -->
<x if="render == 'list'" <x if="render == 'list'"
var2="subLabel=linkList and \ var2="subLabel=field.getListLabel(inPickList)">:field.pxViewList</x>
'selected_objects' or None">:field.pxViewList</x>
<x if="render in ('menus','minimal')">:getattr(field, 'pxView%s' % \ <x if="render in ('menus','minimal')">:getattr(field, 'pxView%s' % \
render.capitalize())</x> render.capitalize())</x>
</x>''') </x>''')
@ -888,8 +862,8 @@ class Ref(Field):
# Indeed, in this case, unlike m_getValue, we already have all objects # Indeed, in this case, unlike m_getValue, we already have all objects
# in "objects": we can't limit objects "waking up" to at most # in "objects": we can't limit objects "waking up" to at most
# self.maxPerPage. # self.maxPerPage.
total = len(objects)
if paginated and not isSearch: if paginated and not isSearch:
total = len(objects)
objects = objects[startNumber:startNumber + self.maxPerPage] objects = objects[startNumber:startNumber + self.maxPerPage]
# Return the result, wrapped in a SomeObjects instance if required # Return the result, wrapped in a SomeObjects instance if required
if not someObjects: if not someObjects:
@ -903,6 +877,17 @@ class Ref(Field):
res.objects = objects res.objects = objects
return res return res
def getViewValues(self, obj, startNumber, scope):
'''Gets the values as must be shown on pxView. If p_scope is "poss", it
is the list of possible, not-yet-linked, values. Else, it is the list
of linked values. In both cases, we take the subset starting at
p_startNumber.'''
if scope == 'poss':
return self.getPossibleValues(obj, startNumber=startNumber,
someObjects=True, removeLinked=True)
# Return the list of already linked values
return self.getValue(obj, startNumber=startNumber, someObjects=True)
def getLinkedObjectsByMenu(self, obj, objects): def getLinkedObjectsByMenu(self, obj, objects):
'''This method groups p_objects into sub-lists of objects, grouped by '''This method groups p_objects into sub-lists of objects, grouped by
menu (happens when self.render == 'menus').''' menu (happens when self.render == 'menus').'''
@ -1220,6 +1205,13 @@ class Ref(Field):
if not inMenu: return obj.translate('add_ref') if not inMenu: return obj.translate('add_ref')
return tiedClassLabel return tiedClassLabel
def getListLabel(self, inPickList):
'''If self.link == "list", a label must be shown in front of the list.
Moreover, the label is different if the list is a pick list or the
list of tied objects.'''
if self.link != 'list': return
return inPickList and 'selectable_objects' or 'selected_objects'
def mayUnlinkElement(self, obj, tied, raiseError=False): def mayUnlinkElement(self, obj, tied, raiseError=False):
'''May we unlink from this Ref field this specific p_tied object?''' '''May we unlink from this Ref field this specific p_tied object?'''
if not self.unlinkElement: return True if not self.unlinkElement: return True
@ -1267,11 +1259,9 @@ class Ref(Field):
# Complete params with default parameters # Complete params with default parameters
params['ajaxHookId'] = hook; params['ajaxHookId'] = hook;
params['scope'] = hook.rsplit('_', 1)[-1] params['scope'] = hook.rsplit('_', 1)[-1]
px = (params['scope'] == 'poss') and 'pxViewPickList' or 'pxView'
px = '%s:%s' % (self.name, px)
params = sutils.getStringDict(params) params = sutils.getStringDict(params)
return "new AjaxData('%s', '%s', %s, null, '%s')" % \ return "new AjaxData('%s', '%s:pxView', %s, null, '%s')" % \
(hook, px, params, zobj.absolute_url()) (hook, self.name, params, zobj.absolute_url())
def getAjaxDataRow(self, obj, parentHook, **params): def getAjaxDataRow(self, obj, parentHook, **params):
'''Initializes an AjaxData object on the DOM node corresponding to '''Initializes an AjaxData object on the DOM node corresponding to

View file

@ -607,13 +607,12 @@ class AbstractWrapper(object):
tiedClassName=ztool.getPortalType(field.klass); tiedClassName=ztool.getPortalType(field.klass);
target=ztool.getLinksTargetInfo(field.klass, zobj.id); target=ztool.getLinksTargetInfo(field.klass, zobj.id);
mayEdit=not field.isBack and zobj.mayEdit(field.writePermission); mayEdit=not field.isBack and zobj.mayEdit(field.writePermission);
mayLink=not inPickList and mayEdit and \ mayEd=not inPickList and mayEdit;
field.mayAdd(zobj, mode='link', checkMayEdit=False); mayLink=mayEd and field.mayAdd(zobj, mode='link', \
mayUnlink=not inPickList and mayEdit and \ checkMayEdit=False);
field.getAttribute(zobj, 'unlink'); mayUnlink=mayEd and field.getAttribute(zobj, 'unlink');
gotoNumber=numbered; gotoNumber=numbered;
changeOrder=not inPickList and mayEdit and \ changeOrder=mayEd and field.getAttribute(zobj, 'changeOrder');
field.getAttribute(zobj, 'changeOrder');
changeNumber=not inPickList and numbered and changeOrder and \ changeNumber=not inPickList and numbered and changeOrder and \
(totalNumber &gt; 3); (totalNumber &gt; 3);
columns=ztool.getColumnsSpecifiers(tiedClassName, \ columns=ztool.getColumnsSpecifiers(tiedClassName, \