[gen] Updated the Ajax system to be able to call a method on a Appy wrapper instead of a Zope object.

This commit is contained in:
Gaetan Delannay 2014-08-05 09:48:05 +02:00
parent fdb8b92fcb
commit 636def8d24
3 changed files with 15 additions and 13 deletions

View file

@ -39,6 +39,7 @@ class Field:
# field, keyed by layoutType. # field, keyed by layoutType.
cssFiles = {} cssFiles = {}
jsFiles = {} jsFiles = {}
bLayouts = Table('lrv-f', width=None)
dLayouts = 'lrv-d-f' dLayouts = 'lrv-d-f'
hLayouts = 'lhrv-f' hLayouts = 'lhrv-f'
wLayouts = Table('lrv-f') wLayouts = Table('lrv-f')
@ -98,10 +99,10 @@ class Field:
# Button for showing changes to the field. # Button for showing changes to the field.
pxChanges = Px('''<x if=":zobj.hasHistory(name)"><img class="clickable" pxChanges = Px('''<x if=":zobj.hasHistory(name)"><img class="clickable"
if="not showChanges" src=":url('changes')" title="_('changes_show')" if="not showChanges" src=":url('changes')" title="_('changes_show')"
onclick=":'askField(%s,%s,%s,%s)' % \ onclick=":'askField(%s,%s,%s,null,%s)' % \
(q(tagId), q(zobj.absolute_url()), q('view'), q('True'))"/><img (q(tagId), q(zobj.absolute_url()), q('view'), q('True'))"/><img
class="clickable" if="showChanges" src=":url('changesNo')" class="clickable" if="showChanges" src=":url('changesNo')"
onclick=":'askField(%s,%s,%s,%s)' % \ onclick=":'askField(%s,%s,%s,null,%s)' % \
(q(tagId), q(zobj.absolute_url(), q('view'), q('True'))" (q(tagId), q(zobj.absolute_url(), q('view'), q('True'))"
title=":_('changes_hide')"/></x>''') title=":_('changes_hide')"/></x>''')

View file

@ -280,8 +280,8 @@ function askRefField(hookId, objectUrl, innerRef, startNumber, action,
evalInnerScripts); evalInnerScripts);
} }
function askField(hookId, objectUrl, layoutType, showChanges, masterValues, function askField(hookId, objectUrl, layoutType, customParams, showChanges,
requestValue, error, className, customParams){ masterValues, requestValue, error, className){
// Sends an Ajax request for getting the content of any field. // Sends an Ajax request for getting the content of any field.
var fieldName = hookId.split('_')[1]; var fieldName = hookId.split('_')[1];
var params = {'layoutType': layoutType, 'showChanges': showChanges}; var params = {'layoutType': layoutType, 'showChanges': showChanges};
@ -530,8 +530,8 @@ function updateSlaves(master, slave, objectUrl, layoutType, requestValues,
var err = null; var err = null;
if (errors && (slaveName in errors)) if (errors && (slaveName in errors))
err = errors[slaveName]; err = errors[slaveName];
askField(slaveId, objectUrl, layoutType, false, masterValues, reqValue, askField(slaveId, objectUrl, layoutType, null, false, masterValues,
err, className); reqValue, err, className);
} }
} }
} }
@ -1052,12 +1052,12 @@ function onSelectObjects(nodeId, objectUrl, mode, sortKey, sortOrder,
if (mode == 'repl') { if (mode == 'repl') {
/* Link the selected objects (and unlink the potentially already linked /* Link the selected objects (and unlink the potentially already linked
ones) and refresh the Ref edit widget. */ ones) and refresh the Ref edit widget. */
askField(':'+nodeId,objectUrl,'edit',null,null,null,null,null,params); askField(':'+nodeId, objectUrl, 'edit', params, false);
} }
else { else {
// Link the selected objects and refresh the Ref view widget. // Link the selected objects and refresh the Ref view widget.
params['action'] = 'onSelectFromPopup'; params['action'] = 'onSelectFromPopup';
askField(':'+nodeId,objectUrl,'view',null,null,null,null,null,params); askField(':'+nodeId, objectUrl, 'view', params, false);
} }
} }
@ -1073,10 +1073,10 @@ function onSelectObject(tdId, nodeId, objectUrl) {
else { else {
/* Close the popup and directly refresh the initiator field with the /* Close the popup and directly refresh the initiator field with the
selected object. */ selected object. */
var uids=checkbox.value; var uids = checkbox.value;
closePopup('iframePopup'); closePopup('iframePopup');
askField(':'+nodeId, objectUrl, 'edit', null, null, null, null, null, var params = {'selected': uids, 'semantics': 'checked'};
{'selected': uids, 'semantics': 'checked'}); askField(':'+nodeId, objectUrl, 'edit', params, false);
} }
} }

View file

@ -632,6 +632,7 @@ class AbstractWrapper(object):
dummy=setattr(req, 'pxContext', _ctx_); dummy=setattr(req, 'pxContext', _ctx_);
lang=ztool.getUserLanguage(); q=ztool.quote; lang=ztool.getUserLanguage(); q=ztool.quote;
action=req.get('action', None); action=req.get('action', None);
actionObj=(action and action.startswith(':')) and obj or zobj;
px=req['px'].split(':'); px=req['px'].split(':');
inPopup=req.get('popup') == '1'; inPopup=req.get('popup') == '1';
className=(len(px) == 3) and px[0] or None; className=(len(px) == 3) and px[0] or None;
@ -646,8 +647,8 @@ class AbstractWrapper(object):
x=resp.setHeader('CacheControl', 'no-cache')"> x=resp.setHeader('CacheControl', 'no-cache')">
<!-- If an action is defined, execute it on p_zobj or on p_field. --> <!-- If an action is defined, execute it on p_zobj or on p_field. -->
<x if="action and not field" var2="x=getattr(zobj, action)()"></x> <x if="action and not field" var2="x=getattr(actionObj, action)()"></x>
<x if="action and field" var2="x=getattr(field, action)(zobj)"></x> <x if="action and field" var2="x=getattr(field, action)(actionObj)"></x>
<!-- Then, call the PX on p_obj or on p_field. --> <!-- Then, call the PX on p_obj or on p_field. -->
<x if="not field">:getattr(obj, px[0])</x> <x if="not field">:getattr(obj, px[0])</x>