[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

@ -36,25 +36,22 @@ class Calendar(Field):
otherCalendars=field.getOtherCalendars(contextObj, preComputed)"
id=":ajaxHookId">
<script type="text/javascript">:'var %s_maxEventLength = %d;' % \
(field.name, field.maxEventLength)">
</script>
<script type="text/javascript">:'var %s_maxEventLength = %d;' % \
(field.name, field.maxEventLength)"></script>
<!-- Month chooser -->
<div style="margin-bottom: 5px"
var="fmt='%Y/%m/%d';
goBack=not startDate or (startDate.strftime(fmt) &lt; \
grid[0][0].strftime(fmt));
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)' % \
<!-- Month chooser -->
<div style="margin-bottom: 5px"
var="fmt='%Y/%m/%d';
goBack=not startDate or (startDate.strftime(fmt) &lt; \
grid[0][0].strftime(fmt));
goForward=not endDate or (endDate.strftime(fmt) &gt; \
grid[-1][-1].strftime(fmt))">
<!-- Go to the previous month -->
<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"
<!-- Go back to the default date -->
<input type="button" if="goBack or goForward"
var="fmt='%Y/%m';
label=(defaultDate.strftime(fmt)==today.strftime(fmt)) and \
'today' or 'goto_source'"
@ -62,170 +59,158 @@ 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"
onclick=":'askMonthView(%s, %s, %s, %s)' % (q(ajaxHookId), \
<!-- Go to the next month -->
<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>
<span>:month.split('/')[0]</span>
</div>
<span>:_('month_%s' % monthDayOne.aMonth())</span>
<span>:month.split('/')[0]</span>
</div>
<!-- Calendar month view -->
<table cellpadding="0" cellspacing="0" width="100%" class="list"
style="font-size: 95%"
var="rowHeight=int(field.height/float(len(grid)))">
<!-- 1st row: names of days -->
<tr height="22px">
<th for="dayName in field.getNamesOfDays(contextObj)"
width="14%">:dayName</th>
</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);
tooLate=endDate and not tooEarly and (date &gt; endDate);
inRange=not tooEarly and not tooLate;
cssClasses=field.getCellStyle(contextObj, date, today)">
<!-- Calendar month view -->
<table cellpadding="0" cellspacing="0" width="100%" class="list"
style="font-size: 95%"
var="rowHeight=int(field.height/float(len(grid)))">
<!-- 1st row: names of days -->
<tr height="22px">
<th for="dayName in field.getNamesOfDays(contextObj)"
width="14%">:dayName</th>
</tr>
<!-- The calendar in itself -->
<tr for="row in grid" valign="top" height=":rowHeight">
<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"
style="date.isCurrentDay() and 'font-weight:bold' or \
'font-weight:normal'"
class=":cssClasses"
onmouseover=":mayEdit and 'this.getElementsByTagName(\
%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 -->
<x if="mayCreate">
<img style="visibility:hidden; cursor:pointer"
var="info=field.getApplicableEventsTypesAt(contextObj, date, \
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"
onmouseover=":mayEdit and 'this.getElementsByTagName(\
%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 ''">
<span>:day</span>
<span if="day == 1">:_('month_%s_short' % date.aMonth())"></span>
<!-- Icon for adding an event -->
<x if="mayCreate">
<img style="visibility:hidden; cursor:pointer"
var="info=field.getApplicableEventsTypesAt(contextObj, date, \
allEventTypes, preComputed, True)"
if="info['eventTypes']"
src=":'%s/ui/plus.png' % appUrl"
onclick=":'openEventPopup(%s, %s, %s, null, %s, %s)' % \
(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"
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']">
<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">
<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>
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']))"/>
</x>
<!-- Icon for deleting an event -->
<img if="mayDelete" style="visibility:hidden; cursor:pointer"
src=":img('delete')"
onclick=":'openEventPopup(%s, %s, %s, %s, null, null)' % \
(q('del'), q(field.name), q(dayString), q(str(spansDays)))"/>
<!-- A single event is allowed for the moment -->
<div if="events" var2="eventType=events[0]['eventType']">
<span style="color: grey">:field.getEventName(contextObj, \
eventType)"></span>
</div>
<!-- Events from other calendars -->
<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>
<!-- Additional info -->
<x var="info=field.getAdditionalInfoAt(contextObj,date,preComputed)"
if="info">::info</x>
</td>
</x>
</x>
</tr>
</table>
</tr>
</table>
<!-- Popup for creating a calendar event -->
<div var="prefix='%s_newEvent' % field.name;
popupId=prefix + 'Popup'"
id=":popupId" class="popup" align="center">
<form id="prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" value=":field.name"/>
<input type="hidden" name="month" value=":month"/>
<input type="hidden" name="name" value=":field.name"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="createEvent"/>
<input type="hidden" name="day"/>
<!-- Popup for creating a calendar event -->
<div var="prefix='%s_newEvent' % field.name;
popupId=prefix + 'Popup'"
id=":popupId" class="popup" align="center">
<form id="prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" value=":field.name"/>
<input type="hidden" name="month" value=":month"/>
<input type="hidden" name="name" value=":field.name"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="createEvent"/>
<input type="hidden" name="day"/>
<!-- Choose an event type -->
<div align="center" style="margin-bottom: 3px">:_('which_event')"></div>
<select name="eventType">
<option value="">:_('choose_a_value')"></option>
<option for="eventType in allEventTypes"
value=":eventType">:field.getEventName(contextObj, eventType)">
</option>
</select><br/><br/>
<!--Span the event on several days -->
<div align="center" class="discreet" style="margin-bottom: 3px">
<span>:_('event_span')"></span>
<input type="text" size="3" name="eventSpan"/>
</div>
<input type="button"
value=":_('object_save')"
onclick=":'triggerCalendarEvent(%s, %s, %s, %s, \
%s_maxEventLength)' % (q('new'), q(ajaxHookId), \
q(field.name), q(objUrl), field.name)"/>
<input type="button"
value=":_('object_cancel')"
onclick=":'closePopup(%s)' % q(popupId)"/>
</form>
</div>
<!-- Choose an event type -->
<div align="center" style="margin-bottom: 3px">:_('which_event')"></div>
<select name="eventType">
<option value="">:_('choose_a_value')"></option>
<option for="eventType in allEventTypes"
value=":eventType">:field.getEventName(contextObj, eventType)">
</option>
</select><br/><br/>
<!--Span the event on several days -->
<div align="center" class="discreet" style="margin-bottom: 3px">
<span>:_('event_span')"></span>
<input type="text" size="3" name="eventSpan"/>
</div>
<input type="button"
value=":_('object_save')"
onclick=":'triggerCalendarEvent(%s, %s, %s, %s, \
%s_maxEventLength)' % (q('new'), q(ajaxHookId), \
q(field.name), q(objUrl), field.name)"/>
<input type="button"
value=":_('object_cancel')"
onclick=":'closePopup(%s)' % q(popupId)"/>
</form>
</div>
<!-- Popup for deleting a calendar event -->
<div var="prefix='%s_delEvent' % field.name;
popupId=prefix + 'Popup'"
id=":popupId" class="popup" align="center">
<form id=":prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" value=":field.name"/>
<input type="hidden" name="month" value=":month"/>
<input type="hidden" name="name" value=":field.name"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="deleteEvent"/>
<input type="hidden" name="day"/>
<!-- Popup for deleting a calendar event -->
<div var="prefix='%s_delEvent' % field.name;
popupId=prefix + 'Popup'"
id=":popupId" class="popup" align="center">
<form id=":prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" value=":field.name"/>
<input type="hidden" name="month" value=":month"/>
<input type="hidden" name="name" value=":field.name"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="deleteEvent"/>
<input type="hidden" name="day"/>
<div align="center" style="margin-bottom: 5px">_('delete_confirm')">
</div>
<div align="center" style="margin-bottom: 5px">_('delete_confirm')">
</div>
<!-- Delete successive events ? -->
<div class="discreet" style="margin-bottom: 10px"
id=":prefix + 'DelNextEvent'">
<input type="checkbox" name="deleteNext_cb"
id=":prefix + '_cb'"
onClick=":'toggleCheckbox(%s, %s)' % \
(q('%s_cb' % prefix), q('%s_hd' % prefix))"/>
<input type="hidden" id=":prefix + '_hd'" name="deleteNext"/>
<span>:_('del_next_events')"></span>
</div>
<input type="button" value=":_('yes')"
onClick=":'triggerCalendarEvent(%s, %s, %s, %s)' % \
(q('del'), q(ajaxHookId), q(field.name), q(objUrl))"/>
<input type="button" value=":_('no')"
onclick=":'closePopup(%s)' % q(popupId)"/>
</form>
</div>
</div>''')
<!-- Delete successive events ? -->
<div class="discreet" style="margin-bottom: 10px"
id=":prefix + 'DelNextEvent'">
<input type="checkbox" name="deleteNext_cb"
id=":prefix + '_cb'"
onClick=":'toggleCheckbox(%s, %s)' % \
(q('%s_cb' % prefix), q('%s_hd' % prefix))"/>
<input type="hidden" id=":prefix + '_hd'" name="deleteNext"/>
<span>:_('del_next_events')"></span>
</div>
<input type="button" value=":_('yes')"
onClick=":'triggerCalendarEvent(%s, %s, %s, %s)' % \
(q('del'), q(ajaxHookId), q(field.name), q(objUrl))"/>
<input type="button" value=":_('no')"
onclick=":'closePopup(%s)' % q(popupId)"/>
</form>
</div>
</div>''')
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,27 +28,23 @@ class Computed(Field):
value=contextObj.getFieldValue(name);
sync=True">:field.pxView</x>''')
pxView = pxCell = pxEdit = Px('''
<x>
<x if="sync">
<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">
<script type="text/javascript">:'askComputedField(%s, %s, %s)' % \
(q(ajaxHookId), q(contextObj.absolute_url()), q(name))">
</script>
</div>
</x>
</x>''')
pxView = pxCell = pxEdit = Px('''<x>
<x if="sync">
<x if="field.plainText">:value</x><x if="not field.plainText">::value></x>
</x>
<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>''')
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"/>
</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"/>
</x>''')
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show='view', page='main', group=None, layouts=None, move=0,

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"
selected="field.isSelected(contextObj, 'day', day, \
rawValue)">:zDay</option></x>
<option for="day in days"
var2="zDay=str(day).zfill(2)" value=":zDay"
selected="field.isSelected(contextObj, 'day', day, \
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"
selected="field.isSelected(contextObj, 'month', month, \
rawValue)">:zMonth</option></x>
<option for="month in months"
var2="zMonth=str(month).zfill(2)" value=":zMonth"
selected="field.isSelected(contextObj, 'month', month, \
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"
selected=":field.isSelected(contextObj, 'hour', hour, \
rawValue)">:zHour</option>
</x>
<option for="hour in hours"
var2="zHour=str(hour).zfill(2)" value=":zHour"
selected=":field.isSelected(contextObj, 'hour', hour, \
rawValue)">:zHour</option>
</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"
selected=":field.isSelected(contextObj, 'minute', minute,\
rawValue)">:zMinute</option></x>
<option for="minute in minutes"
var2="zMinute=str(minute).zfill(2)" value=":zMinute"
selected=":field.isSelected(contextObj, 'minute', minute,\
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

@ -31,26 +31,25 @@ class Float(Field):
</x>''')
pxEdit = Px('''
<input id=":name" name=":name" size=":field.width"
maxlength=":field.maxChars"
value=":inRequest and requestValue or value" type="text"/>''')
<input id=":name" name=":name" size=":field.width"
maxlength=":field.maxChars"
value=":inRequest and requestValue or value" type="text"/>''')
pxSearch = Px('''
<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*float' % widgetName">
<label lfor=":fromName">:_('search_from')"></label>
<input type="text" name=":fromName" maxlength=":field.maxChars"
value=":field.sdefault[0]" size=":field.swidth"/>
</x>
<!-- To -->
<x var="toName='%s_to' % name">
<label lfor=":toName">:_('search_to')</label>
<input type="text" name=":toName" maxlength=":field.maxChars"
value=":field.sdefault[1]" size="field.swidth"/>
</x><br/>
</x>''')
pxSearch = Px('''<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*float' % widgetName">
<label lfor=":fromName">:_('search_from')"></label>
<input type="text" name=":fromName" maxlength=":field.maxChars"
value=":field.sdefault[0]" size=":field.swidth"/>
</x>
<!-- To -->
<x var="toName='%s_to' % name">
<label lfor=":toName">:_('search_to')</label>
<input type="text" name=":toName" maxlength=":field.maxChars"
value=":field.sdefault[1]" size="field.swidth"/>
</x><br/>
</x>''')
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show=True, page='main', group=None, layouts=None, move=0,

View file

@ -32,22 +32,21 @@ class Integer(Field):
maxlength=":field.maxChars"
value=":inRequest and requestValue or value" type="text"/>''')
pxSearch = Px('''
<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*int' % widgetName">
<label lfor=":fromName">:_('search_from')</label>
<input type="text" name=":fromName" maxlength=":field.maxChars"
value=":field.sdefault[0]" size=":field.swidth"/>
</x>
<!-- To -->
<x var="toName='%s_to' % name">
<label lfor=":toName">:_('search_to')"></label>
<input type="text" name=":toName" maxlength=":field.maxChars"
value=":field.sdefault[1]" size=":field.swidth"/>
</x><br/>
</x>''')
pxSearch = Px('''<x>
<label>:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- From -->
<x var="fromName='%s*int' % widgetName">
<label lfor=":fromName">:_('search_from')</label>
<input type="text" name=":fromName" maxlength=":field.maxChars"
value=":field.sdefault[0]" size=":field.swidth"/>
</x>
<!-- To -->
<x var="toName='%s_to' % name">
<label lfor=":toName">:_('search_to')"></label>
<input type="text" name=":toName" maxlength=":field.maxChars"
value=":field.sdefault[1]" size=":field.swidth"/>
</x><br/>
</x>''')
def __init__(self, validator=None, multiplicity=(0,1), default=None,
show=True, page='main', group=None, layouts=None, move=0,

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];
tagCss='noStyle';
widgetName='%s*%d' % (field.name, rowIndex)">:field.pxView</x>
</td>
<td align="center" for="info in field.fields"
var2="field=info[1];
tagCss='noStyle';
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,17 +58,15 @@ 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>
<!-- This input makes Appy aware that this field is in the request -->
<input type="hidden" name=":name" value=""/><x>:field.pxTable</x>
</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>''')
pxSearch = ''

View file

@ -30,21 +30,18 @@ class Ogone(Field):
'''This field allows to perform payments with the Ogone (r) system.'''
urlTypes = ('accept', 'decline', 'exception', 'cancel')
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>
<!-- Submit image -->
<input type="image" id="submit2" name="submit2"
src=":'%s/ui/ogone.gif' % $appUrl" title=":_('custom_pay')"/>
</form>
</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">
<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=":img('ogone.gif')"
title=":_('custom_pay')"/>
</form>
</x>''')
pxEdit = pxSearch = ''

View file

@ -35,23 +35,19 @@ class Pod(Field):
'contact the system administrator.'
DELETE_TEMP_DOC_ERROR = 'A temporary document could not be removed. %s.'
pxView = pxCell = Px('''
<x>
<!-- Ask action -->
<x if="field.askAction">
<x var="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)"
onclick=":'generatePodDocument(%s, %s, %s, %s)' % \
(q(contextObj.UID()), q(name), q(podFormat), \
q(ztool.getQueryInfo()))"
title=":podFormat.capitalize()" style="cursor:pointer"/>
</x>''')
pxView = pxCell = Px('''<x>
<!-- Ask action -->
<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>
<img for="fmt in field.getToolInfo(contextObj.appy())[1]" src=":img(fmt)"
onclick=":'generatePodDocument(%s, %s, %s, %s)' % \
(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,37 +96,34 @@ 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(), \
field.name, field.pageName, 0, totalNumber);
formCall='window.location=%s' % \
q('%s/do?action=Create&amp;className=%s&amp;nav=%s' % \
(folder.absolute_url(), linkedPortalType, navInfo));
formCall=not field.addConfirm and formCall or \
'askConfirm(%s,%s,%s)' % (q('script'), q(formCall), \
q(addConfirmMsg));
noFormCall=navBaseCall.replace('**v**', \
'%d,%s' % (startNumber, q('CreateWithoutForm')));
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>''')
<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' % \
(folder.absolute_url(), linkedPortalType, navInfo));
formCall=not field.addConfirm and formCall or \
'askConfirm(%s,%s,%s)' % (q('script'), q(formCall), \
q(addConfirmMsg));
noFormCall=navBaseCall.replace('**v**', \
'%d,%s' % (startNumber, q('CreateWithoutForm')));
noFormCall=not field.addConfirm and noFormCall or \
'askConfirm(%s, %s, %s)' % (q('script'), q(noFormCall), \
q(addConfirmMsg))"
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,25 +158,21 @@ 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>
<tr valign="top">
<!-- If there is no object -->
<x if="not objs">
<td class="discreet">:_('no_ref')</td>
<td>:field.pxAdd</td>
</x>
<!-- If there is an object... -->
<x if="objs">
<x for="obj in objs">
<td var="includeShownInfo=True">:field.pxObjectTitle</td>
</x>
</x>
</tr>
</table>
</x>
<!-- 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">
<td class="discreet">:_('no_ref')</td>
<td>:field.pxAdd</td>
</x>
<!-- If there is an object... -->
<x if="objs">
<td for="obj in objs"
var2="includeShownInfo=True">:field.pxObjectTitle</td>
</x>
</tr>
</table>
<!-- 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(), \
@ -207,7 +195,7 @@ class Ref(Field):
<p class="discreet" if="not objs">:_('no_ref')</p>
<table if="objs" class=":innerRef and 'innerAppyTable' or ''"
width="100%">
width="100%">
<tr valign="bottom">
<td>
<!-- Show forward or backward reference(s) -->
@ -216,39 +204,32 @@ 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>
<x>:field.pxSortIcons</x>
<x var="className=linkedPortalType">:contextObj.appy(\
).pxShowDetails</x>
</x>
align="column['align']"
var2="field=column['field']">
<span>:_(field.labelId)</span>
<x>:field.pxSortIcons</x>
<x var="className=linkedPortalType">:contextObj.appy(\
).pxShowDetails</x>
</th>
</tr>
<x for="obj in objs">
<tr valign="top" var="odd=loop.obj.odd"
class=":odd and 'even' or 'odd'">
<td for="column in columns"
width=":column['width']" align=":column['align']">
<x var="field=column['field']">
<!-- The "title" field -->
<x if="python: field.name == 'title'">
<x>:field.pxObjectTitle</x>
<div if="obj.mayAct()">:field.pxObjectActions</div>
</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>
</td>
</tr>
</x>
<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']"
var2="field=column['field']">
<!-- The "title" field -->
<x if="python: field.name == 'title'">
<x>:field.pxObjectTitle</x>
<div if="obj.mayAct()">:field.pxObjectActions</div>
</x>
<!-- Any other field -->
<x if="field.name != 'title'">
<x var="contextObj=obj; layoutType='cell'; innerRef=True"
if="obj.showField(field.name, \
layoutType='result')">:field.pxView</x>
</x>
</td>
</tr>
</table>
</td>
</tr>
@ -256,56 +237,49 @@ class Ref(Field):
<!-- Appy (bottom) navigation -->
<x>:contextObj.appy().pxAppyNavigate</x>
</x>
</x>
</div>''')
pxView = pxCell = Px('''
<x var="x=req.set('fieldName', field.name)">:field.pxViewContent</x>''')
pxEdit = Px('''
<x if="field.link"
var="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 ''"
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()"
selected=":inRequest and (uid in requestValue) or \
(uid in uids)"
value=":uid">:field.getReferenceLabel(refObj)</option>
</x>
</select>
</x>''')
<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()"
name=":name" size="isMultiple and field.height or ''"
multiple="isMultiple and 'multiple' or ''">
<option value="" if="not isMultiple">:_('choose_a_value')"></option>
<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>
</select>''')
pxSearch = Px('''
<x>
<label lfor=":widgetName">:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- The "and" / "or" radio buttons -->
<x var="operName='o_%s' % name;
pxSearch = Px('''<x>
<label lfor=":widgetName">:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- The "and" / "or" radio buttons -->
<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"/>
<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>
</select>
</x>''')
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">
<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>''')
def __init__(self, klass=None, attribute=None, validator=None,
multiplicity=(0,1), default=None, add=False, addConfirm=False,

View file

@ -108,29 +108,28 @@ class String(Field):
isSelect=field.isSelect;
isMaster=field.slaves;
isOneLine=fmt in (0,3,4)">
<x if="isSelect">
<select var="possibleValues=field.getPossibleValues(contextObj, \
withTranslations=True, withBlankValue=True)"
name=":name" id=":name" class=":masterCss"
multiple=":isMultiple and 'multiple' or ''"
onchange=":isMaster and 'updateSlaves(this)' or ''"
size=":isMultiple and field.height or 1">
<option for="val in possibleValues" value=":val[0]"
selected=":field.isSelected(contextObj, val[0], rawValue)"
title=":val[1]">:ztool.truncateValue(val[1], field.width)">
</option>
</select>
</x>
<select if="isSelect"
var2="possibleValues=field.getPossibleValues(contextObj, \
withTranslations=True, withBlankValue=True)"
name=":name" id=":name" class=":masterCss"
multiple=":isMultiple and 'multiple' or ''"
onchange=":isMaster and 'updateSlaves(this)' or ''"
size=":isMultiple and field.height or 1">
<option for="val in possibleValues" value=":val[0]"
selected=":field.isSelected(contextObj, val[0], rawValue)"
title=":val[1]">:ztool.truncateValue(val[1], field.width)">
</option>
</select>
<x if="isOneLine and not isSelect">
<input id=":name" name=":name" size=":field.width"
maxlength=":field.maxChars"
value=":inRequest and requestValue or value"
style=":'text-transform:%s' % field.transform"
type=":(fmt == 3) and 'password' or 'text'"/>
<!-- Display a captcha if required -->
<span if="fmt == 4">:_('captcha_text', \
mapping=field.getCaptchaChallenge(req.SESSION))
</span>
<!-- Display a captcha if required -->
<span if="fmt == 4">:_('captcha_text', \
mapping=field.getCaptchaChallenge(req.SESSION))
</span>
</x>
<x if="fmt in (1,2)">
<textarea id=":name" name=":name" cols=":field.width"
@ -149,40 +148,37 @@ class String(Field):
<x if="not multipleValues">:field.pxView</x>
</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"
name=":'%s*string-%s' % (widgetName, field.transform)"
style=":'text-transform:%s' % field.transform"
value=":field.sdefault"/>
pxSearch = Px('''<x>
<label lfor="widgetName">:_(field.labelId)"></label><br/>&nbsp;&nbsp;
<!-- Show a simple search field for most String fields -->
<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"/>
<!-- 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 if="field.multiplicity[1] != 1"
var2="operName='o_%s' % name;
orName='%s_or' % operName;
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>
<!-- 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;
orName='%s_or' % operName;
andName='%s_and' % operName"
if="field.multiplicity[1] != 1">
<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 var="preSelected=field.sdefault"
name=":widgetName" size=":field.sheight" multiple="multiple">
<option for="v in field.getPossibleValues(ztool, withTranslations=True,\
<!-- The list of values -->
<select var="preSelected=field.sdefault"
name=":widgetName" size=":field.sheight" multiple="multiple">
<option for="v in field.getPossibleValues(ztool, withTranslations=True,\
withBlankValue=False, className=className)"
selected=":v[0] in preSelected" value=":v[0]"
title=":v[1]">ztool.truncateValue(v[1], field.swidth)</option>
</select>
</x><br/>
</x>''')
selected=":v[0] in preSelected" value=":v[0]"
title=":v[1]">ztool.truncateValue(v[1], field.swidth)</option>
</select>
</x><br/>
</x>''')
# Some predefined functions that may also be used as validators
@staticmethod