[gen] New ajax system: bugfixes.

This commit is contained in:
Gaetan Delannay 2015-02-05 05:21:51 +01:00
parent a985f188e0
commit d23b9be5e5
2 changed files with 82 additions and 89 deletions

View file

@ -231,80 +231,79 @@ class Ref(Field):
# PX that displays referred objects as a list # PX that displays referred objects as a list
pxViewList = Px(''' pxViewList = Px('''
<div if="not innerRef or mayAdd or mayLink" style="margin-bottom: 4px"> <div id=":ajaxHookId">
<x if="field.collapsible and objects">:collapse.px</x> <div if="not innerRef or mayAdd or mayLink" style="margin-bottom: 4px">
<span if="subLabel" class="discreet">:_(subLabel)</span> <x if="field.collapsible and objects">:collapse.px</x>
(<span class="discreet">:totalNumber</span>) <span if="subLabel" class="discreet">:_(subLabel)</span>
<x>:field.pxAdd</x> (<span class="discreet">:totalNumber</span>)
<!-- This button opens a popup for linking additional objects --> <x>:field.pxAdd</x>
<x if="mayLink and not inPickList" <!-- This button opens a popup for linking additional objects -->
var2="popupMode='add'">:field.pxLink</x> <x if="mayLink and not inPickList"
<!-- The search button if field is queryable --> var2="popupMode='add'">:field.pxLink</x>
<input if="objects and field.queryable" type="button" <!-- The search button if field is queryable -->
var2="label=_('search_button'); css=ztool.getButtonCss(label)" <input if="objects and field.queryable" type="button"
value=":label" class=":css" style=":url('search', bg=True)" var2="label=_('search_button'); css=ztool.getButtonCss(label)"
onclick=":'goto(%s)' % \ value=":label" class=":css" style=":url('search', bg=True)"
q('%s/search?className=%s&amp;ref=%s:%s' % \ onclick=":'goto(%s)' % \
(ztool.absolute_url(), tiedClassName, zobj.id, field.name))"/> q('%s/search?className=%s&amp;ref=%s:%s' % \
</div> (ztool.absolute_url(), tiedClassName, zobj.id, field.name))"/>
</div>
<!-- (Top) navigation --> <!-- (Top) navigation -->
<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 (innerRef 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=":not innerRef and 'list' or ''" class=":not innerRef and 'list' or ''"
width=":innerRef and '100%' or 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">
<script>:field.getAjaxData(ajaxHookId, zobj, popup=inPopup, \ <script>:field.getAjaxData(ajaxHookId, zobj, popup=inPopup, \
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, navBaseCall=navBaseCall)</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>
<th if="checkboxes" class="cbCell"> <th if="checkboxes" class="cbCell">
<img src=":url('checkall')" class="clickable" <img src=":url('checkall')" class="clickable"
title=":_('check_uncheck')" title=":_('check_uncheck')"
onclick=":'toggleAllCbs(%s)' % q(ajaxHookId)"/> onclick=":'toggleAllCbs(%s)' % q(ajaxHookId)"/>
</th> </th>
<th for="column in columns" width=":column.width" <th for="column in columns" width=":column.width"
align=":column.align" var2="refField=column.field"> align=":column.align" var2="refField=column.field">
<span>:_(refField.labelId)</span> <span>:_(refField.labelId)</span>
<x>:field.pxSortIcons</x> <x>:field.pxSortIcons</x>
<x var="className=tiedClassName; <x var="className=tiedClassName;
field=refField">:tool.pxShowDetails</x> field=refField">:tool.pxShowDetails</x>
</th> </th>
</tr> </tr>
<!-- Loop on every (tied or selectable) object --> <!-- Loop on every (tied or selectable) object -->
<x for="tied in objects" <x for="tied in objects"
var2="@currentNumber=currentNumber + 1; var2="@currentNumber=currentNumber + 1;
rowCss=loop.tied.odd and 'even' or 'odd'">:obj.pxViewAsTied</x> rowCss=loop.tied.odd and 'even' or 'odd'">:obj.pxViewAsTied</x>
</table> </table>
<!-- Global actions -->
<!-- Global actions --> <x if="mayEdit and checkboxes">:field.pxGlobalActions</x>
<x if="mayEdit and checkboxes">:field.pxGlobalActions</x> <!-- (Bottom) navigation -->
<x>:tool.pxNavigate</x>
<!-- (Bottom) navigation --> <!-- Init checkboxes if present. -->
<x>:tool.pxNavigate</x> <script if="checkboxes">:'initCbs(%s)' % q(ajaxHookId)</script>
</div>''')
<!-- Init checkboxes if present. -->
<script if="checkboxes"
type="text/javascript">:'initCbs(%s)' % q(ajaxHookId)
</script>''')
# 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="innerRef=False;
ajaxHookId=ajaxHookId|'%s_%s_poss' % (zobj.id, field.name); ajaxHookId=ajaxHookId|'%s_%s_poss' % (zobj.id, field.name);
layoutType='view';
inMenu=False;
inPickList=True; inPickList=True;
startNumber=field.getStartNumber('list', req, ajaxHookId); startNumber=field.getStartNumber('list', req, ajaxHookId);
info=field.getPossibleValues(zobj, startNumber=startNumber, \ info=field.getPossibleValues(zobj, startNumber=startNumber, \
@ -326,6 +325,7 @@ class Ref(Field):
(q(ajaxHookId), q(zobj.absolute_url()), q(innerRef)); (q(ajaxHookId), q(zobj.absolute_url()), q(innerRef));
changeOrder=False; changeOrder=False;
changeNumber=False; changeNumber=False;
numbered=False;
checkboxes=field.getAttribute(zobj, 'checkboxes') and \ checkboxes=field.getAttribute(zobj, 'checkboxes') and \
(totalNumber &gt; 1); (totalNumber &gt; 1);
showSubTitles=showSubTitles|\ showSubTitles=showSubTitles|\
@ -439,14 +439,12 @@ class Ref(Field):
<!-- JS tables storing checkbox statuses if checkboxes are enabled --> <!-- JS tables storing checkbox statuses if checkboxes are enabled -->
<script if="checkboxesEnabled and renderAll and (render == 'list')" <script if="checkboxesEnabled and renderAll and (render == 'list')"
type="text/javascript">:field.getCbJsInit(zobj)</script> type="text/javascript">:field.getCbJsInit(zobj)</script>
<div if="linkList and renderAll and mayEdit" <x if="linkList and renderAll and mayEdit"
var2="ajaxHookId='%s_%s_poss' % (zobj.id, field.name)" var2="ajaxHookId='%s_%s_poss' % \
id=":ajaxHookId">:field.pxViewPickList</div> (zobj.id, field.name)">:field.pxViewPickList</x>
<x if="render == 'list'" <x if="render == 'list'"
var2="subLabel=linkList and 'selected_objects' or None"> var2="subLabel=linkList and \
<div if="renderAll" id=":ajaxHookId">:field.pxViewList</div> 'selected_objects' or None">:field.pxViewList</x>
<x if="not renderAll">:field.pxViewList</x>
</x>
<x if="render in ('menus','minimal')">:getattr(field, 'pxView%s' % \ <x if="render in ('menus','minimal')">:getattr(field, 'pxView%s' % \
render.capitalize())</x> render.capitalize())</x>
</x>''') </x>''')

View file

@ -303,17 +303,17 @@ class AbstractWrapper(object):
# This PX displays an object's history # This PX displays an object's history
pxHistory = Px(''' pxHistory = Px('''
<x var="startNumber=req.get('startNumber', 0); <div id="appyHistory"
startNumber=int(startNumber); 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="objs=historyInfo.events;
totalNumber=historyInfo.totalNumber; totalNumber=historyInfo.totalNumber;
batchNumber=len(objs); batchNumber=len(objs);
ajaxHookId='appyHistory'; ajaxHookId='appyHistory';
navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \ navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \
(q(ajaxHookId), q(zobj.absolute_url()), batchSize)"> (q(ajaxHookId), q(zobj.absolute_url()), batchSize)">
<!-- Navigate between history pages --> <!-- Navigate between history pages -->
<x>:tool.pxNavigate</x> <x>:tool.pxNavigate</x>
@ -370,7 +370,7 @@ class AbstractWrapper(object):
</td> </td>
</tr> </tr>
</table> </table>
</x>''') </div>''')
pxTransitions = Px(''' pxTransitions = Px('''
<form var="transitions=targetObj.getTransitions()" if="transitions" <form var="transitions=targetObj.getTransitions()" if="transitions"
@ -429,12 +429,7 @@ class AbstractWrapper(object):
<!-- Object history --> <!-- Object history -->
<tr if="hasHistory"> <tr if="hasHistory">
<td colspan="2"> <td colspan="2">
<span id=":collapse.id" style=":collapse.style"> <span id=":collapse.id" style=":collapse.style"><x>:obj.pxHistory</x>
<div var="ajaxHookId=zobj.id + '_history'" id=":ajaxHookId">
<script type="text/javascript">::'askObjectHistory(%s,%s,%d,0)' % \
(q(ajaxHookId), q(zobj.absolute_url()), \
historyMaxPerPage)</script>
</div>
</span> </span>
</td> </td>
</tr> </tr>