[gen] Added method Mixin.onCall allowing to call a specific method on a gen-class from the UI.

This commit is contained in:
Gaetan Delannay 2014-04-25 12:14:50 +02:00
parent ef21375410
commit cee7b49e3c
2 changed files with 22 additions and 11 deletions

View file

@ -62,7 +62,7 @@ class Ref(Field):
style=":'%s; %s' % (url('linkMany', bg=True), \ style=":'%s; %s' % (url('linkMany', bg=True), \
ztool.getButtonWidth(label))"/> ztool.getButtonWidth(label))"/>
<!-- Unlink several objects --> <!-- Unlink several objects -->
<input if="not isBack and field.unlink and canWrite and not inPickList" <input if="mayUnlink"
var2="imgName=linkList and 'unlinkManyUp' or 'unlinkMany'; var2="imgName=linkList and 'unlinkManyUp' or 'unlinkMany';
action='unlink'; label=_('object_unlink_many')" action='unlink'; label=_('object_unlink_many')"
type="button" class="button" value=":label" type="button" class="button" value=":label"
@ -119,9 +119,8 @@ class Ref(Field):
onclick=":'onDeleteObject(%s)' % q(tiedUid)"/> onclick=":'onDeleteObject(%s)' % q(tiedUid)"/>
</td> </td>
<!-- Unlink --> <!-- Unlink -->
<td if="not isBack and field.unlink and canWrite and not inPickList"> <td if="mayUnlink">
<img var="imgName=linkList and 'unlinkUp' or 'unlink'; <img var="imgName=linkList and 'unlinkUp' or 'unlink'; action='unlink'"
action='unlink'"
class="clickable" title=":_('object_unlink')" src=":url(imgName)" class="clickable" title=":_('object_unlink')" src=":url(imgName)"
onclick=":'onLink(%s,%s,%s,%s)' % (q(action), q(zobj.id), \ onclick=":'onLink(%s,%s,%s,%s)' % (q(action), q(zobj.id), \
q(field.name), q(tiedUid))"/> q(field.name), q(tiedUid))"/>
@ -142,9 +141,10 @@ class Ref(Field):
# Displays the button allowing to add a new object through a Ref field, if # Displays the button allowing to add a new object through a Ref field, if
# it has been declared as addable and if multiplicities allow it. # it has been declared as addable and if multiplicities allow it.
pxAdd = Px(''' pxAdd = Px('''
<input if="showPlusIcon and not inPickList" type="button" class="button" <input if="showPlusIcon and not inPickList" type="button"
var2="navInfo='ref.%s.%s:%s.%d.%d' % (zobj.UID(), \ class="buttonSmall button"
field.name, field.pageName, 0, totalNumber); var2="navInfo='ref.%s.%s:%s.%d.%d' % (zobj.id, field.name, \
field.pageName, 0, totalNumber);
formCall='goto(%s)' % \ formCall='goto(%s)' % \
q('%s/do?action=Create&amp;className=%s&amp;nav=%s' % \ q('%s/do?action=Create&amp;className=%s&amp;nav=%s' % \
(folder.absolute_url(), tiedClassName, navInfo)); (folder.absolute_url(), tiedClassName, navInfo));
@ -218,8 +218,9 @@ class Ref(Field):
(<span class="discreet">:totalNumber</span>) (<span class="discreet">:totalNumber</span>)
<x>:field.pxAdd</x> <x>:field.pxAdd</x>
<!-- The search button if field is queryable --> <!-- The search button if field is queryable -->
<input if="objects and field.queryable" type="button" class="button" <input if="objects and field.queryable" type="button"
var2="label=_('search_title')" value=":label" class="buttonSmall button"
var2="label=_('search_button')" value=":label"
style=":'%s; %s' % (url('search', bg=True), \ style=":'%s; %s' % (url('search', bg=True), \
ztool.getButtonWidth(label))" ztool.getButtonWidth(label))"
onclick=":'goto(%s)' % \ onclick=":'goto(%s)' % \
@ -309,6 +310,7 @@ class Ref(Field):
tiedClassName=tiedClassName|ztool.getPortalType(field.klass); tiedClassName=tiedClassName|ztool.getPortalType(field.klass);
canWrite=canWrite|\ canWrite=canWrite|\
not field.isBack and zobj.allows(field.writePermission); not field.isBack and zobj.allows(field.writePermission);
mayUnlink=False;
showPlusIcon=False; showPlusIcon=False;
atMostOneRef=False; atMostOneRef=False;
navBaseCall='askRefField(%s,%s,%s,%s,**v**)' % \ navBaseCall='askRefField(%s,%s,%s,%s,**v**)' % \
@ -324,7 +326,7 @@ class Ref(Field):
# PX that displays referred objects as menus. # PX that displays referred objects as menus.
pxViewMenus = Px(''' pxViewMenus = Px('''
<table><tr valign="bottom"> <table if="objects"><tr valign="bottom">
<td for="menu in field.getLinkedObjectsByMenu(obj, objects)"> <td for="menu in field.getLinkedObjectsByMenu(obj, objects)">
<!-- A single object in the menu: show a clickable icon to get it --> <!-- A single object in the menu: show a clickable icon to get it -->
@ -376,6 +378,8 @@ class Ref(Field):
folder=zobj.getCreateFolder(); folder=zobj.getCreateFolder();
tiedClassName=ztool.getPortalType(field.klass); tiedClassName=ztool.getPortalType(field.klass);
canWrite=not field.isBack and zobj.allows(field.writePermission); canWrite=not field.isBack and zobj.allows(field.writePermission);
mayUnlink=not isBack and canWrite and \
field.getAttribute(zobj, 'unlink');
showPlusIcon=field.mayAdd(zobj); showPlusIcon=field.mayAdd(zobj);
atMostOneRef=(field.multiplicity[1]==1) and (len(objects)&lt;=1); atMostOneRef=(field.multiplicity[1]==1) and (len(objects)&lt;=1);
addConfirmMsg=field.addConfirm and \ addConfirmMsg=field.addConfirm and \

View file

@ -1180,7 +1180,7 @@ class BaseMixin:
rq = self.getProductConfig().fakeRequest rq = self.getProductConfig().fakeRequest
if not hasattr(rq, 'wrappers'): rq.wrappers = {} if not hasattr(rq, 'wrappers'): rq.wrappers = {}
# Return the Appy wrapper if already present in the cache # Return the Appy wrapper if already present in the cache
uid = self.UID() uid = self.id
if uid in rq.wrappers: return rq.wrappers[uid] if uid in rq.wrappers: return rq.wrappers[uid]
# Create the Appy wrapper, cache it in rq.wrappers and return it # Create the Appy wrapper, cache it in rq.wrappers and return it
wrapper = self.wrapperClass(self) wrapper = self.wrapperClass(self)
@ -1559,4 +1559,11 @@ class BaseMixin:
'''This method is a general hook for transfering processing of a request '''This method is a general hook for transfering processing of a request
to a given field, whose name must be in the request.''' to a given field, whose name must be in the request.'''
return self.getAppyType(self.REQUEST['name']).process(self) return self.getAppyType(self.REQUEST['name']).process(self)
def onCall(self):
'''Calls a specific method on the corresponding wrapper.'''
self.allows('read', raiseError=True)
method = self.REQUEST['method']
obj = self.appy()
return getattr(obj, method)()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------