[gen] Replaced old-style JS calls to 'askAjaxChunk' to calls to 'askAjax'.

This commit is contained in:
Gaetan Delannay 2015-02-13 17:29:51 +01:00
parent 7c58582b9a
commit f842c0ce02
8 changed files with 141 additions and 154 deletions

View file

@ -114,8 +114,7 @@ class Field:
</x> </x>
<!-- Any other field --> <!-- Any other field -->
<x if="(refField.name != 'title') and mayView"> <x if="(refField.name != 'title') and mayView">
<x var="zobj=tied.o; obj=tied; layoutType='cell'; <x var="zobj=tied.o; obj=tied; layoutType='cell'; field=refField"
innerRef=True; field=refField"
if="field.isShowable(zobj, 'result')">:field.pxRender</x> if="field.isShowable(zobj, 'result')">:field.pxRender</x>
</x>''') </x>''')
@ -173,7 +172,7 @@ class Field:
</x> </x>
<!-- Any other field --> <!-- Any other field -->
<x if="(field.name != 'title') and mayView"> <x if="(field.name != 'title') and mayView">
<x var="layoutType='cell'; innerRef=True" <x var="layoutType='cell'"
if="field.isShowable(zobj, 'result')">:field.pxRender</x> if="field.isShowable(zobj, 'result')">:field.pxRender</x>
</x>''') </x>''')

View file

@ -92,10 +92,10 @@ class Pod(Field):
onmouseout=":'toggleDropdown(%s,%s)' % (q(dropdownId), q('none'))"> onmouseout=":'toggleDropdown(%s,%s)' % (q(dropdownId), q('none'))">
<x>:field.pxIcon</x> <x>:field.pxIcon</x>
<!-- The dropdown menu containing freeze actions --> <!-- The dropdown menu containing freeze actions -->
<table id=":dropdownId" class="dropdown" width="100px"> <table id=":dropdownId" class="dropdown" width="110px">
<!-- Unfreeze --> <!-- Unfreeze -->
<tr if="freezeAllowed and frozen" valign="top"> <tr if="freezeAllowed and frozen" valign="top">
<td width="85px"> <td width="95px">
<a onclick=":'freezePod(%s,%s,%s,%s,%s)' % (q(uid), q(name), \ <a onclick=":'freezePod(%s,%s,%s,%s,%s)' % (q(uid), q(name), \
q(info.template), q(fmt), q('unfreeze'))" q(info.template), q(fmt), q('unfreeze'))"
class="smaller">:_('unfreezeField')</a> class="smaller">:_('unfreezeField')</a>

View file

@ -83,26 +83,27 @@ class Ref(Field):
style=":'display:%s' % field.showActions" var2="layoutType='buttons'"> style=":'display:%s' % field.showActions" var2="layoutType='buttons'">
<!-- Arrows for moving objects up or down --> <!-- Arrows for moving objects up or down -->
<x if="(totalNumber &gt;1) and changeOrder and not inPickList \ <x if="(totalNumber &gt;1) and changeOrder and not inPickList \
and not inMenu" and not inMenu">
var2="ajaxBaseCall=navBaseCall.replace('**v**','%s,%s,{%s:%s,%s:%s}'%\
(q(startNumber), q('doChangeOrder'), q('refObjectUid'),
q(tiedUid), q('move'), q('**v**')))">
<!-- Move to top --> <!-- Move to top -->
<img if="objectIndex &gt; 1" class="clickable" <img if="objectIndex &gt; 1" class="clickable"
src=":url('arrowsUp')" title=":_('move_top')" src=":url('arrowsUp')" title=":_('move_top')"
onclick=":ajaxBaseCall.replace('**v**', 'top')"/> onclick=":'askBunchMove(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(tiedUid), q('top'))"/>
<!-- Move to bottom --> <!-- Move to bottom -->
<img if="objectIndex &lt; (totalNumber-2)" class="clickable" <img if="objectIndex &lt; (totalNumber-2)" class="clickable"
src=":url('arrowsDown')" title=":_('move_bottom')" src=":url('arrowsDown')" title=":_('move_bottom')"
onclick=":ajaxBaseCall.replace('**v**', 'bottom')"/> onclick=":'askBunchMove(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(tiedUid), q('bottom'))"/>
<!-- Move up --> <!-- Move up -->
<img if="objectIndex &gt; 0" class="clickable" src=":url('arrowUp')" <img if="objectIndex &gt; 0" class="clickable" src=":url('arrowUp')"
title=":_('move_up')" title=":_('move_up')"
onclick=":ajaxBaseCall.replace('**v**', 'up')"/> onclick=":'askBunchMove(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(tiedUid), q('up'))"/>
<!-- Move down --> <!-- Move down -->
<img if="objectIndex &lt; (totalNumber-1)" class="clickable" <img if="objectIndex &lt; (totalNumber-1)" class="clickable"
src=":url('arrowDown')" title=":_('move_down')" src=":url('arrowDown')" title=":_('move_down')"
onclick=":ajaxBaseCall.replace('**v**', 'down')"/> onclick=":'askBunchMove(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(tiedUid), q('down'))"/>
</x> </x>
<!-- Edit --> <!-- Edit -->
<a if="not field.noForm and tied.o.mayEdit()" <a if="not field.noForm and tied.o.mayEdit()"
@ -167,7 +168,7 @@ class Ref(Field):
css=ztool.getButtonCss(label)" class=":css" css=ztool.getButtonCss(label)" class=":css"
value=":label" style=":url('add', bg=True)" title=":addLabel" value=":label" style=":url('add', bg=True)" title=":addLabel"
onclick=":field.getOnAdd(q, formName, addConfirmMsg, target, \ onclick=":field.getOnAdd(q, formName, addConfirmMsg, target, \
navBaseCall, startNumber)"/> ajaxHookId, startNumber)"/>
</form>''') </form>''')
# Displays the button allowing to select from a popup objects to be linked # Displays the button allowing to select from a popup objects to be linked
@ -192,16 +193,15 @@ class Ref(Field):
# ref field according to the field that corresponds to this column. # ref field according to the field that corresponds to this column.
pxSortIcons = Px(''' pxSortIcons = Px('''
<x if="changeOrder and (len(objects) &gt; 1) and \ <x if="changeOrder and (len(objects) &gt; 1) and \
refField.isSortable(usage='ref')" refField.isSortable(usage='ref')">
var2="ajaxBaseCall=navBaseCall.replace('**v**', '%s,%s,{%s:%s,%s:%s}'% \
(q(startNumber), q('sort'), q('sortKey'), q(refField.name), \
q('reverse'), q('**v**')))">
<img class="clickable" src=":url('sortAsc')" <img class="clickable" src=":url('sortAsc')"
var="js=ajaxBaseCall.replace('**v**', 'False')" var="js='askBunchSortRef(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(refField.name), q('False'))"
onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \ onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \
q(sortConfirm))"/> q(sortConfirm))"/>
<img class="clickable" src=":url('sortDesc')" <img class="clickable" src=":url('sortDesc')"
var="js=ajaxBaseCall.replace('**v**', 'True')" var="js='askBunchSortRef(%s, %s, %s, %s)' % \
(q(ajaxHookId), q(startNumber), q(refField.name), q('True'))"
onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \ onclick=":'askConfirm(%s,%s,%s)' % (q('script'), q(js,False), \
q(sortConfirm))"/> q(sortConfirm))"/>
</x>''') </x>''')
@ -223,16 +223,16 @@ class Ref(Field):
<div id=":dropdownId" class="dropdown"> <div id=":dropdownId" class="dropdown">
<img class="clickable" src=":url('move')" id=":imgId" <img class="clickable" src=":url('move')" id=":imgId"
title=":_('move_number')" title=":_('move_number')"
onclick=":navBaseCall.replace('**v**','%s,%s,{%s:%s,%s:this}' % \ onclick=":'askBunchMove(%s, %s, %s, this)' % \
(q(startNumber), q('doChangeOrder'), q('refObjectUid'), (q(ajaxHookId), q(startNumber), q(tiedUid))"/>
q(tiedUid), q('move')))"/>
</div> </div>
</div>''') </div>''')
# PX that displays referred objects as a list # PX that displays referred objects as a list
pxViewList = Px(''' pxViewList = Px('''
<div id=":ajaxHookId"> <div id=":ajaxHookId">
<div if="not innerRef or mayAdd or mayLink" style="margin-bottom: 4px"> <div if="(layoutType == 'view') or mayAdd or mayLink"
style="margin-bottom: 4px">
<x if="field.collapsible and objects">:collapse.px</x> <x if="field.collapsible and objects">:collapse.px</x>
<span if="subLabel" class="discreet">:_(subLabel)</span> <span if="subLabel" class="discreet">:_(subLabel)</span>
(<span class="discreet">:totalNumber</span>) (<span class="discreet">:totalNumber</span>)
@ -253,13 +253,11 @@ class Ref(Field):
<x>:tool.pxNavigate</x> <x>:tool.pxNavigate</x>
<!-- No object is present --> <!-- No object is present -->
<p class="discreet" <p class="discreet" if="not objects and mayAdd">:_('no_ref')</p>
if="not objects and (innerRef and mayAdd)">:_('no_ref')</p>
<!-- Linked objects --> <!-- Linked objects -->
<table if="objects" id=":collapse.id" style=":collapse.style" <table if="objects" id=":collapse.id" style=":collapse.style" class="list"
class=":not innerRef and 'list' or ''" width=":field.layouts['view'].width"
width=":innerRef and '100%' or field.layouts['view'].width"
var2="columns=ztool.getColumnsSpecifiers(tiedClassName, \ var2="columns=ztool.getColumnsSpecifiers(tiedClassName, \
field.getAttribute(obj, 'shownInfo'), dir); field.getAttribute(obj, 'shownInfo'), dir);
currentNumber=0"> currentNumber=0">
@ -267,7 +265,7 @@ class Ref(Field):
checkboxes=checkboxes, startNumber=startNumber, \ checkboxes=checkboxes, startNumber=startNumber, \
totalNumber=totalNumber, sourceId=zobj.id, \ totalNumber=totalNumber, sourceId=zobj.id, \
refFieldName=field.name, inPickList=inPickList, \ refFieldName=field.name, inPickList=inPickList, \
numbered=numbered, navBaseCall=navBaseCall)</script> numbered=numbered)</script>
<tr if="field.showHeaders"> <tr if="field.showHeaders">
<th if="not inPickList and numbered" width=":numbered"></th> <th if="not inPickList and numbered" width=":numbered"></th>
@ -300,8 +298,7 @@ class Ref(Field):
# PX that displays the list of objects the user may select to insert into a # PX that displays the list of objects the user may select to insert into a
# ref field with link="list". # ref field with link="list".
pxViewPickList = Px(''' pxViewPickList = Px('''
<x var="innerRef=False; <x var="ajaxHookId=ajaxHookId|'%s_%s_poss' % (zobj.id, field.name);
ajaxHookId=ajaxHookId|'%s_%s_poss' % (zobj.id, field.name);
layoutType='view'; layoutType='view';
inMenu=False; inMenu=False;
inPickList=True; inPickList=True;
@ -321,8 +318,6 @@ class Ref(Field):
mayAdd=False; mayAdd=False;
mayLink=False; mayLink=False;
mayUnlink=False; mayUnlink=False;
navBaseCall='askRefField(%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(zobj.absolute_url()), q(innerRef));
changeOrder=False; changeOrder=False;
changeNumber=False; changeNumber=False;
numbered=False; numbered=False;
@ -396,8 +391,7 @@ class Ref(Field):
# if, in the request, key "scope" is present and holds value "objs", the # if, in the request, key "scope" is present and holds value "objs", the
# pick list (containing possible values) will not be rendered. # pick list (containing possible values) will not be rendered.
pxView = Px(''' pxView = Px('''
<x var="innerRef=req.get('innerRef', False) == 'True'; <x var="ajaxHookId='%s_%s_objs' % (zobj.id, field.name);
ajaxHookId='%s_%s_objs' % (zobj.id, field.name);
layoutType=layoutType|'view'; layoutType=layoutType|'view';
render=field.getRenderMode(layoutType); render=field.getRenderMode(layoutType);
linkList=field.link == 'list'; linkList=field.link == 'list';
@ -423,8 +417,6 @@ class Ref(Field):
mayUnlink=mayEdit and field.getAttribute(zobj, 'unlink'); mayUnlink=mayEdit and field.getAttribute(zobj, 'unlink');
addConfirmMsg=field.addConfirm and \ addConfirmMsg=field.addConfirm and \
_('%s_addConfirm' % field.labelId) or ''; _('%s_addConfirm' % field.labelId) or '';
navBaseCall='askRefField(%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(zobj.absolute_url()), q(innerRef));
changeOrder=mayEdit and field.getAttribute(zobj, 'changeOrder'); changeOrder=mayEdit and field.getAttribute(zobj, 'changeOrder');
sortConfirm=changeOrder and _('sort_confirm'); sortConfirm=changeOrder and _('sort_confirm');
numbered=field.isNumbered(zobj); numbered=field.isNumbered(zobj);
@ -960,7 +952,7 @@ class Ref(Field):
return res return res
return tied.o.getUrl(nav=''), '_self' return tied.o.getUrl(nav=''), '_self'
def getStartNumber(self, render, req, ajaxHookId): def getStartNumber(self, render, req, hookId):
'''This method returns the index of the first linked object that must be '''This method returns the index of the first linked object that must be
shown, or None if all linked objects must be shown at once (it shown, or None if all linked objects must be shown at once (it
happens when p_render is "menus").''' happens when p_render is "menus").'''
@ -968,7 +960,9 @@ class Ref(Field):
if render == 'menus': return if render == 'menus': return
# When using 'list' (=default) render mode, the index of the first # When using 'list' (=default) render mode, the index of the first
# object to show is in the request. # object to show is in the request.
return int(req.get('%s_startNumber' % ajaxHookId, 0)) key = '%s_startNumber' % hookId
nb = req.has_key(key) and req[key] or req.get('startNumber', 0)
return int(nb)
def getFormattedValue(self, obj, value, showChanges=False, language=None): def getFormattedValue(self, obj, value, showChanges=False, language=None):
return value return value
@ -1197,14 +1191,13 @@ class Ref(Field):
obj.raiseUnauthorized("User can't write Ref field '%s' (%s)." % \ obj.raiseUnauthorized("User can't write Ref field '%s' (%s)." % \
(self.name, may.msg)) (self.name, may.msg))
def getOnAdd(self, q, formName, addConfirmMsg, target, navBaseCall, def getOnAdd(self, q, formName, addConfirmMsg, target, hookId, startNumber):
startNumber):
'''Computes the JS code to execute when button "add" is clicked.''' '''Computes the JS code to execute when button "add" is clicked.'''
if self.noForm: if self.noForm:
# Ajax-refresh the Ref with a special param to link a newly created # Ajax-refresh the Ref with a special param to link a newly created
# object. # object.
res = navBaseCall.replace('**v**', res = "askAjax('%s', null, {'startNumber':'%d', " \
"%d,'doCreateWithoutForm'" % startNumber) "'action':'doCreateWithoutForm'})" % (hookId, startNumber)
if self.addConfirm: if self.addConfirm:
res = "askConfirm('script', %s, %s)" % \ res = "askConfirm('script', %s, %s)" % \
(q(res, False), q(addConfirmMsg)) (q(res, False), q(addConfirmMsg))
@ -1273,9 +1266,10 @@ class Ref(Field):
p_hook = the whole search result.''' p_hook = the whole search result.'''
# Complete params with default parameters # Complete params with default parameters
params['ajaxHookId'] = hook; params['ajaxHookId'] = hook;
params = sutils.getStringDict(params) params['scope'] = hook.rsplit('_', 1)[-1]
px = hook.endswith('_poss') and 'pxViewPickList' or 'pxView' px = (params['scope'] == 'poss') and 'pxViewPickList' or 'pxView'
px = '%s:%s' % (self.name, px) px = '%s:%s' % (self.name, px)
params = sutils.getStringDict(params)
return "getAjaxHook('%s',true)['ajax']=new AjaxData('%s', " \ return "getAjaxHook('%s',true)['ajax']=new AjaxData('%s', " \
"'%s', %s, null, '%s')" % \ "'%s', %s, null, '%s')" % \
(hook, hook, px, params, zobj.absolute_url()) (hook, hook, px, params, zobj.absolute_url())

View file

@ -24,6 +24,7 @@ from group import Group
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class Search: class Search:
'''Used for specifying a search for a given class.''' '''Used for specifying a search for a given class.'''
def __init__(self, name=None, group=None, sortBy='', sortOrder='asc', def __init__(self, name=None, group=None, sortBy='', sortOrder='asc',
maxPerPage=30, default=False, colspan=1, translated=None, maxPerPage=30, default=False, colspan=1, translated=None,
show=True, showActions=True, translatedDescr=None, show=True, showActions=True, translatedDescr=None,
@ -158,6 +159,10 @@ class Search:
class UiSearch: class UiSearch:
'''Instances of this class are generated on-the-fly for manipulating a '''Instances of this class are generated on-the-fly for manipulating a
Search from the User Interface.''' Search from the User Interface.'''
# Default values for request parameters defining query sort and filter
sortFilterDefaults = {'sortKey': '', 'sortOrder': 'asc',
'filterKey': '', 'filterValue': ''}
# Rendering a search # Rendering a search
pxView = Px(''' pxView = Px('''
<div class="portletSearch"> <div class="portletSearch">
@ -240,8 +245,8 @@ class UiSearch:
# Render search results # Render search results
pxResult = Px(''' pxResult = Px('''
<div var="ajaxHookId='queryResult'; <div var="ajaxHookId='queryResult';
className=req['className']; className=className|req['className'];
searchName=req.get('search', ''); searchName=field.name|req.get('search', '');
uiSearch=field|ztool.getSearch(className, searchName, ui=True); uiSearch=field|ztool.getSearch(className, searchName, ui=True);
rootHookId=uiSearch.getRootHookId(); rootHookId=uiSearch.getRootHookId();
refInfo=ztool.getRefInfo(); refInfo=ztool.getRefInfo();
@ -264,9 +269,6 @@ class UiSearch:
totalNumber=queryResult.totalNumber; totalNumber=queryResult.totalNumber;
batchSize=queryResult.batchSize; batchSize=queryResult.batchSize;
batchNumber=len(zobjects); batchNumber=len(zobjects);
navBaseCall='askQueryResult(%s,%s,%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(ztool.absolute_url()), q(className), \
q(searchName),int(inPopup));
showNewSearch=showNewSearch|True; showNewSearch=showNewSearch|True;
newSearchUrl='%s/search?className=%s%s' % \ newSearchUrl='%s/search?className=%s%s' % \
(ztool.absolute_url(), className, refUrlPart); (ztool.absolute_url(), className, refUrlPart);
@ -302,7 +304,7 @@ class UiSearch:
<span class="discreet">:uiSearch.translatedDescr</span><br/> <span class="discreet">:uiSearch.translatedDescr</span><br/>
</td> </td>
<!-- (Top) navigation --> <!-- (Top) navigation -->
<td align=":dright" width="150px">:tool.pxNavigate</td> <td align=":dright" width="200px">:tool.pxNavigate</td>
</tr> </tr>
</table> </table>
@ -397,13 +399,20 @@ class UiSearch:
def getAjaxData(self, hook, ztool, **params): def getAjaxData(self, hook, ztool, **params):
'''Initializes an AjaxData object on the DOM node corresponding to '''Initializes an AjaxData object on the DOM node corresponding to
p_hook = the whole search result.''' p_hook = the whole search result.'''
# Complete params with default parameters # Complete params with default ones and optional filter/sort params. For
# performing a complete Ajax request, "className" and "searcName" are
# not needed because included in the PX name. But they are requested by
# sub-Ajax queries at the row level.
params['className'] = self.className params['className'] = self.className
params['searchName'] = self.name params['searchName'] = self.name
req = ztool.REQUEST
for param, default in UiSearch.sortFilterDefaults.iteritems():
params[param] = req.get(param, default)
# Convert params into a JS dict
params = sutils.getStringDict(params) params = sutils.getStringDict(params)
return "getAjaxHook('%s',true)['ajax']=new AjaxData('%s', " \ px = '%s:%s:pxResult' % (self.className, self.name)
"'pxResult', %s, null, '%s')" % \ return "getAjaxHook('%s',true)['ajax']=new AjaxData('%s', '%s', %s, " \
(hook, hook, params, ztool.absolute_url()) "null, '%s')" % (hook, hook, px, params, ztool.absolute_url())
def getAjaxDataRow(self, zobj, parentHook, **params): def getAjaxDataRow(self, zobj, parentHook, **params):
'''Initializes an AjaxData object on the DOM node corresponding to '''Initializes an AjaxData object on the DOM node corresponding to

View file

@ -1247,7 +1247,15 @@ class BaseMixin:
def getHistoryCollapse(self): def getHistoryCollapse(self):
'''Gets a Collapsible instance for showing a collapse or expanded '''Gets a Collapsible instance for showing a collapse or expanded
history in this object.''' history in this object.'''
return Collapsible('appyHistory', self.REQUEST) return Collapsible('objectHistory', self.REQUEST)
def getHistoryAjaxData(self, hook, startNumber, batchSize):
'''Gets data allowing to ajax-ask paginated history data.'''
params = {'startNumber': startNumber, 'maxPerPage': batchSize}
# Convert params into a JS dict
params = sutils.getStringDict(params)
return "getAjaxHook('%s',true)['ajax']=new AjaxData('%s','pxHistory', "\
"%s, null, '%s')" % (hook, hook, params, self.absolute_url())
def mayNavigate(self): def mayNavigate(self):
'''May the currently logged user see the navigation panel linked to '''May the currently logged user see the navigation panel linked to

View file

@ -118,25 +118,6 @@ function injectChunk(elem, content, inner, searchTop){
return res; return res;
} }
function clickOn(node) {
// If node is a form, disable all form buttons
if (node.tagName == 'FORM') {
var i = node.elements.length -1;
while (i >= 0) {
if (node.elements[i].type == 'button') { clickOn(node.elements[i]); }
i = i - 1;
}
return;
}
// Disable any click on p_node to be protected against double-click
var cn = (node.className)? 'unclickable ' + node.className : 'unclickable';
node.className = cn;
/* For a button, show the preloader directly. For a link, show it only after
a while, if the target page is still not there. */
if (node.tagName != 'A') injectChunk(node, loadingButton);
else setTimeout(function(){injectChunk(node, loadingLink)}, 700);
}
function getAjaxHook(hookId, forceTop) { function getAjaxHook(hookId, forceTop) {
/* Gets the XHTML element whose ID is p_hookId: it will be the placeholder /* Gets the XHTML element whose ID is p_hookId: it will be the placeholder
for the result of an ajax request. If p_hookId starts with ':', we search for the result of an ajax request. If p_hookId starts with ':', we search
@ -309,61 +290,62 @@ function askAjax(hook, form, params) {
evalInnerScripts); evalInnerScripts);
} }
/* The functions below wrap askAjaxChunk for getting specific content through function askBunch(hookId, startNumber) {
an Ajax request. */ askAjax(hookId, null, {'startNumber': startNumber})}
function askQueryResult(hookId, objectUrl, className, searchName, popup,
startNumber, sortKey, sortOrder, filterKey) { function askBunchSorted(hookId, sortKey, sortOrder) {
// Sends an Ajax request for getting the result of a query var data = {'startNumber': '0', 'sortKey': sortKey, 'sortOrder': sortOrder};
var params = {'className': className, 'search': searchName, askAjax(hookId, null, data);
'startNumber': startNumber, 'popup': popup}; }
if (sortKey) params['sortKey'] = sortKey;
if (sortOrder) params['sortOrder'] = sortOrder; function askBunchFiltered(hookId, filterKey) {
if (filterKey) { var data = {'startNumber': '0', 'filterKey': filterKey, 'filterValue': ''};
var filterWidget = document.getElementById(hookId + '_' + filterKey); var node = document.getElementById(hookId + '_' + filterKey);
if (filterWidget && filterWidget.value) { if (node.value) data['filterValue'] = encodeURIComponent(node.value);
params['filterKey'] = filterKey; askAjax(hookId, null, data);
params['filterValue'] = encodeURIComponent(filterWidget.value); }
function askBunchMove(hookId, startNumber, uid, move){
var moveTo = move;
if (typeof move == 'object'){
// Get the new index from an input field
var id = move.id;
id = id.substr(0, id.length-4);
var input = document.getElementById(id);
if (isNaN(input.value)) {
input.style.background = wrongTextInput;
return;
} }
moveTo = 'index_' + input.value;
} }
var px = className + ':' + searchName + ':' + 'pxResult'; var data = {'startNumber': startNumber, 'action': 'doChangeOrder',
askAjaxChunk(hookId, 'GET', objectUrl, px, params, null, evalInnerScripts); 'refObjectUid': uid, 'move': moveTo};
askAjax(hookId, null, data);
} }
function askObjectHistory(hookId, objectUrl, maxPerPage, startNumber) { function askBunchSortRef(hookId, startNumber, sortKey, reverse) {
// Sends an Ajax request for getting the history of an object var data = {'startNumber': startNumber, 'action': 'sort', 'sortKey': sortKey,
var params = {'maxPerPage': maxPerPage, 'startNumber': startNumber}; 'reverse': reverse};
askAjaxChunk(hookId, 'GET', objectUrl, 'pxHistory', params); askAjax(hookId, null, data);
} }
function askRefField(hookId, objectUrl, innerRef, startNumber, action, function clickOn(node) {
actionParams){ // If node is a form, disable all form buttons
var hookElems = hookId.split('_'); if (node.tagName == 'FORM') {
var fieldName = hookElems[1]; var i = node.elements.length -1;
// Sends an Ajax request for getting the content of a reference field while (i >= 0) {
var startKey = hookId + '_startNumber'; if (node.elements[i].type == 'button') { clickOn(node.elements[i]); }
var scope = hookElems.pop(); i = i - 1;
var params = {'innerRef': innerRef, 'scope': scope}; }
params[startKey] = startNumber; return;
if (action) params['action'] = action;
if (actionParams) {
for (var key in actionParams) {
if ((key == 'move') && (typeof actionParams[key] == 'object')) {
// Get the new index from an input field
var id = actionParams[key].id;
id = id.substr(0, id.length-4);
var input = document.getElementById(id);
if (isNaN(input.value)) {
input.style.background = wrongTextInput;
return;
}
params[key] = 'index_' + input.value;
}
else params[key] = actionParams[key];
};
} }
var px = (scope == 'objs')? ':pxView': ':pxViewPickList'; // Disable any click on p_node to be protected against double-click
askAjaxChunk(hookId, 'GET', objectUrl, fieldName + px, params, null, var cn = (node.className)? 'unclickable ' + node.className : 'unclickable';
evalInnerScripts); node.className = cn;
/* For a button, show the preloader directly. For a link, show it only after
a while, if the target page is still not there. */
if (node.tagName != 'A') injectChunk(node, loadingButton);
else setTimeout(function(){injectChunk(node, loadingLink)}, 700);
} }
function gotoTied(objectUrl, field, numberWidget, total) { function gotoTied(objectUrl, field, numberWidget, total) {
@ -381,7 +363,7 @@ function gotoTied(objectUrl, field, numberWidget, total) {
function askField(hookId, objectUrl, layoutType, customParams, showChanges, function askField(hookId, objectUrl, layoutType, customParams, showChanges,
masterValues, requestValue, error, className){ 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};
if (customParams){for (var key in customParams) params[key]=customParams[key]} if (customParams){for (var key in customParams) params[key]=customParams[key]}
@ -833,10 +815,10 @@ function generatePod(node, uid, fieldName, template, podFormat, queryData,
f.checkedSem.value = ''; f.checkedSem.value = '';
if (getChecked) { if (getChecked) {
// We must collect selected objects from a Ref field // We must collect selected objects from a Ref field
var node = document.getElementById(uid + '_' + getChecked); var cNode = document.getElementById(uid + '_' + getChecked);
if (node && node.hasOwnProperty('_appy_objs_cbs')) { if (cNode && cNode.hasOwnProperty('_appy_objs_cbs')) {
f.checkedUids.value = stringFromDictKeys(node['_appy_objs_cbs']); f.checkedUids.value = stringFromDictKeys(cNode['_appy_objs_cbs']);
f.checkedSem.value = node['_appy_objs_sem']; f.checkedSem.value = cNode['_appy_objs_sem'];
} }
} }
// Submitting the form at the end blocks the animated gifs on FF // Submitting the form at the end blocks the animated gifs on FF

View file

@ -24,12 +24,12 @@ class ToolWrapper(AbstractWrapper):
pxSortAndFilter = Px(''' pxSortAndFilter = Px('''
<x if="sortable"> <x if="sortable">
<img if="(sortKey != field.name) or (sortOrder == 'desc')" <img if="(sortKey != field.name) or (sortOrder == 'desc')"
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \ onclick=":'askBunchSorted(%s, %s, %s)' % \
(q(field.name), q('asc'), q(filterKey)))" (q(ajaxHookId), q(field.name), q('asc'))"
src=":url('sortDown.gif')" class="clickable"/> src=":url('sortDown.gif')" class="clickable"/>
<img if="(sortKey != field.name) or (sortOrder == 'asc')" <img if="(sortKey != field.name) or (sortOrder == 'asc')"
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \ onclick=":'askBunchSorted(%s, %s, %s)' % \
(q(field.name), q('desc'), q(filterKey)))" (q(ajaxHookId), q(field.name), q('desc'))"
src=":url('sortUp.gif')" class="clickable"/> src=":url('sortUp.gif')" class="clickable"/>
</x> </x>
<x if="filterable" <x if="filterable"
@ -41,27 +41,23 @@ class ToolWrapper(AbstractWrapper):
onkeydown=":'if (event.keyCode==13) document.getElementById ' \ onkeydown=":'if (event.keyCode==13) document.getElementById ' \
'(%s).click()' % q(filterIdIcon)"/> '(%s).click()' % q(filterIdIcon)"/>
<img id=":filterIdIcon" class="clickable" src=":url('funnel')" <img id=":filterIdIcon" class="clickable" src=":url('funnel')"
onclick=":navBaseCall.replace('**v**', '0, %s,%s,%s' % \ onclick=":'askBunchFiltered(%s, %s)' % \
(q(sortKey), q(sortOrder), q(field.name)))"/> (q(ajaxHookId), q(field.name))"/>
</x>''') </x>''')
# Buttons for navigating among a list of objects (from a Ref field or a # Buttons for navigating among a list of objects (from a Ref field or a
# query): next,back,first,last... # query): next,back,first,last...
pxNavigate = Px(''' pxNavigate = Px('''
<div if="totalNumber &gt; batchSize" align=":dright" <div if="totalNumber &gt; batchSize" align=":dright">
var2="mustSortAndFilter=ajaxHookId == 'queryResult';
sortAndFilter=mustSortAndFilter and \
',%s,%s,%s' % (q(sortKey),q(sortOrder),q(filterKey)) or ''">
<!-- Go to the first page --> <!-- Go to the first page -->
<img if="(startNumber != 0) and (startNumber != batchSize)" <img if="(startNumber != 0) and (startNumber != batchSize)"
class="clickable" src=":url('arrowsLeft')" title=":_('goto_first')" class="clickable" src=":url('arrowsLeft')" title=":_('goto_first')"
onClick=":navBaseCall.replace('**v**', '0'+sortAndFilter)"/> onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q('0'))"/>
<!-- Go to the previous page --> <!-- Go to the previous page -->
<img var="sNumber=startNumber - batchSize" if="startNumber != 0" <img var="sNumber=startNumber - batchSize" if="startNumber != 0"
class="clickable" src=":url('arrowLeft')" title=":_('goto_previous')" class="clickable" src=":url('arrowLeft')" title=":_('goto_previous')"
onClick=":navBaseCall.replace('**v**', str(sNumber)+sortAndFilter)"/> onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
<!-- Explain which elements are currently shown --> <!-- Explain which elements are currently shown -->
<span class="discreet"> <span class="discreet">
@ -73,7 +69,7 @@ class ToolWrapper(AbstractWrapper):
<!-- Go to the next page --> <!-- Go to the next page -->
<img var="sNumber=startNumber + batchSize" if="sNumber &lt; totalNumber" <img var="sNumber=startNumber + batchSize" if="sNumber &lt; totalNumber"
class="clickable" src=":url('arrowRight')" title=":_('goto_next')" class="clickable" src=":url('arrowRight')" title=":_('goto_next')"
onClick=":navBaseCall.replace('**v**', str(sNumber)+sortAndFilter)"/> onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
<!-- Go to the last page --> <!-- Go to the last page -->
<img var="lastPageIsIncomplete=totalNumber % batchSize; <img var="lastPageIsIncomplete=totalNumber % batchSize;
@ -84,7 +80,7 @@ class ToolWrapper(AbstractWrapper):
if="(startNumber != sNumber) and \ if="(startNumber != sNumber) and \
(startNumber != sNumber-batchSize)" class="clickable" (startNumber != sNumber-batchSize)" class="clickable"
src=":url('arrowsRight')" title=":_('goto_last')" src=":url('arrowsRight')" title=":_('goto_last')"
onClick=":navBaseCall.replace('**v**', str(sNumber)+sortAndFilter)"/> onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
<!-- Go to the element number... --> <!-- Go to the element number... -->
<x var="gotoNumber=gotoNumber|False" if="gotoNumber" <x var="gotoNumber=gotoNumber|False" if="gotoNumber"

View file

@ -53,7 +53,7 @@ class AbstractWrapper(object):
<!-- Object navigation --> <!-- Object navigation -->
<td var="nav=req.get('nav', None)" if="nav" <td var="nav=req.get('nav', None)" if="nav"
var2="self=ztool.getNavigationInfo(nav, inPopup)" align=":dright" var2="self=ztool.getNavigationInfo(nav, inPopup)" align=":dright"
width="150px">:self.pxNavigate</td> width="200px">:self.pxNavigate</td>
</tr> </tr>
</table> </table>
<!-- Object phases and pages --> <!-- Object phases and pages -->
@ -303,18 +303,17 @@ class AbstractWrapper(object):
# This PX displays an object's history # This PX displays an object's history
pxHistory = Px(''' pxHistory = Px('''
<div id="appyHistory" <div var="startNumber=int(req.get('startNumber', 0));
var="startNumber=int(req.get('startNumber', 0));
batchSize=int(req.get('maxPerPage', 5)); batchSize=int(req.get('maxPerPage', 5));
historyInfo=zobj.getHistory(startNumber, batchSize=batchSize)" historyInfo=zobj.getHistory(startNumber, batchSize=batchSize)"
if="historyInfo.events" if="historyInfo.events"
var2="objs=historyInfo.events; var2="ajaxHookId='appyHistory';
objs=historyInfo.events;
totalNumber=historyInfo.totalNumber; totalNumber=historyInfo.totalNumber;
batchNumber=len(objs); batchNumber=len(objs)"
ajaxHookId='appyHistory'; id=":ajaxHookId">
navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \ <script>:zobj.getHistoryAjaxData(ajaxHookId, startNumber, \
(q(ajaxHookId), q(zobj.absolute_url()), batchSize)"> batchSize)</script>
<!-- Navigate between history pages --> <!-- Navigate between history pages -->
<x>:tool.pxNavigate</x> <x>:tool.pxNavigate</x>
<!-- History --> <!-- History -->