[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.
cssFiles = {}
jsFiles = {}
bLayouts = Table('lrv-f', width=None)
dLayouts = 'lrv-d-f'
hLayouts = 'lhrv-f'
wLayouts = Table('lrv-f')
@ -98,10 +99,10 @@ class Field:
# Button for showing changes to the field.
pxChanges = Px('''<x if=":zobj.hasHistory(name)"><img class="clickable"
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
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'))"
title=":_('changes_hide')"/></x>''')

View file

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

View file

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