[gen] Replaced old-style JS calls to 'askAjaxChunk' to calls to 'askAjax'.
This commit is contained in:
parent
7c58582b9a
commit
f842c0ce02
8 changed files with 141 additions and 154 deletions
gen
|
@ -1247,7 +1247,15 @@ class BaseMixin:
|
|||
def getHistoryCollapse(self):
|
||||
'''Gets a Collapsible instance for showing a collapse or expanded
|
||||
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):
|
||||
'''May the currently logged user see the navigation panel linked to
|
||||
|
|
126
gen/ui/appy.js
126
gen/ui/appy.js
|
@ -118,25 +118,6 @@ function injectChunk(elem, content, inner, searchTop){
|
|||
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) {
|
||||
/* 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
|
||||
|
@ -309,61 +290,62 @@ function askAjax(hook, form, params) {
|
|||
evalInnerScripts);
|
||||
}
|
||||
|
||||
/* The functions below wrap askAjaxChunk for getting specific content through
|
||||
an Ajax request. */
|
||||
function askQueryResult(hookId, objectUrl, className, searchName, popup,
|
||||
startNumber, sortKey, sortOrder, filterKey) {
|
||||
// Sends an Ajax request for getting the result of a query
|
||||
var params = {'className': className, 'search': searchName,
|
||||
'startNumber': startNumber, 'popup': popup};
|
||||
if (sortKey) params['sortKey'] = sortKey;
|
||||
if (sortOrder) params['sortOrder'] = sortOrder;
|
||||
if (filterKey) {
|
||||
var filterWidget = document.getElementById(hookId + '_' + filterKey);
|
||||
if (filterWidget && filterWidget.value) {
|
||||
params['filterKey'] = filterKey;
|
||||
params['filterValue'] = encodeURIComponent(filterWidget.value);
|
||||
function askBunch(hookId, startNumber) {
|
||||
askAjax(hookId, null, {'startNumber': startNumber})}
|
||||
|
||||
function askBunchSorted(hookId, sortKey, sortOrder) {
|
||||
var data = {'startNumber': '0', 'sortKey': sortKey, 'sortOrder': sortOrder};
|
||||
askAjax(hookId, null, data);
|
||||
}
|
||||
|
||||
function askBunchFiltered(hookId, filterKey) {
|
||||
var data = {'startNumber': '0', 'filterKey': filterKey, 'filterValue': ''};
|
||||
var node = document.getElementById(hookId + '_' + filterKey);
|
||||
if (node.value) data['filterValue'] = encodeURIComponent(node.value);
|
||||
askAjax(hookId, null, data);
|
||||
}
|
||||
|
||||
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';
|
||||
askAjaxChunk(hookId, 'GET', objectUrl, px, params, null, evalInnerScripts);
|
||||
var data = {'startNumber': startNumber, 'action': 'doChangeOrder',
|
||||
'refObjectUid': uid, 'move': moveTo};
|
||||
askAjax(hookId, null, data);
|
||||
}
|
||||
|
||||
function askObjectHistory(hookId, objectUrl, maxPerPage, startNumber) {
|
||||
// Sends an Ajax request for getting the history of an object
|
||||
var params = {'maxPerPage': maxPerPage, 'startNumber': startNumber};
|
||||
askAjaxChunk(hookId, 'GET', objectUrl, 'pxHistory', params);
|
||||
function askBunchSortRef(hookId, startNumber, sortKey, reverse) {
|
||||
var data = {'startNumber': startNumber, 'action': 'sort', 'sortKey': sortKey,
|
||||
'reverse': reverse};
|
||||
askAjax(hookId, null, data);
|
||||
}
|
||||
|
||||
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 = hookElems.pop();
|
||||
var params = {'innerRef': innerRef, 'scope': scope};
|
||||
params[startKey] = startNumber;
|
||||
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];
|
||||
};
|
||||
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;
|
||||
}
|
||||
var px = (scope == 'objs')? ':pxView': ':pxViewPickList';
|
||||
askAjaxChunk(hookId, 'GET', objectUrl, fieldName + px, params, null,
|
||||
evalInnerScripts);
|
||||
// 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 gotoTied(objectUrl, field, numberWidget, total) {
|
||||
|
@ -381,7 +363,7 @@ function gotoTied(objectUrl, field, numberWidget, total) {
|
|||
|
||||
function askField(hookId, objectUrl, layoutType, customParams, showChanges,
|
||||
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 params = {'layoutType': layoutType, 'showChanges': showChanges};
|
||||
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 = '';
|
||||
if (getChecked) {
|
||||
// We must collect selected objects from a Ref field
|
||||
var node = document.getElementById(uid + '_' + getChecked);
|
||||
if (node && node.hasOwnProperty('_appy_objs_cbs')) {
|
||||
f.checkedUids.value = stringFromDictKeys(node['_appy_objs_cbs']);
|
||||
f.checkedSem.value = node['_appy_objs_sem'];
|
||||
var cNode = document.getElementById(uid + '_' + getChecked);
|
||||
if (cNode && cNode.hasOwnProperty('_appy_objs_cbs')) {
|
||||
f.checkedUids.value = stringFromDictKeys(cNode['_appy_objs_cbs']);
|
||||
f.checkedSem.value = cNode['_appy_objs_sem'];
|
||||
}
|
||||
}
|
||||
// Submitting the form at the end blocks the animated gifs on FF
|
||||
|
|
|
@ -24,44 +24,40 @@ class ToolWrapper(AbstractWrapper):
|
|||
pxSortAndFilter = Px('''
|
||||
<x if="sortable">
|
||||
<img if="(sortKey != field.name) or (sortOrder == 'desc')"
|
||||
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
|
||||
(q(field.name), q('asc'), q(filterKey)))"
|
||||
onclick=":'askBunchSorted(%s, %s, %s)' % \
|
||||
(q(ajaxHookId), q(field.name), q('asc'))"
|
||||
src=":url('sortDown.gif')" class="clickable"/>
|
||||
<img if="(sortKey != field.name) or (sortOrder == 'asc')"
|
||||
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
|
||||
(q(field.name), q('desc'), q(filterKey)))"
|
||||
onclick=":'askBunchSorted(%s, %s, %s)' % \
|
||||
(q(ajaxHookId), q(field.name), q('desc'))"
|
||||
src=":url('sortUp.gif')" class="clickable"/>
|
||||
</x>
|
||||
<x if="filterable"
|
||||
var2="filterId='%s_%s' % (ajaxHookId, field.name);
|
||||
filterIdIcon='%s_icon' % filterId">
|
||||
<!-- Pressing the "enter" key in the field clicks the icon (onkeydown)-->
|
||||
<!-- Pressing the "enter" key in the field clicks the icon (onkeydown)-->
|
||||
<input type="text" size="7" id=":filterId"
|
||||
value=":filterKey == field.name and filterValue or ''"
|
||||
onkeydown=":'if (event.keyCode==13) document.getElementById ' \
|
||||
'(%s).click()' % q(filterIdIcon)"/>
|
||||
<img id=":filterIdIcon" class="clickable" src=":url('funnel')"
|
||||
onclick=":navBaseCall.replace('**v**', '0, %s,%s,%s' % \
|
||||
(q(sortKey), q(sortOrder), q(field.name)))"/>
|
||||
onclick=":'askBunchFiltered(%s, %s)' % \
|
||||
(q(ajaxHookId), q(field.name))"/>
|
||||
</x>''')
|
||||
|
||||
# Buttons for navigating among a list of objects (from a Ref field or a
|
||||
# query): next,back,first,last...
|
||||
pxNavigate = Px('''
|
||||
<div if="totalNumber > batchSize" align=":dright"
|
||||
var2="mustSortAndFilter=ajaxHookId == 'queryResult';
|
||||
sortAndFilter=mustSortAndFilter and \
|
||||
',%s,%s,%s' % (q(sortKey),q(sortOrder),q(filterKey)) or ''">
|
||||
|
||||
<div if="totalNumber > batchSize" align=":dright">
|
||||
<!-- Go to the first page -->
|
||||
<img if="(startNumber != 0) and (startNumber != batchSize)"
|
||||
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 -->
|
||||
<img var="sNumber=startNumber - batchSize" if="startNumber != 0"
|
||||
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 -->
|
||||
<span class="discreet">
|
||||
|
@ -73,7 +69,7 @@ class ToolWrapper(AbstractWrapper):
|
|||
<!-- Go to the next page -->
|
||||
<img var="sNumber=startNumber + batchSize" if="sNumber < totalNumber"
|
||||
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 -->
|
||||
<img var="lastPageIsIncomplete=totalNumber % batchSize;
|
||||
|
@ -84,7 +80,7 @@ class ToolWrapper(AbstractWrapper):
|
|||
if="(startNumber != sNumber) and \
|
||||
(startNumber != sNumber-batchSize)" class="clickable"
|
||||
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... -->
|
||||
<x var="gotoNumber=gotoNumber|False" if="gotoNumber"
|
||||
|
|
|
@ -53,7 +53,7 @@ class AbstractWrapper(object):
|
|||
<!-- Object navigation -->
|
||||
<td var="nav=req.get('nav', None)" if="nav"
|
||||
var2="self=ztool.getNavigationInfo(nav, inPopup)" align=":dright"
|
||||
width="150px">:self.pxNavigate</td>
|
||||
width="200px">:self.pxNavigate</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!-- Object phases and pages -->
|
||||
|
@ -303,18 +303,17 @@ class AbstractWrapper(object):
|
|||
|
||||
# This PX displays an object's history
|
||||
pxHistory = Px('''
|
||||
<div id="appyHistory"
|
||||
var="startNumber=int(req.get('startNumber', 0));
|
||||
<div var="startNumber=int(req.get('startNumber', 0));
|
||||
batchSize=int(req.get('maxPerPage', 5));
|
||||
historyInfo=zobj.getHistory(startNumber, batchSize=batchSize)"
|
||||
if="historyInfo.events"
|
||||
var2="objs=historyInfo.events;
|
||||
var2="ajaxHookId='appyHistory';
|
||||
objs=historyInfo.events;
|
||||
totalNumber=historyInfo.totalNumber;
|
||||
batchNumber=len(objs);
|
||||
ajaxHookId='appyHistory';
|
||||
navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \
|
||||
(q(ajaxHookId), q(zobj.absolute_url()), batchSize)">
|
||||
|
||||
batchNumber=len(objs)"
|
||||
id=":ajaxHookId">
|
||||
<script>:zobj.getHistoryAjaxData(ajaxHookId, startNumber, \
|
||||
batchSize)</script>
|
||||
<!-- Navigate between history pages -->
|
||||
<x>:tool.pxNavigate</x>
|
||||
<!-- History -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue