[gen] Optimized PXs. [px] added tag 'var2', similar to 'var', but that is executed after tags 'for' and 'if'.

This commit is contained in:
Gaetan Delannay 2013-07-15 11:23:29 +02:00
parent 73c3cfb2c7
commit 1810373304
18 changed files with 834 additions and 956 deletions

View file

@ -33,17 +33,15 @@ class Action(Field):
<input type="hidden" name="action" value="ExecuteAppyAction"/>
<input type="hidden" name="objectUid" value=":contextObj.UID()"/>
<input type="hidden" name="fieldName" value=":name"/>
<x if="field.confirm"><input
type="button" class="button"
<input if="field.confirm" type="button" class="button"
var="labelConfirm=_(field.labelId + '_confirm')"
value=":ztool.truncateValue(label)" title=":label"
style=":'background-image: url(%s/ui/buttonAction.png)' % appUrl"
style=":img('buttonAction', bg=True)"
onclick=":'askConfirm(%s,%s,%s)' % (q('form'), q(formId), \
q(labelConfirm))"/>
</x>
<input if="not field.confirm" type="submit" class="button" name="do"
value=":ztool.truncateValue(label)" title=":label"
style=":'background-image: url(%s/ui/buttonAction.png)' % appUrl"/>
style=":img('buttonAction', bg=True)"/>
</form>''')
# It is not possible to edit an action, not to search it.

View file

@ -37,8 +37,7 @@ class Calendar(Field):
id=":ajaxHookId">
<script type="text/javascript">:'var %s_maxEventLength = %d;' % \
(field.name, field.maxEventLength)">
</script>
(field.name, field.maxEventLength)"></script>
<!-- Month chooser -->
<div style="margin-bottom: 5px"
@ -48,13 +47,11 @@ class Calendar(Field):
goForward=not endDate or (endDate.strftime(fmt) &gt; \
grid[-1][-1].strftime(fmt))">
<!-- Go to the previous month -->
<img style="cursor:pointer" tal:condition="goBack"
src=":'%s/ui/arrowLeftSimple.png' % appUrl"
onclick=":'askMonthView(%s, %s, %s, %s)' % \
<img style="cursor:pointer" if="goBack" src=":img('arrowLeftSimple')"
onclick=":'askMonthView(%s,%s,%s,%s)' % \
(q(ajaxHookId),q(objUrl),q(field.name),q(previousMonth))"/>
<!-- Go back to the default date -->
<x if="goBack or goForward">
<input type="button"
<input type="button" if="goBack or goForward"
var="fmt='%Y/%m';
label=(defaultDate.strftime(fmt)==today.strftime(fmt)) and \
'today' or 'goto_source'"
@ -62,10 +59,8 @@ class Calendar(Field):
onclick=":'askMonthView(%s, %s, %s, %s)' % (q(ajaxHookId), \
q(objUrl), q(field.name), q(defaultDateMonth))"
disabled=":defaultDate.strftime(fmt)==monthDayOne.strftime(fmt)"/>
</x>
<!-- Go to the next month -->
<img style="cursor:pointer" if="goForward"
src=":'%s/ui/arrowRightSimple.png' % appUrl"
<img style="cursor:pointer" if="goForward" src=":img('arrowRightSimple')"
onclick=":'askMonthView(%s, %s, %s, %s)' % (q(ajaxHookId), \
q(objUrl), q(field.name), q(nextMonth))"/>
<span>:_('month_%s' % monthDayOne.aMonth())</span>
@ -83,19 +78,21 @@ class Calendar(Field):
</tr>
<!-- The calendar in itself -->
<tr for="row in grid" valign="top" height=":rowHeight">
<x for="date in row">
<x var="tooEarly=startDate and (date &lt; startDate);
<x for="date in row"
var2="tooEarly=startDate and (date &lt; startDate);
tooLate=endDate and not tooEarly and (date &gt; endDate);
inRange=not tooEarly and not tooLate;
cssClasses=field.getCellStyle(contextObj, date, today)">
<!-- Dump an empty cell if we are out of the supported date range -->
<td if="not inRange" class=":cssClasses"></td>
<!-- Dump a normal cell if we are in range -->
<x if="inRange">
<td var="events=field.getEventsAt(contextObj, date);
<td if="inRange"
var2="events=field.getEventsAt(contextObj, date);
spansDays=field.hasEventsAt(contextObj, date+1, events);
mayCreate=mayEdit and not events;
mayDelete=mayEdit and events"
mayDelete=mayEdit and events;
day=date.day();
dayString=date.strftime('%Y/%m/%d')"
style="date.isCurrentDay() and 'font-weight:bold' or \
'font-weight:normal'"
class=":cssClasses"
@ -103,8 +100,6 @@ class Calendar(Field):
%s)[0].style.visibility=%s' % (q('img'), q('visible')) or ''"
onmouseout="mayEdit and 'this.getElementsByTagName(\
%s)[0].style.visibility=%s' % (q('img'), q('hidden')) or ''">
<x var="day=date.day();
dayString=date.strftime('%Y/%m/%d')">
<span>:day</span>
<span if="day == 1">:_('month_%s_short' % date.aMonth())"></span>
<!-- Icon for adding an event -->
@ -112,41 +107,33 @@ class Calendar(Field):
<img style="visibility:hidden; cursor:pointer"
var="info=field.getApplicableEventsTypesAt(contextObj, date, \
allEventTypes, preComputed, True)"
if="info['eventTypes']"
src=":'%s/ui/plus.png' % appUrl"
if="info['eventTypes']" src=":img('plus')"
onclick=":'openEventPopup(%s, %s, %s, null, %s, %s)' % \
(q('new'), q(field.name), q(dayString), \
q(info['eventTypes']), q(info['message']))"/>
(q('new'), q(field.name), q(dayString), q(info['eventTypes']),\
q(info['message']))"/>
</x>
<!-- Icon for deleting an event -->
<img if="mayDelete" style="visibility:hidden; cursor:pointer"
src=":'%s/ui/delete.png' % appUrl"
src=":img('delete')"
onclick=":'openEventPopup(%s, %s, %s, %s, null, null)' % \
(q('del'), q(field.name), q(dayString), q(str(spansDays)))"/>
<x if="events">
<!-- A single event is allowed for the moment -->
<div var="eventType=events[0]['eventType']">
<div if="events" var2="eventType=events[0]['eventType']">
<span style="color: grey">:field.getEventName(contextObj, \
eventType)"></span>
</div>
</x>
<!-- Events from other calendars -->
<x if="otherCalendars">
<x var="otherEvents=field.getOtherEventsAt(contextObj, date, \
otherCalendars)"
if="otherEvents">
<x if="otherCalendars"
var2="otherEvents=field.getOtherEventsAt(contextObj, date, \
otherCalendars)">
<div style=":'color: %s; font-style: italic' % event['color']"
for="event in otherEvents">:event['name']</div>
</x>
</x>
<!-- Additional info -->
<x var="info=field.getAdditionalInfoAt(contextObj,date,preComputed)"
if="info">::info</x>
</x>
</td>
</x>
</x>
</x>
</tr>
</table>
@ -222,10 +209,8 @@ class Calendar(Field):
pxView = pxCell = Px('''
<x var="defaultDate=field.getDefaultDate(contextObj);
x=req.set('fieldName', field.name);
x=req.set('month', defaultDate.strftime('%Y/%m'))">
<x>:field.pxMonthView</x>
</x>''')
x=req.set('month', defaultDate.strftime('%Y/%m'));
x=req.set('fieldName', field.name)">:field.pxMonthView</x>''')
pxEdit = pxSearch = ''

View file

@ -28,23 +28,19 @@ class Computed(Field):
value=contextObj.getFieldValue(name);
sync=True">:field.pxView</x>''')
pxView = pxCell = pxEdit = Px('''
<x>
pxView = pxCell = pxEdit = Px('''<x>
<x if="sync">
<x if="field.plainText">:value</x>
<x if="not field.plainText">::value></x>
<x if="field.plainText">:value</x><x if="not field.plainText">::value></x>
</x>
<x if="not sync">
<div var="ajaxHookId=contextObj.UID() + name" id="ajaxHookId">
<div if="not sync">
var2="ajaxHookId=contextObj.UID() + name" id="ajaxHookId">
<script type="text/javascript">:'askComputedField(%s, %s, %s)' % \
(q(ajaxHookId), q(contextObj.absolute_url()), q(name))">
</script>
</div>
</x>
</x>''')
pxSearch = Px('''
<x>
pxSearch = Px('''<x>
<label lfor=":name">:field.labelId</label><br/>&nbsp;&nbsp;
<input type="text" name=":'%s*string' % name" maxlength=":field.maxChars"
size=":field.width" value=":field.sdefault"/>

View file

@ -29,20 +29,20 @@ class Date(Field):
<select var="days=range(1,32)"
name=":'%s_day' % name" id=":'%s_day' % name">
<option value="">-</option>
<x for="day in days">
<option var="zDay=str(day).zfill(2)" value=":zDay"
<option for="day in days"
var2="zDay=str(day).zfill(2)" value=":zDay"
selected="field.isSelected(contextObj, 'day', day, \
rawValue)">:zDay</option></x>
rawValue)">:zDay</option>
</select>
<!-- Month -->
<select var="months=range(1,13)"
name=":'%s_month' % name" id=":'%s_month' % name">
<option value="">-</option>
<x for="month in months">
<option var="zMonth=str(month).zfill(2)" value=":zMonth"
<option for="month in months"
var2="zMonth=str(month).zfill(2)" value=":zMonth"
selected="field.isSelected(contextObj, 'month', month, \
rawValue)">:zMonth</option></x>
rawValue)">:zMonth</option>
</select>
<!-- Year -->
@ -56,7 +56,7 @@ class Date(Field):
<!-- The icon for displaying the calendar popup -->
<x if="field.calendar">
<input type="hidden" id=":name" name=":name"/>
<img id=":'%s_img' % name" src=":'%s/ui/calendar.gif' % appUrl"/>
<img id=":'%s_img' % name" src=":img('calendar.gif')"/>
<script type="text/javascript">:field.getJsInit(name, years)</script>
</x>
@ -65,19 +65,18 @@ class Date(Field):
<select var="hours=range(0,24)" name=":'%s_hour' % name"
id=":'%s_hour' % name">
<option value="">-</option>
<x for="hour in hours">
<option var="zHour=str(hour).zfill(2)" value=":zHour"
<option for="hour in hours"
var2="zHour=str(hour).zfill(2)" value=":zHour"
selected=":field.isSelected(contextObj, 'hour', hour, \
rawValue)">:zHour</option>
</x>
</select> :
<select var="minutes=range(0,60,5)" name=":'%s_minute' % name"
id=":'%s_minute' % name">
<option value="">-</option>
<x for="minute in minutes">
<option var="zMinute=str(minute).zfill(2)" value=":zMinute"
<option for="minute in minutes"
var2="zMinute=str(minute).zfill(2)" value=":zMinute"
selected=":field.isSelected(contextObj, 'minute', minute,\
rawValue)">:zMinute</option></x>
rawValue)">:zMinute</option>
</select>
</x>
</x>''')
@ -112,7 +111,7 @@ class Date(Field):
<!-- The icon for displaying the calendar popup -->
<x if="field.calendar">
<input type="hidden" id=":fromName" name=":fromName"/>
<img id=":'%s_img' % fromName" src=":'%s/ui/calendar.gif' % appUrl"/>
<img id=":'%s_img' % fromName" src=":img('calendar.gif')"/>
<script type="text/javascript">:field.getJsInit(fromName, years)
</script>
</x>
@ -145,7 +144,7 @@ class Date(Field):
<!-- The icon for displaying the calendar popup -->
<x if="widget.calendar">
<input type="hidden" id=":toName" name=":toName"/>
<img id=":'%s_img' % toName" src=":%s/ui/calendar.gif' % appUrl"/>
<img id=":'%s_img' % toName" src=":img('calendar.gif')"/>
<script type="text/javascript">:field.getJsInit(toName, years)">
</script>
</x>

View file

@ -35,8 +35,7 @@ class Float(Field):
maxlength=":field.maxChars"
value=":inRequest and requestValue or value" type="text"/>''')
pxSearch = Px('''
<x>
pxSearch = Px('''<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*float' % widgetName">

View file

@ -32,8 +32,7 @@ class Integer(Field):
maxlength=":field.maxChars"
value=":inRequest and requestValue or value" type="text"/>''')
pxSearch = Px('''
<x>
pxSearch = Px('''<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*int' % widgetName">

View file

@ -27,15 +27,14 @@ class List(Field):
# PX for rendering a single row.
pxRow = Px('''
<tr valign="top" style="(rowIndex==-1) and 'display: none' or ''">
<td align="center" for="info in field.fields">
<x var="field=info[1];
<td align="center" for="info in field.fields"
var2="field=info[1];
tagCss='noStyle';
widgetName='%s*%d' % (field.name, rowIndex)">:field.pxView</x>
</td>
widgetName='%s*%d' % (field.name, rowIndex)">:field.pxView</td>
<!-- Icon for removing the row -->
<td if="layoutType=='edit'" align=":dright">
<img style="cursor:pointer" src=":'%s/ui/delete.png' % appUrl"
title="Delete"
<img style="cursor:pointer" src=":img(delete')"
title=":_('object_delete')"
onclick=":'deleteRow(%s, this)' % q('list_%s' % name)"/>
</td>
</tr>''')
@ -49,8 +48,7 @@ class List(Field):
<th for="info in field.fields">::_(info[1].labelId)</th>
<!-- Icon for adding a new row. -->
<th if="isEdit">
<img style="cursor:pointer" src=":'%s/ui/plus.png' % appUrl"
title=":_('add_ref')"
<img style="cursor:pointer" src=":img('plus')" title=":_('add_ref')"
onclick=":'insertRow(%s)' % q('list_%s' % name)"/>
</th>
</tr>
@ -60,14 +58,12 @@ class List(Field):
<tr height="7px" if="isEdit"><td></td></tr>
<!-- Rows of data -->
<x var="rows=inRequest and requestValue or value" for="row in rows">
<x var="rowIndex=loop.row.nb">:field.pxRow</x>
</x>
<x var="rows=inRequest and requestValue or value"
for="row in rows" var2="rowIndex=loop.row.nb">:field.pxRow</x>
</table>''')
pxView = pxCell = Px('''<x>:field.pxTable</x>''')
pxEdit = Px('''
<x>
pxEdit = Px('''<x>
<!-- This input makes Appy aware that this field is in the request -->
<input type="hidden" name=":name" value=""/><x>:field.pxTable</x>
</x>''')

View file

@ -30,19 +30,16 @@ class Ogone(Field):
'''This field allows to perform payments with the Ogone (r) system.'''
urlTypes = ('accept', 'decline', 'exception', 'cancel')
pxView = pxCell = Px('''
<x>
pxView = pxCell = Px('''<x>
<!-- var "value" is misused and contains the contact params for Ogone -->
<!-- The form for sending the payment request to Ogone -->
<form method="post" id="form1" name="form1" var="env=value['env']"
action=":'https://secure.ogone.com/ncol/%s/orderstandard.asp'% env">
<x for="item in value.items()">
<input type="hidden" if="item[0] != 'env'" id=":item[0]"
name=":item[0]" value=":item[1]"/>
</x>
<input type="hidden" for="item in value.items()" if="item[0] != 'env'"
id=":item[0]" name=":item[0]" value=":item[1]"/>
<!-- Submit image -->
<input type="image" id="submit2" name="submit2"
src=":'%s/ui/ogone.gif' % $appUrl" title=":_('custom_pay')"/>
<input type="image" id="submit2" name="submit2" src=":img('ogone.gif')"
title=":_('custom_pay')"/>
</form>
</x>''')

View file

@ -35,22 +35,18 @@ class Pod(Field):
'contact the system administrator.'
DELETE_TEMP_DOC_ERROR = 'A temporary document could not be removed. %s.'
pxView = pxCell = Px('''
<x>
pxView = pxCell = Px('''<x>
<!-- Ask action -->
<x if="field.askAction">
<x var="doLabel='%s_askaction' % field.labelId;
<x if="field.askAction"
var2="doLabel='%s_askaction' % field.labelId;
chekboxId='%s_%s_cb' % (contextObj.UID(), name)">
<input type="checkbox" name=":doLabel" id=":chekboxId"/>
<label lfor=":chekboxId" class="discreet">:_(doLabel)"></label>
</x>
</x>
<img for="podFormat in field.getToolInfo(contextObj.appy())[1]"
src=":'%s/ui/%s.png' % (appUrl, podFormat)"
<img for="fmt in field.getToolInfo(contextObj.appy())[1]" src=":img(fmt)"
onclick=":'generatePodDocument(%s, %s, %s, %s)' % \
(q(contextObj.UID()), q(name), q(podFormat), \
q(ztool.getQueryInfo()))"
title=":podFormat.capitalize()" style="cursor:pointer"/>
(q(contextObj.UID()), q(name), q(fmt), q(ztool.getQueryInfo()))"
title=":fmt.capitalize()" style="cursor:pointer"/>
</x>''')
pxEdit = pxSearch = ''

View file

@ -56,41 +56,37 @@ class Ref(Field):
<table class="noStyle" var="isBack=field.isBack">
<tr>
<!-- Arrows for moving objects up or down -->
<td if="not isBack and (len(objs)&gt;1) and changeOrder and canWrite">
<x var="objectIndex=field.getIndexOf(contextObj, obj);
<td if="not isBack and (len(objs)&gt;1) and changeOrder and canWrite"
var2="objectIndex=field.getIndexOf(contextObj, obj);
ajaxBaseCall=navBaseCall.replace('**v**','%s,%s,{%s:%s,%s:%s}'%\
(q(startNumber), q('ChangeRefOrder'), q('refObjectUid'),
q(obj.UID()), q('move'), q('**v**')))">
<img if="objectIndex &gt; 0" style="cursor:pointer"
src=":'%s/ui/arrowUp.png' % appUrl" title=":_('move_up')"
onclick=":ajaxBaseCall.replace('**v**', 'up')"/><img
style="cursor:pointer" if="objectIndex &lt; (totalNumber-1)"
src=":'%s/ui/arrowDown.png' % appUrl" title=":_('move_down')"
src=":img('arrowUp')" title=":_('move_up')"
onclick=":ajaxBaseCall.replace('**v**', 'up')"/>
<img if="objectIndex &lt; (totalNumber-1)" style="cursor:pointer"
src=":img('arrowDown')" title=":_('move_down')"
onclick=":ajaxBaseCall.replace('**v**', 'down')"/>
</x>
</td>
<!-- Workflow transitions -->
<td if="obj.showTransitions('result')">
<x var="targetObj=obj">:targetObj.appy().pxTransitions</x>
</td>
<td if="obj.showTransitions('result')"
var2="targetObj=obj">:targetObj.appy().pxTransitions</td>
<!-- Edit -->
<td if="not field.noForm and obj.mayEdit() and field.delete">
<a var="navInfo='ref.%s.%s:%s.%d.%d' % (contextObj.UID(), field.name, \
field.pageName, loop.obj.nb + startNumber, totalNumber)"
href=":obj.getUrl(mode='edit', page='main', nav=navInfo)">
<img src=":'%s/ui/edit.png' % appUrl" title=":_('object_edit')"/>
</a>
<img src=":img('edit')" title=":_('object_edit')"/></a>
</td>
<!-- Delete -->
<td if="not isBack and field.delete and canWrite and obj.mayDelete()">
<img style="cursor:pointer" title=":_('object_delete')"
src=":'%s/ui/delete.png' % appUrl"
onclick=":'onDeleteObject(%s)' % q(obj.UID())"/>
src=":img('delete')" onclick=":'onDeleteObject(%s)'%q(obj.UID())"/>
</td>
<!-- Unlink -->
<td if="not isBack and field.unlink and canWrite">
<img style="cursor:pointer" title=":_('object_unlink')"
src=":'%s/ui/unlink.png' % appUrl"
src=":img('unlink')"
onclick=":'onUnlinkObject(%s,%s,%s)' % (q(contextObj.UID()), \
q(field.name), q(obj.UID()))"/>
</td>
@ -100,9 +96,8 @@ class Ref(Field):
# Displays the button allowing to add a new object through a Ref field, if
# it has been declared as addable and if multiplicities allow it.
pxAdd = Px('''
<x if="showPlusIcon">
<input type="button" class="button"
var="navInfo='ref.%s.%s:%s.%d.%d' % (contextObj.UID(), \
<input if="showPlusIcon" type="button" class="button"
var2="navInfo='ref.%s.%s:%s.%d.%d' % (contextObj.UID(), \
field.name, field.pageName, 0, totalNumber);
formCall='window.location=%s' % \
q('%s/do?action=Create&amp;className=%s&amp;nav=%s' % \
@ -115,22 +110,20 @@ class Ref(Field):
noFormCall=not field.addConfirm and noFormCall or \
'askConfirm(%s, %s, %s)' % (q('script'), q(noFormCall), \
q(addConfirmMsg))"
style=":'background-image: url(%s/ui/buttonAdd.png)' % appUrl"
value=":_('add_ref')"
onclick=":field.noForm and noFormCall or formCall"/>
</x>''')
style=":img('buttonAdd', bg=True)" value=":_('add_ref')"
onclick=":field.noForm and noFormCall or formCall"/>''')
# This PX displays, in a cell header from a ref table, icons for sorting the
# ref field according to the field that corresponds to this column.
pxSortIcons = Px('''
<x var="ajaxBaseCall=navBaseCall.replace('**v**', '%s,%s,{%s:%s,%s:%s}' % \
<x if="changeOrder and canWrite and ztool.isSortable(field.name, \
objs[0].meta_type, 'ref')"
var2="ajaxBaseCall=navBaseCall.replace('**v**', '%s,%s,{%s:%s,%s:%s}'% \
(q(startNumber), q('SortReference'), q('sortKey'), \
q(field.name), q('reverse'), q('**v**')))"
if="changeOrder and canWrite and ztool.isSortable(field.name, \
objs[0].meta_type, 'ref')">
<img style="cursor:pointer" src=":'%s/ui/sortAsc.png' % appUrl"
q(field.name), q('reverse'), q('**v**')))">
<img style="cursor:pointer" src=":img('sortAsc')"
onclick=":ajaxBaseCall.replace('**v**', 'False')"/>
<img style="cursor:pointer" src=":'%s/ui/sortDesc.png' % appUrl"
<img style="cursor:pointer" src=":img('sortDesc')"
onclick=":ajaxBaseCall.replace('**v**', 'True')"/>
</x>''')
@ -165,10 +158,8 @@ class Ref(Field):
shouldn't check the actual number of referenced objects. But for
back references people often forget to specify multiplicities. So
concretely, multiplicities (0,None) are coded as (0,1). -->
<x if="atMostOneRef">
<!-- Display a simplified widget if maximum number of referenced objects
is 1. -->
<table>
<!-- Display a simplified widget if at most 1 referenced object. -->
<table if="atMostOneRef">
<tr valign="top">
<!-- If there is no object -->
<x if="not objs">
@ -177,13 +168,11 @@ class Ref(Field):
</x>
<!-- If there is an object... -->
<x if="objs">
<x for="obj in objs">
<td var="includeShownInfo=True">:field.pxObjectTitle</td>
</x>
<td for="obj in objs"
var2="includeShownInfo=True">:field.pxObjectTitle</td>
</x>
</tr>
</table>
</x>
<!-- Display a table in all other cases -->
<x if="not atMostOneRef">
@ -192,8 +181,7 @@ class Ref(Field):
<x>:field.pxAdd</x>
<!-- The search button if field is queryable -->
<input if="objs and field.queryable" type="button" class="button"
style=":'background-image: url(%s/ui/buttonSearch.png)' % appUrl"
value=":_('search_title')"
style=":img('buttonSearch', bg=True)" value=":_('search_title')"
onclick=":'window.location=%s' % \
q('%s/ui/search?className=%s&amp;ref=%s:%s' % \
(ztool.absolute_url(), linkedPortalType, contextObj.UID(), \
@ -216,21 +204,19 @@ class Ref(Field):
var="columns=objs[0].getColumnsSpecifiers(field.shownInfo, dir)">
<tr if="field.showHeaders">
<th for="column in columns" width=":column['width']"
align="column['align']">
<x var="field=column['field']">
<span>_(field.labelId)</span>
align="column['align']"
var2="field=column['field']">
<span>:_(field.labelId)</span>
<x>:field.pxSortIcons</x>
<x var="className=linkedPortalType">:contextObj.appy(\
).pxShowDetails</x>
</x>
</th>
</tr>
<x for="obj in objs">
<tr valign="top" var="odd=loop.obj.odd"
<tr for="obj in objs" var2="odd=loop.obj.odd" valign="top"
class=":odd and 'even' or 'odd'">
<td for="column in columns"
width=":column['width']" align=":column['align']">
<x var="field=column['field']">
width=":column['width']" align=":column['align']"
var2="field=column['field']">
<!-- The "title" field -->
<x if="python: field.name == 'title'">
<x>:field.pxObjectTitle</x>
@ -238,17 +224,12 @@ class Ref(Field):
</x>
<!-- Any other field -->
<x if="field.name != 'title'">
<x var="contextObj=obj;
layoutType='cell';
innerRef=True"
if="obj.showField(field.name, layoutType='result')">
<!-- use-macro="app/ui/widgets/show/macros/field"/-->
</x>
</x>
<x var="contextObj=obj; layoutType='cell'; innerRef=True"
if="obj.showField(field.name, \
layoutType='result')">:field.pxView</x>
</x>
</td>
</tr>
</x>
</table>
</td>
</tr>
@ -263,47 +244,40 @@ class Ref(Field):
<x var="x=req.set('fieldName', field.name)">:field.pxViewContent</x>''')
pxEdit = Px('''
<x if="field.link"
var="requestValue=req.get(name, []);
<select if="field.link"
var2="requestValue=req.get(name, []);
inRequest=req.has_key(name);
allObjects=field.getSelectableObjects();
uids=[o.UID() for o in field.getLinkedObjects(contextObj).objects];
isBeingCreated=contextObj.isTemporary()">
<select name=":name" size="isMultiple and field.height or ''"
uids=[o.UID() for o in \
field.getLinkedObjects(contextObj).objects];
isBeingCreated=contextObj.isTemporary()"
name=":name" size="isMultiple and field.height or ''"
multiple="isMultiple and 'multiple' or ''">
<option value="" if="not isMultiple">:_('choose_a_value')"></option>
<x for="refObj in allObjects">
<option var="uid=refObj.o.UID()"
<option for="refObj in allObjects" var2="uid=refObj.o.UID()"
selected=":inRequest and (uid in requestValue) or \
(uid in uids)"
value=":uid">:field.getReferenceLabel(refObj)</option>
</x>
</select>
</x>''')
</select>''')
pxSearch = Px('''
<x>
pxSearch = Px('''<x>
<label lfor=":widgetName">:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- The "and" / "or" radio buttons -->
<x var="operName='o_%s' % name;
<x if="field.multiplicity[1] != 1"
var2="operName='o_%s' % name;
orName='%s_or' % operName;
andName='%s_and' % operName"
if="field.multiplicity[1] != 1">
<input type="radio" name=":operName" id=":orName"
checked="checked" value="or"/>
andName='%s_and' % operName">
<input type="radio" name=":operName" id=":orName" checked="checked"
value="or"/>
<label lfor=":orName">:_('search_or')"></label>
<input type="radio" name=":operName" id=":andName" value="and"/>
<label lfor=":andName">:_('search_and')"></label><br/>
</x>
<!-- The list of values -->
<select name=":widgetName" size=":field.sheight" multiple="multiple">
<x for="v in ztool.getSearchValues(name, className)">
<option var="uid=v[0];
title=field.getReferenceLabel(v[1])"
value=":uid"
title=":title">:ztool.truncateValue(title, field.swidth)">
</option>
</x>
<option for="v in ztool.getSearchValues(name, className)"
var2="uid=v[0]; title=field.getReferenceLabel(v[1])" value=":uid"
title=":title">:ztool.truncateValue(title,field.swidth)"></option>
</select>
</x>''')

View file

@ -108,8 +108,8 @@ class String(Field):
isSelect=field.isSelect;
isMaster=field.slaves;
isOneLine=fmt in (0,3,4)">
<x if="isSelect">
<select var="possibleValues=field.getPossibleValues(contextObj, \
<select if="isSelect"
var2="possibleValues=field.getPossibleValues(contextObj, \
withTranslations=True, withBlankValue=True)"
name=":name" id=":name" class=":masterCss"
multiple=":isMultiple and 'multiple' or ''"
@ -120,7 +120,6 @@ class String(Field):
title=":val[1]">:ztool.truncateValue(val[1], field.width)">
</option>
</select>
</x>
<x if="isOneLine and not isSelect">
<input id=":name" name=":name" size=":field.width"
maxlength=":field.maxChars"
@ -149,24 +148,21 @@ class String(Field):
<x if="not multipleValues">:field.pxView</x>
</x>''')
pxSearch = Px('''
<x>
pxSearch = Px('''<x>
<label lfor="widgetName">:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- Show a simple search field for most String fields -->
<x if="not field.isSelect">
<input type="text" maxlength=":field.maxChars" size=":field.swidth"
<input if="not field.isSelect" type="text" maxlength=":field.maxChars"
size=":field.swidth" value=":field.sdefault"
name=":'%s*string-%s' % (widgetName, field.transform)"
style=":'text-transform:%s' % field.transform"
value=":field.sdefault"/>
</x>
style=":'text-transform:%s' % field.transform"/>
<!-- Show a multi-selection box for fields whose validator defines a list
of values, with a "AND/OR" checkbox. -->
<x if="field.isSelect">
<!-- The "and" / "or" radio buttons -->
<x var="operName='o_%s' % name;
<x if="field.multiplicity[1] != 1"
var2="operName='o_%s' % name;
orName='%s_or' % operName;
andName='%s_and' % operName"
if="field.multiplicity[1] != 1">
andName='%s_and' % operName">
<input type="radio" name=":operName" id=":orName" checked="checked"
value="or"/>
<label lfor=":orName">:_('search_or')</label>

View file

@ -105,6 +105,17 @@ class ToolMixin(BaseMixin):
podField = self.getAppyType(name, className=obj.meta_type)
return podField.getToolInfo(obj.appy())
def getImageUrl(self, name, bg=False):
'''Gets the full URL of an image named p_name. If p_bg is False, the URL
is meant to be used as content for an img's "src" attribute. If p_bg
is True, the URL is meant to be used in a "style" attribute for
defining the background image of the current tag.'''
# If not extension is found in the image p_name, suppose it is a png.
if '.' not in name: name += '.png'
url = '%s/ui/%s' % (self.getPhysicalRoot(),absolute_url(), name)
if not bg: return url
return 'background-image: url(%s)' % url
def generateDocument(self):
'''Generates the document from field-related info. UID of object that
is the template target is given in the request.'''

View file

@ -64,38 +64,34 @@ class GroupDescr(Descr):
sharing the same appy.gen.Group instance, that some logged user can
see.'''
# PX that renders a group of fields
pxGroupedFields = Px('''<p>pxGroupedFields</p>''')
pxView = Px('''<p>pxGroupedFields</p>''')
# PX that renders a group of fields
pxGroupedSearches = Px('''
<x var="expanded=req.get(widget['labelId'], 'collapsed') == 'expanded'">
# PX that renders a group of searches
pxViewSearches = Px('''
<x var="expanded=req.get(field.labelId, 'collapsed') == 'expanded'">
<!-- Group name, prefixed by the expand/collapse icon -->
<div class="portletGroup">
<img style="cursor:pointer; margin-right: 3px" align=":dleft"
id=":'%s_img' % widget['labelId']"
src=":expanded and 'ui/collapse.gif' or 'ui/expand.gif'"
onclick=":'toggleCookie(&quot;%s&quot;)' % widget['labelId']"/>
<x if="not widget['translated']">:_(widget['labelId'])</x>
<x if="widget['translated']">:widget['translated']</x>
id=":'%s_img' % field.labelId"
src=":expanded and img('collapse.gif') or img('expand.gif')"
onclick=":'toggleCookie(%s)' % q(field.labelId)"/>
<x if="not field.translated">:_(field.labelId)</x>
<x if="field.translated">:field.translated</x>
</div>
<!-- Group content -->
<div var="display=expanded and 'display:block' or 'display:none'"
id=":widget['labelId']" style=":'padding-left: 10px; %s' % display">
<x for="searches in widget['widgets']">
<x for="searchElem in searches">
id=":field.labelId" style=":'padding-left: 10px; %s' % display">
<x for="searches in field.widgets">
<x for="elem in searches">
<!-- An inner group within this group -->
<x if="searchElem['type'] == 'group'">
<x var="widget=searchElem">:widget['px']</x>
</x>
<x if="elem['type'] == 'group'"
var2="field=elem">:field.pxViewSearches</x>
<!-- A search -->
<x if="searchElem['type'] != 'group'">
<x var="search=searchElem">:search['px']</x>
</x>
<x if="elem['type'] != 'group'" var2="search=elem">:search.pxView</x>
</x>
</x>
</div>
</x>
''')
</x>''')
def __init__(self, group, page, metaType, forSearch=False):
self.type = 'group'
@ -125,7 +121,7 @@ class GroupDescr(Descr):
# they will be rendered as a table.
self.widgets = [[]]
# PX to user for rendering this group.
self.px = forSearch and self.pxGroupedSearches or self.pxGroupedFields
self.px = forSearch and self.pxViewSearches or self.pxView
@staticmethod
def addWidget(groupDict, newWidget):
@ -178,20 +174,19 @@ class PhaseDescr(Descr):
editable=mayEdit and phase['pagesInfo'][aPage]['showOnEdit']">
<a if="editable and not locked"
href="contextObj.getUrl(mode='edit', page=aPage)">
<img src=":'%s/ui/edit.png' % appUrl" title=":_('object_edit')"/>
</a>
<img src=":img('edit')" title=":_('object_edit')"/></a>
<a if="editable and locked">
<img style="cursor: help"
var="lockDate=tool.formatDate(locked[1]);
lockMap={'user':ztool.getUserName(locked[0]), \
'date':lockDate};
lockMsg=_('page_locked', mapping=lockMap)"
src=":'%s/ui/locked.png' % appUrl" title=":lockMsg"/></a>
src=":img('locked')" title=":lockMsg"/></a>
<a if="editable and locked and user.has_role('Manager')">
<img style="cursor: pointer" title=":_('page_unlock')"
src=":'%s/ui/unlock.png' % appUrl"
onclick=":'onUnlockPage(&quot;%s&quot;,&quot;%s&quot;)' % \
(contextObj.UID(), aPage)"/></a>
src=":img('unlock')"
onclick=":'onUnlockPage(%s,%s)' % \
(q(contextObj.UID()), q(aPage))"/></a>
</x>
</div>
<!-- Next lines: links -->
@ -202,8 +197,7 @@ class PhaseDescr(Descr):
</x>
</x>
</td>
</tr>
''')
</tr>''')
def __init__(self, name, obj):
self.name = name
@ -266,14 +260,13 @@ class PhaseDescr(Descr):
class SearchDescr(Descr):
'''Describes a Search.'''
# PX for rendering a search.
pxSearch = Px('''
pxView = Px('''
<div class="portletSearch">
<a href=":'%s?className=%s&amp;search=%s' % \
(queryUrl, rootClass, search['name'])"
class=":search['name'] == currentSearch and 'portletCurrent' or ''"
title=":search['translatedDescr']">:search['translated']</a>
</div>
''')
</div>''')
def __init__(self, search, className, tool):
self.search = search

View file

@ -29,12 +29,11 @@ class ToolWrapper(AbstractWrapper):
</table>''', template=AbstractWrapper.pxTemplate, hook='content')
# Show on query list or grid, the field content for a given object.
pxQueryField = Px('''
<x><!-- Title -->
<x if="widget['name'] == 'title'">
<x var="navInfo='search.%s.%s.%d.%d' % (className, searchName, \
startNumber+currentNumber, \
totalNumber);
pxQueryField = Px('''<x>
<!-- Title -->
<x if="field.name == 'title'"
var2="navInfo='search.%s.%s.%d.%d' % \
(className, searchName, startNumber+currentNumber, totalNumber);
cssClass=obj.getCssFor('title')">
<x>::obj.getSupTitle(navInfo)</x>
<a href=":obj.getUrl(nav=navInfo, page=obj.getDefaultViewPage())"
@ -45,29 +44,21 @@ class ToolWrapper(AbstractWrapper):
<!-- Actions: edit, delete -->
<div if="obj.mayAct()">
<a var="navInfo='search.%s.%s.%d.%d' % (className, searchName, \
loop.obj.nb+1+startNumber, \
totalNumber)"
if="obj.mayEdit()"
<a if="obj.mayEdit()"
var2="navInfo='search.%s.%s.%d.%d' % \
(className, searchName, loop.obj.nb+1+startNumber, totalNumber)"
href=":obj.getUrl(mode='edit', page=obj.getDefaultEditPage(), \
nav=navInfo)">
<img src=":'%s/ui/edit.png' % appUrl"
title=":_('object_edit')"/></a><img
if="obj.mayDelete()" style="cursor:pointer"
src=":'%s/ui/delete.png' % appUrl"
<img src=":img('edit')" title=":_('object_edit')"/></a>
<img if="obj.mayDelete()" style="cursor:pointer" src=":img('delete')"
title=":_('object_delete')"
onClick="'onDeleteObject(&quot;%s&quot;)' % obj.UID()"/>
onClick="'onDeleteObject(%s)' % q(obj.UID())"/>
</div>
</x>
</x>
<!-- Any other field -->
<x if="widget['name'] != 'title'">
<x var="contextObj=obj;
layoutType='cell';
innerRef=True"
if="contextObj.showField(widget['name'], 'result')">
<!-- metal:f use-macro="context/ui/widgets/show/macros/field"/-->
</x>
<x if="field.name != 'title'">
<x var="contextObj=obj; layoutType='cell'; innerRef=True"
if="contextObj.showField(field.name, 'result')">field.pxView</x>
</x>
</x>''')
@ -76,28 +67,25 @@ class ToolWrapper(AbstractWrapper):
<table class="list" width="100%">
<!-- Headers, with filters and sort arrows -->
<tr if="showHeaders">
<x for="column in columns">
<th var="widget=column['field'];
sortable=ztool.isSortable(widget['name'], className, 'search');
filterable=widget.get('filterable', None)"
<th for="column in columns"
var2="widget=column['field'];
sortable=ztool.isSortable(field.name, className, 'search');
filterable=widget.filterable"
width=":column['width']" align=":column['align']">
<x>::ztool.truncateText(_(widget['labelId']))</x>
<x>::ztool.truncateText(_(field.labelId))</x>
<x>:self.pxSortAndFilter</x><x>:self.pxShowDetails</x>
</th>
</x>
</tr>
<!-- Results -->
<x for="obj in objs">
<tr var="odd=loop.obj.odd; currentNumber=currentNumber + 1"
<tr for="obj in objs"
var2="odd=loop.obj.odd; currentNumber=currentNumber + 1"
id="query_row" valign="top" class=":odd and 'even' or 'odd'">
<x for="column in columns">
<td var="widget=column['field']" id=":'field_%s' % widget['name']"
<td for="column in columns"
var2="widget=column['field']" id=":'field_%s' % field.name"
width=":column['width']"
align=":column['align']">:self.pxQueryField</td>
</x>
</tr>
</x>
</table>''')
# Show query results as a grid.
@ -110,9 +98,8 @@ class ToolWrapper(AbstractWrapper):
<td for="obj in row" width=":'%d%%' % (100/cols)" align="center"
style="padding-top: 25px">
<x var="currentNumber=currentNumber + 1"
for="column in columns">
<x var="widget = column['field']">:self.pxQueryField</x>
</x>
for="column in columns"
var2="widget = column['field']">:self.pxQueryField</x>
</td>
</tr>
</table>''')
@ -144,9 +131,9 @@ class ToolWrapper(AbstractWrapper):
totalNumber=queryResult['totalNumber'];
batchSize=queryResult['batchSize'];
ajaxHookId='queryResult';
navBaseCall='askQueryResult(&quot;%s&quot;,&quot;%s&quot;, \
&quot;%s&quot;, &quot;%s&quot;, **v**)' % (ajaxHookId, \
ztool.absolute_url(), className, searchName);
navBaseCall='askQueryResult(%s,%s,%s,%s,**v**)' % \
(q(ajaxHookId), q(ztool.absolute_url()), q(className), \
q(searchName));
newSearchUrl='%s/ui/search?className=%s%s' % \
(ztool.absolute_url(), className, refUrlPart);
showSubTitles=req.get('showSubTitles', 'true') == 'true';
@ -158,9 +145,7 @@ class ToolWrapper(AbstractWrapper):
layoutType='view'"
if="objs and widgets" align=":dright">
<tr>
<td var="contextObj=objs[0]" for="widget in widgets">
<!--use-macro="context/ui/widgets/show/macros/field"/>&nbsp;&nbsp;&nbsp;-->
</td>
<td var="contextObj=objs[0]" for="field in widgets">:field.pxView</td>
</tr>
</table>
@ -238,30 +223,25 @@ class ToolWrapper(AbstractWrapper):
<table width="100%">
<tr for="searchRow in ztool.getGroupedSearchFields(searchInfo)"
valign="top">
<x for="widget in searchRow">
<td var="scolspan=widget and widget['scolspan'] or 1"
<td for="field in searchRow"
var2="scolspan=field and field.scolspan or 1"
colspan=":scolspan"
width=":'%d%%' % ((100/searchInfo['nbOfColumns'])*scolspan)">
<x if="widget">
<x var="name=widget['name'];
widgetName='w_%s' % name;
macroPage=widget['type'].lower()">
<!--metal:call use-macro="python: getattr(appFolder.ui.widgets, macroPage).macros['search']"/-->
</x>
</x><br class="discreet"/>
<x if="field"
var2="name=field.name;
widgetName='w_%s' % name">field.pxSearch</x>
<br class="discreet"/>
</td>
</x>
</tr>
</table>
<!-- Submit button -->
<p align=":dright"><br/>
<input type="submit" class="button" value=":_('search_button')"
style=":'background-image: url(%s/ui/buttonSearch.png)'%appUrl"/>
style=":img('buttonSearch', bg=True)"/>
</p>
</form>
</x>
''', template=AbstractWrapper.pxTemplate, hook='content')
</x>''', template=AbstractWrapper.pxTemplate, hook='content')
pxImport = Px('''
<x var="className=req['className'];
@ -325,18 +305,17 @@ class ToolWrapper(AbstractWrapper):
<table class="list" width="100%">
<tr>
<th for="columnHeader in importElems[0]">
<img if="loop.columnHeader.nb == 0" src=":'%s/ui/eye.png' % appUrl"
<img if="loop.columnHeader.nb == 0" src=":img('eye')"
title="_('import_show_hide')" style="cursor:pointer"
onClick="toggleViewableElements()" align=":dleft" />
<x>:columnHeader</x>
</th>
<th></th>
<th width="20px"><img src=":'%s/ui/select_elems.png' % $appUrl"
title=":_('select_delesect')" onClick="toggleCheckboxes()"
style="cursor:pointer"/></th>
<th width="20px"><img src=":img('select_elems')" style="cursor:pointer"
title=":_('select_delesect')" onClick="toggleCheckboxes()"/></th>
</tr>
<x for="row in importElems[1]">
<tr var="alreadyImported=ztool.isAlreadyImported(className, row[0]);
<tr for="row in importElems[1]"
var2="alreadyImported=ztool.isAlreadyImported(className, row[0]);
allAreImported=allAreImported and alreadyImported;
odd=loop.row.odd"
id=":alreadyImported and 'importedElem' or 'notImportedElem'"
@ -346,16 +325,15 @@ class ToolWrapper(AbstractWrapper):
<td for="elem in row[1:]">:elem</td>
<td>
<input type="button" if="not alreadyImported"
onClick=":'importSingleElement(&quot;%s&quot;)' % row[0]"
onClick=":'importSingleElement(%s)' % q(row[0])"
value=":_('query_import')"/>
<x if="alreadyImported">:_('import_already')</x>
</td>
<td align="center">
<input if="not alreadyImported" type="checkbox" checked="checked"
id="cbElem" name="cbElem" value="row[0]" />
id="cbElem" name="cbElem" value="row[0]"/>
</td>
</tr>
</x>
<tr if="not importElems[1] or allAreImported">
<td colspan="15">:_('query_no_result')</td></tr>
</table>

View file

@ -32,35 +32,30 @@ class AbstractWrapper(object):
# --------------------------------------------------------------------------
# Icon for hiding/showing details below the title.
pxShowDetails = Px('''
<x if="ztool.subTitleIsUsed(className)">
<img if="widget['name'] == 'title'" style="cursor:pointer"
src=":'%s/ui/toggleDetails.png'%appUrl" onClick="toggleSubTitles()"/>
</x>''')
<img if="ztool.subTitleIsUsed(className) and (field.name == 'title')"
style="cursor:pointer" src=":img('toggleDetails')"
onClick="toggleSubTitles()"/>''')
# Displays up/down arrows in a table header column for sorting a given
# column. Requires variables "sortable", 'filterable' and 'fieldName'.
pxSortAndFilter = Px('''
<x var="fieldName=widget['name']">
# column. Requires variables "sortable", 'filterable' and 'field'.
pxSortAndFilter = Px('''<x>
<x if="sortable">
<img if="(sortKey != fieldName) or (sortOrder == 'desc')"
onclick=":navBaseCall.replace('**v**', '0,&quot;%s&quot;, \
&quot;asc&quot;, &quot;%s&quot;' % (fieldName,filterKey))"
src=":'%s/ui/sortDown.gif' % appUrl" style="cursor:pointer"/>
<img if="(sortKey != fieldName) or (sortOrder == 'asc')"
onClick=":navBaseCall.replace('**v**', '0,&quot;%s&quot;, \
&quot;desc&quot;, &quot;%s&quot;' % (fieldName,filterKey))"
src=":'%s/ui/sortUp.gif' % appUrl" style="cursor:pointer"/>
<img if="(sortKey != field.name) or (sortOrder == 'desc')"
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
(q(field.name), q('asc'), q(filterKey)))"
src=":img('sortDown.gif')" style="cursor:pointer"/>
<img if="(sortKey != field.name) or (sortOrder == 'asc')"
onClick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
(q(field.name), q('desc'), q(filterKey)))"
src=":img('sortUp.gif')" style="cursor:pointer"/>
</x>
<x if="filterable">
<input type="text" size="7"
id=":'%s_%s' % (ajaxHookId, fieldName)"
value=":filterKey == fieldName and filterValue or ''"/>
<img onClick=":navBaseCall.replace('**v**', '0, &quot;%s&quot;, \
&quot;%s&quot;, &quot;%s&quot;' % \
(sortKey, sortOrder, fieldName))"
src=":'%s/ui/funnel.png' % appUrl" style="cursor:pointer"/>
</x>
</x>''')
<input type="text" size="7" id=":'%s_%s' % (ajaxHookId, field.name)"
value=":filterKey == field.name and filterValue or ''"/>
<img onClick=":navBaseCall.replace('**v**', '0, %s,%s,%s' % \
(q(sortKey), q(sortOrder), q(field.name)))"
src=":img('funnel')" style="cursor:pointer"/>
</x></x>''')
# Buttons for navigating among a list of elements: next,back,first,last...
pxAppyNavigate = Px('''
@ -68,33 +63,31 @@ class AbstractWrapper(object):
<table class="listNavigate"
var="mustSortAndFilter=ajaxHookId == 'queryResult';
sortAndFilter=mustSortAndFilter and \
',&quot;%s&quot;, &quot;%s&quot;, &quot;%s&quot;' % \
(sortKey, sortOrder, filterKey) or ''">
',%s,%s,%s' % (q(sortKey),q(sortOrder),q(filterKey)) or ''">
<tr valign="middle">
<!-- Go to the first page -->
<td if="(startNumber != 0) and (startNumber != batchSize)"><img
style="cursor:pointer" src=":'%s/ui/arrowLeftDouble.png' % appUrl"
style="cursor:pointer" src=":img('arrowLeftDouble')"
title=":_('goto_first')"
onClick=":navBaseCall.replace('**v**', '0'+sortAndFilter)"/></td>
<!-- Go to the previous page -->
<td var="sNumber=startNumber - batchSize" if="startNumber != 0"><img
style="cursor:pointer" src=":'%s/ui/arrowLeftSimple.png' % appUrl"
style="cursor:pointer" src=":img('arrowLeftSimple')"
title=":_('goto_previous')"
onClick="navBaseCall.replace('**v**', \
str(sNumber)+sortAndFilter)"/></td>
<!-- Explain which elements are currently shown -->
<td class="discreet">&nbsp;
<x>:startNumber + 1</x><img src=":'%s/ui/to.png' % appUrl"/>
<x>:startNumber + 1</x><img src=":img('to')"/>
<x>:startNumber + len(objs)</x>&nbsp;<b>//</b>
<x>:totalNumber</x>&nbsp;&nbsp;</td>
<!-- Go to the next page -->
<td var="sNumber=startNumber + batchSize"
if="sNumber &lt; totalNumber"><img style="cursor:pointer"
src=":'%s/ui/arrowRightSimple.png' % appUrl"
title=":_('goto_next')"
src=":img('arrowRightSimple')" title=":_('goto_next')"
onClick=":navBaseCall.replace('**v**', \
str(sNumber)+sortAndFilter)"/></td>
@ -106,8 +99,7 @@ class AbstractWrapper(object):
sNumber= nbOfCountedPages * batchSize"
if="(startNumber != sNumber) and \
(startNumber != sNumber-batchSize)"><img style="cursor:pointer"
src=":'%s/ui/arrowRightDouble.png' % appUrl"
title=":_('goto_last')"
src=":img('arrowRightDouble')" title=":_('goto_last')"
onClick="navBaseCall.replace('**v**', \
str(sNumber)+sortAndFilter)"/></td>
</tr>
@ -117,8 +109,8 @@ class AbstractWrapper(object):
# Buttons for going to next/previous elements if this one is among bunch of
# referenced or searched objects. currentNumber starts with 1.
pxObjectNavigate = Px('''
<x if="req.get('nav', None)">
<div var="navInfo=ztool.getNavigationInfo();
<div if="req.get('nav', None)"
var2="navInfo=ztool.getNavigationInfo();
currentNumber=navInfo['currentNumber'];
totalNumber=navInfo['totalNumber'];
firstUrl=navInfo['firstUrl'];
@ -133,15 +125,15 @@ class AbstractWrapper(object):
var="gotoSource=_('goto_source');
goBack=backText and ('%s - %s' % (backText, gotoSource)) \
or gotoSource"
src=":'%s/ui/gotoSource.png' % appUrl" title=":goBack"/></a>
src=":img('gotoSource')" title=":goBack"/></a>
<!-- Go to the first page -->
<a if="firstUrl" href=":firstUrl"><img title=":_('goto_first')"
src=":'%s/ui/arrowLeftDouble.png' % appUrl"/></a>
src=":img('arrowLeftDouble')"/></a>
<!-- Go to the previous page -->
<a if="previousUrl" href=":previousUrl"><img title=":_('goto_previous')"
src=":'%s/ui/arrowLeftSimple.png' % appUrl"/></a>
src=":img('arrowLeftSimple')"/></a>
<!-- Explain which element is currently shown -->
<span class="discreet">&nbsp;
@ -151,29 +143,28 @@ class AbstractWrapper(object):
<!-- Go to the next page -->
<a if="nextUrl" href=":nextUrl"><img title=":_('goto_next')"
src=":'%s/ui/arrowRightSimple.png' % appUrl"/></a>
src=":img('arrowRightSimple')"/></a>
<!-- Go to the last page -->
<a if="lastUrl" href=":lastUrl"><img title=":_('goto_last')"
src=":'%s/ui/arrowRightDouble.png' % appUrl"/></a>
</div>
</x>''')
src=":img('arrowRightDouble')"/></a>
</div>''')
pxNavigationStrip = Px('''
<table width="100%" class="navigate">
<tr>
<!-- Breadcrumb -->
<td var="breadcrumb=contextObj.getBreadCrumb()" class="breadcrumb">
<x for="bc in breadcrumb">
<x var="nb=loop.bc.nb">
<img if="nb != 0" src=":'%s/ui/to.png' % appUrl"/>
<x for="bc in breadcrumb" var2="nb=loop.bc.nb">
<img if="nb != 0" src=":img('to')"/>
<!-- Display only the title of the current object -->
<span if="nb == len(breadcrumb)-1">:bc['title']</span>
<!-- Display a link for parent objects -->
<a if="nb != len(breadcrumb)-1" href=":bc['url']">:bc['title']</a>
</x>
</x>
</td>
<td align="right">:self.pxObjectNavigate</td>
<!-- Object navigation -->
<td align=":dright">:self.pxObjectNavigate</td>
</tr>
</table>''')
@ -181,8 +172,7 @@ class AbstractWrapper(object):
# PXs for graphical elements shown on every page
# --------------------------------------------------------------------------
# Global elements included in every page.
pxPagePrologue = Px('''
<div>
pxPagePrologue = Px('''<x>
<!-- Include type-specific CSS and JS. -->
<x if="cssJs">
<link for="cssFile in cssJs['css']" rel="stylesheet" type="text/css"
@ -227,7 +217,7 @@ class AbstractWrapper(object):
<input type="hidden" name="queryData"/>
<input type="hidden" name="customParams"/>
</form>
</div>''')
</x>''')
pxPageBottom = Px('''
<script type="text/javascript">initSlaves();</script>''')
@ -241,14 +231,13 @@ class AbstractWrapper(object):
rootClasses=ztool.getRootClasses();
phases=contextObj and contextObj.getAppyPhases() or None">
<x if="contextObj and phases and contextObj.mayNavigate()">
<table class="portletContent"
var="singlePhase=phases and (len(phases) == 1);
if="contextObj and phases and contextObj.mayNavigate()"
var2="singlePhase=phases and (len(phases) == 1);
page=req.get('page', '');
mayEdit=contextObj.mayEdit()">
<x for="phase in phases">:phase['px']</x>
</table>
</x>
<!-- One section for every searchable root class -->
<x for="rootClass in [rc for rc in rootClasses \
@ -279,18 +268,17 @@ class AbstractWrapper(object):
<!-- Create a new object from a web form -->
<input type="button" class="button"
if="userMayAdd and ('form' in createMeans)"
style=":'background-image: url(%s/ui/buttonAdd.png)' % appUrl"
value=":_('query_create')"
onclick=":'window.location=&quot;%s/do?action=Create&amp;' \
'className=%s&quot;' % (toolUrl, rootClass)"/>
style=":img('buttonAdd', bg=True)" value=":_('query_create')"
onclick=":'window.location=%s' % \
q('%s/do?action=Create&amp;className=%s' % \
(toolUrl, rootClass))"/>
<!-- Create object(s) by importing data -->
<input type="button" class="button"
if="userMayAdd and ('import' in createMeans)"
style=":'background-image: url(%s/ui/buttonImport.png)'% appUrl"
value=":_('query_import')"
onclick=":'window.location=&quot;%s/ui/import?' \
'className=%s&quot;' % (toolUrl, rootClass)"/>
style=":img('buttonImport', bg=True)" value=":_('query_import')"
onclick=":'window.location=%s' % \
q('%s/ui/import?className=%s' % (toolUrl, rootClass))"/>
</x>
<!-- Searches -->
@ -304,8 +292,8 @@ class AbstractWrapper(object):
<tr valign="bottom">
<td><input type="text" size="14" name="w_SearchableText"
class="inputSearch"/></td>
<td><input type="image" style="cursor:pointer"
src=":'%s/ui/search.gif' % appUrl"
<td>
<input type="image" style="cursor:pointer" src=":img('search.gif')"
title=":_('search_button')"/></td>
</tr>
</table>
@ -325,10 +313,8 @@ class AbstractWrapper(object):
<!-- Predefined searches -->
<x for="widget in searchInfo['searches']">
<x if="widget['type'] == 'group'">:widget['px']</x>
<x if="widget['type'] != 'group'">
<x var="search=widget">:search['px']</x>
</x>
<x if="widget['type']=='group'">:widget['px']</x>
<x if="widget['type']!='group'" var2="search=widget">:search['px']</x>
</x>
</div>
</x>
@ -336,16 +322,13 @@ class AbstractWrapper(object):
# The message that is shown when a user triggers an action.
pxMessage = Px('''
<x var="messages=ztool.consumeMessages()" if="messages">
<div class="message">
<div var="messages=ztool.consumeMessages()" if="messages" class="message">
<!-- The icon for closing the message -->
<img src=":'%s/ui/close.png' % appUrl" align=":dright"
style="cursor:pointer"
<img src=":img('close')" align=":dright" style="cursor:pointer"
onclick="this.parentNode.style.display='none'"/>
<!-- The message content -->
<x>::messages</x>
</div>
</x>''')
</div>''')
# The page footer.
pxFooter = Px('''
@ -371,6 +354,7 @@ class AbstractWrapper(object):
appName=ztool.getAppName(); _=ztool.translate;
req=ztool.REQUEST; resp=req.RESPONSE;
lang=ztool.getUserLanguage(); q=ztool.quote;
img = ztool.getImageUrl;
layoutType=ztool.getLayoutType();
contextObj=ztool.getPublishedObject(layoutType) or \
ztool.getHomeObject();
@ -414,8 +398,7 @@ class AbstractWrapper(object):
<span class="discreet">:_('workflow_comment')</span>
<textarea name="comment" cols="30" rows="3"></textarea>
<br/>
</div>
<br/>
</div><br/>
<input type="button" onclick="doConfirm()" value=":_('yes')"/>
<input type="button" onclick="closePopup('confirmActionPopup')"
value=":_('no')"/>
@ -444,13 +427,13 @@ class AbstractWrapper(object):
<tr class="top">
<!-- Top banner -->
<td var="bannerName=(dir == 'ltr') and 'banner' or 'bannerrtl'"
style=":'background-image: url(%s/ui/%s.jpg)'% (appUrl,bannerName)">
style=":img('%s.jpg' % bannerName, bg=True)">
<!-- Top links -->
<div style="margin-top: 4px" align=":dright">
<!-- Icon "home" -->
<a class="pageLink" href=":appUrl" title=": _('app_home')">
<img src=":'%s/ui/home.gif' % appUrl" style="margin-right: 3px"/>
<img src=":img('home.gif')" style="margin-right: 3px"/>
</a>
<!-- Additional links -->
@ -466,14 +449,13 @@ class AbstractWrapper(object):
style="cursor:pointer">:_('app_connect')</a>
<!-- Language selector -->
<x if="ztool.showLanguageSelector()">
<select var="languages=ztool.getLanguages();
<select if="ztool.showLanguageSelector()"
var2="languages=ztool.getLanguages();
defaultLanguage=languages[0]"
class="pageLink" onchange="switchLanguage(this)">
<option for="lg in languages" value=":lg"
selected=":lang == lg">:ztool.getLanguageName(lg)</option>
</select>
</x>
</div>
</td>
</tr>
@ -526,18 +508,18 @@ class AbstractWrapper(object):
<!-- Config -->
<a if="user.has_role('Manager')" href=":tool.url"
title=":_('%sTool' % appName)">
<img src=":'%s/ui/appyConfig.gif' % appUrl"/></a>
<img src=":img('appyConfig.gif')"/></a>
<!-- Additional icons -->
<x>:self.pxIcons</x>
<!-- Log out -->
<a href=":tool.url + '/performLogout'" title=":_('app_logout')">
<img src=":'%s/ui/logout.gif' % appUrl"/></a>
<img src=":img('logout.gif')"/></a>
</td>
<td class="userStripText" var="userInfo=ztool.getUserLine()"
align=":dright">
<span>:userInfo[0]</span>
<a if="userInfo[1]" href=":userInfo[1]">
<img src=":'%s/ui/edit.png' % appUrl"/></a>
<a if="userInfo[1]"
href=":userInfo[1]"><img src=":img('edit')"/></a>
</td>
</tr>
</table>
@ -578,16 +560,17 @@ class AbstractWrapper(object):
<x var="startNumber=req.get'startNumber', 0);
startNumber=int(startNumber);
batchSize=int(req.get('maxPerPage', 5));
historyInfo=contextObj.getHistory(startNumber,batchSize=batchSize);
objs=historyInfo['events'];
historyInfo=contextObj.getHistory(startNumber,batchSize=batchSize)"
if="historyInfo['events']"
var2="objs=historyInfo['events'];
totalNumber=historyInfo['totalNumber'];
ajaxHookId='appyHistory';
navBaseCall='askObjectHistory(&quot;%s&quot;, &quot;%s&quot;, \
%d, **v**)' % (ajaxHookId,contextObj.absolute_url(),batchSize)">
navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \
(q(ajaxHookId), q(contextObj.absolute_url()), batchSize)">
<!-- Table containing the history -->
<x if="objs">
<!-- Navigate between history pages -->
<x>:self.pxAppyNavigate</x>
<!-- History -->
<table width="100%" class="history">
<tr>
<th align=":dleft">:_('object_action')</th>
@ -595,8 +578,8 @@ class AbstractWrapper(object):
<th align=":dleft">:_('action_date')</th>
<th align=":dleft">:_('action_comment')</th>
</tr>
<x for="event in objs">
<tr var="odd=loop.event.odd;
<tr for="event in objs"
var2="odd=loop.event.odd;
rhComments=event.get('comments', None);
state=event.get('review_state', None);
action=event['action'];
@ -605,9 +588,9 @@ class AbstractWrapper(object):
<td if="isDataChange">
<x>:_('data_change')</x>
<img if="user.has_role('Manager')" style="cursor:pointer"
src=":'%s/ui/delete.png' % appUrl"
onclick=":'onDeleteEvent(&quot;%s&quot;, &quot;%s&quot;)' % \
(contextObj.UID(), event['time'])"/>
src=":img('delete')"
onclick=":'onDeleteEvent(%s,%s)' % \
(q(contextObj.UID()), q(event['time']))"/>
</td>
<td if="not isDataChange">:_(contextObj.getWorkflowLabel(action))</td>
<td var="actorId=event.get('actor')">
@ -627,25 +610,21 @@ class AbstractWrapper(object):
<th align=":dleft" width="30%">:_('modified_field')</th>
<th align=":dleft" width="70%">:_('previous_value')</th>
</tr>
<tr for="change in event['changes'].items()" valign="top">
<x var="appyType=contextObj.getAppyType(change[0], asDict=True)">
<tr for="change in event['changes'].items()" valign="top"
var2="appyType=contextObj.getAppyType(change[0], asDict=True)">
<td>::_(appyType['labelId'])</td>
<td>::change[1][0]</td>
</x>
</tr>
</table>
</td>
</tr>
</x>
</table>
</x>
</x>
''')
</x>''')
# Displays an object's transitions(s).
pxTransitions = Px('''
<x var="transitions=targetObj.getAppyTransitions()" if="transitions">
<form var="formId='trigger_%s' % targetObj.UID()" method="post"
<form var="transitions=targetObj.getAppyTransitions()" if="transitions"
var2="formId='trigger_%s' % targetObj.UID()" method="post"
id=":formId" action=":targetObj.absolute_url() + '/do'">
<input type="hidden" name="action" value="Trigger"/>
<input type="hidden" name="workflow_action"/>
@ -658,50 +637,44 @@ class AbstractWrapper(object):
<td align=":dright" for="transition in transitions">
<!-- Real button -->
<input type="button" class="button" if="transition['may_trigger']"
style=":'background-image: \
url(%s/ui/buttonTransition.png)' % appUrl"
style=":img('buttonTransition', bg=True)"
title=":transition['title']"
value=":ztool.truncateValue(transition['title'])"
onclick=":'triggerTransition(&quot;%s&quot;, &quot;%s&quot;, \
&quot;%s&quot;)' % (formId, transition['name'], \
transition['confirm'])"/>
onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \
q(transition['name']), q(transition['confirm']))"/>
<!-- Fake button, explaining why the transition can't be triggered -->
<input type="button" class="button" if="not transition['may_trigger']"
style=":'background-image: url(%s/ui/buttonFake.png); \
cursor: help' % appUrl"
style=":img('buttonFake', bg=True) + ';cursor: help'"
value=":ztool.truncateValue(transition['title'])"
title=":'%s: %s' % (transition['title'], \
transition['reason'])"/>
</td>
</tr>
</table>
</form>
</x>''')
</form>''')
# Displays header information about an object: title, workflow-related info,
# history...
pxObjectHeader = Px('''
<div var="hasHistory=contextObj.hasHistory();
<div if="not contextObj.isTemporary()"
var2="hasHistory=contextObj.hasHistory();
historyMaxPerPage=req.get('maxPerPage', 5);
historyExpanded=req.get('appyHistory','collapsed') == 'expanded';
creator=contextObj.Creator()"
if="not contextObj.isTemporary()">
creator=contextObj.Creator()">
<table width="100%" class="summary">
<tr>
<td colspan="2" class="by">
<!-- Plus/minus icon for accessing history -->
<x if="hasHistory">
<img style="cursor:pointer" onClick="toggleCookie('appyHistory')"
src="historyExpanded and 'ui/collapse.gif' or 'ui/expand.gif'"
<img style="cursor:pointer" onclick="toggleCookie('appyHistory')"
src="historyExpanded and img('collapse.gif') or img('expand.gif')"
align=":dleft" id="appyHistory_img"/>
<x>:_('object_history')</x> ||
</x>
<!-- Creator and last modification date -->
<x>:_('object_created_by')</x>
<x>:ztool.getUserName(creator)</x>
<x>:_('object_created_by')</x><x>:ztool.getUserName(creator)</x>
<!-- Creation and last modification dates -->
<x>:_('object_created_on')</x>
@ -726,18 +699,16 @@ class AbstractWrapper(object):
<td colspan="2">
<span id="appyHistory"
style=":historyExpanded and 'display:block' or 'display:none')">
<div var="ajaxHookId=contextObj.UID() + '_history'"
id=":ajaxHookId">
<script type="text/javascript">:'askObjectHistory(&quot;%s&quot;, \
&quot;%s&quot;, %d, 0)' % (ajaxHookId, contextObj.absolute_url(),\
<div var="ajaxHookId=contextObj.UID() + '_history'" id=":ajaxHookId">
<script type="text/javascript">:'askObjectHistory(%s,%s,%d,0)' % \
(q(ajaxHookId), q(contextObj.absolute_url()), \
historyMaxPerPage)</script>
</div>
</span>
</td>
</tr>
</table>
</div>
''')
</div>''')
# Shows the range of buttons (next, previous, save,...) and the workflow
# transitions.
@ -754,73 +725,61 @@ class AbstractWrapper(object):
<x if="isEdit">
<input type="button" class="button" value=":_('page_previous')"
onClick="submitAppyForm('previous')"
style=":'background-image: \
url(%s/ui/buttonPrevious.png)' % appUrl"/>
style=":img('buttonPrevious', bg=True)"/>
<input type="hidden" name="previousPage" value=":previousPage"/>
</x>
<!-- Button on the view page -->
<x if="not isEdit">
<input type="button" class="button" value=":_('page_previous')"
style=":'background-image: \
url(%s/ui/buttonPrevious.png)' % appUrl"
onclick=":'window.location=&quot;%s&quot;' % \
contextObj.getUrl(page=previousPage)"/>
</x>
<input if="not isEdit" type="button" class="button"
value=":_('page_previous')"
style=":img('buttonPrevious', bg=True)"
onclick=":'window.location=%s' % \
q(contextObj.getUrl(page=previousPage))"/>
</td>
<!-- Save -->
<td if="isEdit and pageInfo['showSave']">
<input type="button" class="button" onClick="submitAppyForm('save')"
style=":'background-image: url(%s/ui/buttonSave.png)' % appUrl"
value=":_('object_save')"/>
style=":img(buttonSave', bg=True)" value=":_('object_save')"/>
</td>
<!-- Cancel -->
<td if="isEdit and pageInfo['showCancel']">
<input type="button" class="button" onClick="submitAppyForm('cancel')"
style=":'background-image: url(%s/ui/buttonCancel.png)' % appUrl"
value=":_('object_cancel')"/>
style=":img('buttonCancel', bg=True)" value=":_('object_cancel')"/>
</td>
<x if="not isEdit">
<td var="locked=contextObj.isLocked(user, page);
<td if="not isEdit"
var2="locked=contextObj.isLocked(user, page);
editable=pageInfo['showOnEdit'] and contextObj.mayEdit()">
<!-- Edit -->
<input type="button" class="button" if="editable and not locked"
style=":'background-image: url(%s/ui/buttonEdit.png)' % appUrl"
value=":_('object_edit')"
onclick=":'window.location=&quot;%s&quot;' % \
contextObj.getUrl(mode='edit', page=page)"/>
style=":img('buttonEdit', bg=True)" value=":_('object_edit')"
onclick=":'window.location=%s' % \
q(contextObj.getUrl(mode='edit', page=page))"/>
<!-- Locked -->
<a if="editable and locked">
<img style="cursor: help"
var="lockDate=tool.formatDate(locked[1]);
lockMap={'user': tool.getUserName(locked[0]),\
'date': lockDate};
lockMap={'user':tool.getUserName(locked[0]),'date':lockDate};
lockMsg=_('page_locked', mapping=lockMap)"
src=":'%s/ui/lockedBig.png' % appUrl" title=":lockMsg"/></a>
src=":img('lockedBig')" title=":lockMsg"/></a>
</td>
</x>
<!-- Next -->
<td if="nextPage and pageInfo['showNext']">
<!-- Button on the edit page -->
<x if="isEdit">
<input type="button" class="button" onClick="submitAppyForm('next')"
style=":'background-image: url(%s/ui/buttonNext.png)' % appUrl"
value=":_('page_next')"/>
style=":img('buttonNext', bg=True)" value=":_('page_next')"/>
<input type="hidden" name="nextPage" value=":nextPage"/>
</x>
<!-- Button on the view page -->
<x if="not isEdit">
<input type="button" class="button"
style=":'background-image: url(%s/ui/buttonNext.png)' % appUrl"
value=":_('page_next')"
onclick=":'window.location=&quot;%s&quot;' % \
contextObj.getUrl(page=nextPage)"/>
</x>
<input if="not isEdit" type="button" class="button"
style=":img('buttonNext', bg=True)" value=":_('page_next')"
onclick=":'window.location=%s' % \
q(contextObj.getUrl(page=nextPage))"/>
</td>
<!-- Workflow transitions -->
@ -830,8 +789,8 @@ class AbstractWrapper(object):
<!-- Refresh -->
<td if="contextObj.isDebug()">
<a href="contextObj.getUrl(mode=layoutType, page=page, refresh='yes')">
<img title="Refresh" style="vertical-align:top"
src=":'%s/ui/refresh.png' % appUrl"/></a>
<img title="Refresh" style="vertical-align:top" src=":img('refresh')"/>
</a>
</td>
</tr>
</table>''')
@ -869,7 +828,7 @@ class AbstractWrapper(object):
cssJs=cssJs)">
<x>:self.pxPagePrologue</x>
<!-- Warn the user that the form should be left via buttons -->
<script type="text/javascript">
<script type="text/javascript"><![CDATA[
window.onbeforeunload = function(e){
theForm = document.getElementById('appyForm');
if (theForm.button.value == "") {
@ -877,7 +836,7 @@ class AbstractWrapper(object):
if (e) {e.returnValue = warn_leave_form;}
return warn_leave_form;
}
}
}]]>
</script>
<form id="appyForm" name="appyForm" method="post"
enctype="multipart/form-data"
@ -890,9 +849,8 @@ class AbstractWrapper(object):
<x var="tagId='pageLayout'">:self.pxLayoutedObject</x>
</form>
<script type="text/javascript"
if="confirmMsg">:'askConfirm(&quot;script&quot;, \
&quot;postConfirmedEditForm()&quot;, \
&quot;%s&quot;)' % confirmMsg</script>
if="confirmMsg">:'askConfirm(%s,%s,%s)' % \
(q('script'), q('postConfirmedEditForm()'), q(confirmMsg))</script>
<x>:self.pxPageBottom</x>
</x>''', template=pxTemplate, hook='content')

View file

@ -135,6 +135,9 @@ class IfAction(BufferAction):
the result or not.'''
def do(self, result, context, exprRes):
if exprRes:
if self.subAction:
self.subAction.execute(result, context)
else:
self.evaluateBuffer(result, context)
else:
if self.buffer.isMainElement(Cell.OD):

View file

@ -499,7 +499,7 @@ class MemoryBuffer(Buffer):
'buffer', None)
elif actionType == 'if':
action= IfAction('if', self, statement, elem, False, 'buffer', None)
elif actionType == 'var':
elif actionType in ('var', 'var2'):
variables = self._getVariables(statement)
action = VariablesAction('var', self, elem, False, variables,
'buffer', None)

View file

@ -44,7 +44,7 @@ class PxEnvironment(XmlEnvironment):
# ------------------------------------------------------------------------------
class PxParser(XmlParser):
'''PX parser that is specific for parsing PX data.'''
pxAttributes = ('var', 'for', 'if')
pxAttributes = ('var', 'for', 'if', 'var2')
# No-end tags
noEndTags = ('br', 'img', 'link', 'input')
noDumpTags = ('selected', 'checked', 'disabled', 'multiple')
@ -79,7 +79,7 @@ class PxParser(XmlParser):
# the main element or to a sub-element.
e.currentBuffer.addElement(elem, elemType='px')
if elem != 'x':
# Dump the start elements and its attributes. But as a preamble,
# Dump the start element and its attributes. But as a preamble,
# manage special attributes that could not be dumped at all, like
# "selected" or "checked".
hook = None