[gen] Ref field: first cmplete version of Ref with link='popup'.

This commit is contained in:
Gaetan Delannay 2014-07-28 12:29:16 +02:00
parent 0bcd0055a3
commit a45dfa8dd0
5 changed files with 93 additions and 45 deletions

View file

@ -736,7 +736,7 @@ class ToolMixin(BaseMixin):
elif ':' in name:
# The search is defined in a Ref field with link=popup. Get the
# search, the initiator object and the Ref field.
uid, ref = name.split(':')
uid, ref, mode = name.split(':')
initiator = self.getObject(uid, appy=True)
initiatorField = initiator.getField(ref)
res = getattr(initiator.klass, ref).select
@ -756,7 +756,7 @@ class ToolMixin(BaseMixin):
# Return a UiSearch if required.
if ui:
res = UiSearch(res, className, self)
if initiator: res.setInitiator(initiator, initiatorField)
if initiator: res.setInitiator(initiator, initiatorField, mode)
return res
def advancedSearchEnabledFor(self, klass):

View file

@ -249,11 +249,13 @@ function askObjectHistory(hookId, objectUrl, maxPerPage, startNumber) {
askAjaxChunk(hookId, 'GET', objectUrl, 'pxHistory', params);
}
function askRefField(hookId, objectUrl, fieldName, innerRef, startNumber,
action, actionParams){
function askRefField(hookId, objectUrl, innerRef, startNumber, action,
actionParams){
var hookElems = hookId.split('_');
var fieldName = hookElems[1];
// Sends an Ajax request for getting the content of a reference field.
var startKey = hookId + '_startNumber';
var scope = hookId.split('_').pop();
var scope = hookElems.pop();
var params = {'innerRef': innerRef, 'scope': scope};
params[startKey] = startNumber;
if (action) params['action'] = action;
@ -1028,7 +1030,7 @@ function onSelectDate(cal) {
}
}
function onSelectObjects(nodeId, objectUrl, sortKey, sortOrder,
function onSelectObjects(nodeId, objectUrl, mode, sortKey, sortOrder,
filterKey, filterValue){
/* Objects have been selected in a popup, to be linked via a Ref with
link='popup'. Get them. */
@ -1042,12 +1044,21 @@ function onSelectObjects(nodeId, objectUrl, sortKey, sortOrder,
}
// Close the popup.
closePopup('iframePopup');
/* Refresh the Ref edit widget to include the linked objects. All those
parameters are needed to replay the query in the popup. */
askField(':'+nodeId, objectUrl, 'edit', null, null, null, null, null,
{'selected': uids, 'semantics': semantics, 'sortKey': sortKey,
'sortOrder': sortOrder, 'filterKey': filterKey,
'filterValue': filterValue});
/* When refreshing the Ref field we will need to pass all those parameters,
for replaying the popup query. */
var params = {'selected': uids, 'semantics': semantics, 'sortKey': sortKey,
'sortOrder': sortOrder, 'filterKey': filterKey,
'filterValue': filterValue};
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);
}
else {
// Link the selected objects and refresh the Ref view widget.
params['action'] = 'onSelectFromPopup';
askField(':'+nodeId,objectUrl,'view',null,null,null,null,null,params);
}
}
function onSelectObject(tdId, nodeId, objectUrl) {

View file

@ -417,9 +417,10 @@ class ToolWrapper(AbstractWrapper):
<input type="button" class="button"
var="label=_('object_link_many')"
value=":label"
onclick=":'onSelectObjects(%s,%s,%s,%s,%s,%s)' % (q(rootHookId), \
q(uiSearch.initiator.url),q(sortKey),q(sortOrder), \
q(filterKey), q(filterValue))"
onclick=":'onSelectObjects(%s,%s,%s,%s,%s,%s,%s)' % \
(q(rootHookId), q(uiSearch.initiator.url), \
q(uiSearch.initiatorMode), q(sortKey), q(sortOrder), \
q(filterKey), q(filterValue))"
style=":'%s; %s' % (url('linkMany', bg=True), \
ztool.getButtonWidth(label))"/>
</div>
@ -450,8 +451,8 @@ class ToolWrapper(AbstractWrapper):
_=ztool.translate;
className=req['className'];
searchName=req.get('search', '');
rootHookId=rootHookId|searchName.replace(':', '_');
uiSearch=uiSearch|ztool.getSearch(className,searchName,ui=True);
rootHookId=uiSearch.getRootHookId();
refInfo=ztool.getRefInfo();
refObject=refInfo[0];
refField=refInfo[1];
@ -537,7 +538,7 @@ class ToolWrapper(AbstractWrapper):
<div var="className=req['className'];
searchName=req.get('search', '');
uiSearch=ztool.getSearch(className, searchName, ui=True);
rootHookId=searchName.replace(':', '_');
rootHookId=uiSearch.getRootHookId();
cssJs=None"
id=":rootHookId">
<script type="text/javascript">:uiSearch.search.getCbJsInit(rootHookId)