[pod,px] 'loop' variable allows to know if we are managing an even or odd elem via loop.<elem>.odd and loop.<elem>.even. [gen] In the process of migrating from ZPT (Zope Page Templates) to appy.px (Python Xml).

This commit is contained in:
Gaetan Delannay 2013-06-27 11:57:39 +02:00
parent e6cacd10dd
commit cb6fea7631
6 changed files with 595 additions and 35 deletions

View file

@ -44,6 +44,11 @@ class ToolMixin(BaseMixin):
tool = self.appy() tool = self.appy()
return tool.pxHome({'self': tool}) return tool.pxHome({'self': tool})
def query(self):
'''Returns the content of px ToolWrapper.pxQuery.'''
tool = self.appy()
return tool.pxQuery({'self': tool})
def getHomePage(self): def getHomePage(self):
'''Return the home page when a user hits the app.''' '''Return the home page when a user hits the app.'''
# If the app defines a method "getHomePage", call it. # If the app defines a method "getHomePage", call it.
@ -452,9 +457,9 @@ class ToolMixin(BaseMixin):
'''Guess the current layout type, according to actual URL.''' '''Guess the current layout type, according to actual URL.'''
actualUrl = self.REQUEST['ACTUAL_URL'] actualUrl = self.REQUEST['ACTUAL_URL']
res = '' res = ''
if actualUrl.endswith('/ui/view'): if actualUrl.endswith('/view'):
res = 'view' res = 'view'
elif actualUrl.endswith('/ui/edit') or actualUrl.endswith('/do'): elif actualUrl.endswith('/edit') or actualUrl.endswith('/do'):
res = 'edit' res = 'edit'
return res return res

View file

@ -203,6 +203,16 @@ class BaseMixin:
obj = createObject(tool.getPath('/temp_folder'), id, className, appName) obj = createObject(tool.getPath('/temp_folder'), id, className, appName)
return self.goto(obj.getUrl(**urlParams)) return self.goto(obj.getUrl(**urlParams))
def view(self):
'''Returns the view PX.'''
appySelf = self.appy()
return appySelf.pxView({'self': appySelf})
def edit(self):
'''Returns the edit PX.'''
appySelf = self.appy()
return appySelf.pxEdit({'self': appySelf})
def setLock(self, user, page): def setLock(self, user, page):
'''A p_user edits a given p_page on this object: we will set a lock, to '''A p_user edits a given p_page on this object: we will set a lock, to
prevent other users to edit this page at the same time.''' prevent other users to edit this page at the same time.'''

View file

@ -1,6 +1,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import re, os, os.path import re, os, os.path
from appy.shared.utils import normalizeText from appy.shared.utils import normalizeText
from appy.px import Px
# Function for creating a Zope object ------------------------------------------ # Function for creating a Zope object ------------------------------------------
def createObject(folder, id, className, appName, wf=True, noSecurity=False): def createObject(folder, id, className, appName, wf=True, noSecurity=False):
@ -53,15 +54,50 @@ def createObject(folder, id, className, appName, wf=True, noSecurity=False):
if wf: obj.notifyWorkflowCreated() if wf: obj.notifyWorkflowCreated()
return obj return obj
# Classes used by edit/view templates for accessing information ---------------- # Classes used by edit/view PXs for accessing information ----------------------
class Descr: class Descr:
'''Abstract class for description classes.''' '''Abstract class for description classes.'''
def get(self): return self.__dict__ def get(self): return self.__dict__
class GroupDescr(Descr): class GroupDescr(Descr):
'''Intermediary, on-the-fly-generated data structure that groups all fields
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>''')
# PX that renders a group of fields
pxGroupedSearches = Px('''
<x var="expanded=req.get(widget['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>
</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">
<!-- An inner group within this group -->
<x if="searchElem['type'] == 'group'">
<x var="widget=searchElem">:widget['px']</x>
</x>
<!-- A search -->
<x if="searchElem['type'] != 'group'">
<x var="search=searchElem">:search['px']</x>
</x>
</x>
</x>
</div>
</x>
''')
def __init__(self, group, page, metaType, forSearch=False): def __init__(self, group, page, metaType, forSearch=False):
'''Creates the data structure manipulated in ZPTs for p_group, the
Group instance used in the field definition.'''
self.type = 'group' self.type = 'group'
# All p_group attributes become self attributes. # All p_group attributes become self attributes.
for name, value in group.__dict__.iteritems(): for name, value in group.__dict__.iteritems():
@ -88,6 +124,8 @@ class GroupDescr(Descr):
# They will be stored by m_addWidget below as a list of lists because # They will be stored by m_addWidget below as a list of lists because
# they will be rendered as a table. # they will be rendered as a table.
self.widgets = [[]] self.widgets = [[]]
# PX to user for rendering this group.
self.px = forSearch and self.pxGroupedSearches or self.pxGroupedFields
@staticmethod @staticmethod
def addWidget(groupDict, newWidget): def addWidget(groupDict, newWidget):
@ -118,6 +156,55 @@ class GroupDescr(Descr):
groupDict['widgets'].append(newRow) groupDict['widgets'].append(newRow)
class PhaseDescr(Descr): class PhaseDescr(Descr):
'''Describes a phase.'''
pxPhase = Px('''
<tr var="singlePage=len(phase['pages']) == 1">
<td var="label='%s_phase_%s' % (contextObj.meta_type, phase['name'])">
<!-- The title of the phase -->
<div class="portletGroup"
if="not singlePhase and not singlePage">::_(label)</div>
<!-- The page(s) within the phase -->
<x for="aPage in phase['pages']">
<!-- First line: page name and icons -->
<div if="not (singlePhase and singlePage)"
class=":aPage==page and 'portletCurrent portletPage' or \
'portletPage'">
<a href=":contextObj.getUrl(page=aPage)">::_('%s_page_%s' % \
(contextObj.meta_type, aPage))</a>
<x var="locked=contextObj.isLocked(user, aPage);
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>
<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>
<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>
</x>
</div>
<!-- Next lines: links -->
<x var="links=phase['pagesInfo'][aPage].get('links')" if="links">
<div for="link in links">
<a href=":link['url']">:link['title']</a>
</div>
</x>
</x>
</td>
</tr>
''')
def __init__(self, name, obj): def __init__(self, name, obj):
self.name = name self.name = name
self.obj = obj self.obj = obj
@ -133,6 +220,7 @@ class PhaseDescr(Descr):
# phase if allowed by phase state. # phase if allowed by phase state.
self.previousPhase = None self.previousPhase = None
self.nextPhase = None self.nextPhase = None
self.px = self.pxPhase
def addPageLinks(self, appyType, obj): def addPageLinks(self, appyType, obj):
'''If p_appyType is a navigable Ref, we must add, within self.pagesInfo, '''If p_appyType is a navigable Ref, we must add, within self.pagesInfo,
@ -177,6 +265,16 @@ class PhaseDescr(Descr):
class SearchDescr(Descr): class SearchDescr(Descr):
'''Describes a Search.''' '''Describes a Search.'''
# PX for rendering a search.
pxSearch = 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>
''')
def __init__(self, search, className, tool): def __init__(self, search, className, tool):
self.search = search self.search = search
self.name = search.name self.name = search.name
@ -200,6 +298,7 @@ class SearchDescr(Descr):
self.translatedDescr = tool.translate(labelDescr) self.translatedDescr = tool.translate(labelDescr)
else: else:
self.translatedDescr = '' self.translatedDescr = ''
self.px = self.pxSearch
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
upperLetter = re.compile('[A-Z]') upperLetter = re.compile('[A-Z]')

View file

@ -26,8 +26,191 @@ class ToolWrapper(AbstractWrapper):
<tr valign="middle"> <tr valign="middle">
<td align="center">::_('front_page_text')</td> <td align="center">::_('front_page_text')</td>
</tr> </tr>
</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);
cssClass=obj.getCssFor('title')">
<x>::obj.getSupTitle(navInfo)</x>
<a href=":obj.getUrl(nav=navInfo, page=obj.getDefaultViewPage())"
if="enableLinks" class=":cssClass">:obj.Title()</a><span
if="not enableLinks" class=":cssClass">:obj.Title()</span><span
style=":showSubTitles and 'display:inline' or 'display:none'"
name="subTitle">::obj.getSubTitle()</span>
<!-- 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()"
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"
title=":_('object_delete')"
onClick="'onDeleteObject(&quot;%s&quot;)' % 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>
</x>''')
# Show query results as a list.
pxQueryResultList = Px('''
<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)"
width=":column['width']" align=":column['align']">
<x>::ztool.truncateText(_(widget['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"
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']"
width=":column['width']"
align=":column['align']">:self.pxQueryField</td>
</x>
</tr>
</x>
</table>''')
# Show query results as a grid.
pxQueryResultGrid = Px('''
<table width="100%"
var="modeElems=resultMode.split('_');
cols=(len(modeElems)==2) and int(modeElems[1]) or 4;
rows=ztool.splitList(objs, cols)">
<tr for="row in rows" valign="middle">
<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>
</td>
</tr>
</table>''')
# Show paginated query results as a list or grid.
pxQueryResult = Px('''
<div id="queryResult"
var="_=ztool.translate;
className=req['className'];
refInfo=ztool.getRefInfo();
refObject=refInfo[0];
refField=refInfo[1];
refUrlPart=refObject and ('&amp;ref=%s:%s' % (refObject.UID(), \
refField)) or '';
startNumber=req.get('startNumber', '0');
startNumber=int(startNumber);
searchName=req.get('search', '');
searchDescr=ztool.getSearch(className, searchName, descr=True);
sortKey=req.get('sortKey', '');
sortOrder=req.get('sortOrder', 'asc');
filterKey=req.get('filterKey', '');
filterValue=req.get('filterValue', '');
queryResult=ztool.executeQuery(className, \
search=searchDescr['search'], startNumber=startNumber, \
remember=True, sortBy=sortKey, sortOrder=sortOrder, \
filterKey=filterKey, filterValue=filterValue, \
refObject=refObject, refField=refField);
objs=queryResult['objects'];
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);
newSearchUrl='%s/ui/search?className=%s%s' % \
(ztool.absolute_url(), className, refUrlPart);
showSubTitles=req.get('showSubTitles', 'true') == 'true';
resultMode=ztool.getResultMode(className)">
<x if="objs">
<!-- Display here POD templates if required. -->
<table var="widgets=ztool.getResultPodFields(className);
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>
</tr>
</table> </table>
''', template=AbstractWrapper.pxTemplate, hook='content')
<!-- The title of the search -->
<p>
<x>:searchDescr['translated']</x>
(<x>:totalNumber</x>)
<x if="showNewSearch and (searchName == 'customSearch')">&nbsp;&mdash;
&nbsp;<i><a href=":newSearchUrl">:_('search_new')</a></i>
</x>
</p>
<table width="100%">
<tr>
<!-- Search description -->
<td if="searchDescr['translatedDescr']">
<span class="discreet">:searchDescr['translatedDescr']</span><br/>
</td>
<!-- Appy (top) navigation -->
<td align=":dright" width="25%"><x>:self.pxAppyNavigate</x></td>
</tr>
</table>
<!-- Results, as a list or grid -->
<x var="columnLayouts=ztool.getResultColumnsLayouts(className, refInfo);
columns=objs[0].getColumnsSpecifiers(columnLayouts, dir);
currentNumber=0">
<x if="resultMode == 'list'">:self.pxQueryResultList</x>
<x if="resultMode != 'list'">:self.pxQueryResultGrid</x>
</x>
<!-- Appy (bottom) navigation -->
<x>:self.pxAppyNavigate</x>
</x>
<x if="not objs">
<x>:_('query_no_result')></x>
<x if="showNewSearch and (searchName == 'customSearch')"><br/>
<i class="discreet"><a href=":newSearchUrl">:_('search_new')</a></i></x>
</x>
</div>''')
pxQuery = Px('''
<x var="className=req['className'];
searchName=req.get('search', '');
cssJs=None;
showNewSearch=True;
showHeaders=True;
enableLinks=True">
<x>:self.pxPagePrologue</x><x>:self.pxQueryResult</x>
</x>''', template=AbstractWrapper.pxTemplate, hook='content')
def validPythonWithUno(self, value): def validPythonWithUno(self, value):
'''This method represents the validator for field unoEnabledPython.''' '''This method represents the validator for field unoEnabledPython.'''

View file

@ -27,8 +27,210 @@ class AbstractWrapper(object):
'''Any real Appy-managed Zope object has a companion object that is an '''Any real Appy-managed Zope object has a companion object that is an
instance of this class.''' instance of this class.'''
pxPhases = Px('''<p>Phases</p> # --------------------------------------------------------------------------
''') # Navigation-related PXs
# --------------------------------------------------------------------------
# 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>''')
# 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']">
<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"/>
</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>''')
# Buttons for navigating among a list of elements: next,back,first,last...
pxAppyNavigate = Px('''
<div if="totalNumber &gt; batchSize" align=":dright">
<table class="listNavigate"
var="mustSortAndFilter=ajaxHookId == 'queryResult';
sortAndFilter=mustSortAndFilter and \
',&quot;%s&quot;, &quot;%s&quot;, &quot;%s&quot;' % \
(sortKey, sortOrder, 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"
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"
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 + 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')"
onClick=":navBaseCall.replace('**v**', \
str(sNumber)+sortAndFilter)"/></td>
<!-- Go to the last page -->
<td var="lastPageIsIncomplete=totalNumber % batchSize;
nbOfCompletePages=totalNumber/batchSize;
nbOfCountedPages=lastPageIsIncomplete and \
nbOfCompletePages or nbOfCompletePages-1;
sNumber= nbOfCountedPages * batchSize"
if="(startNumber != sNumber) and \
(startNumber != sNumber-batchSize)"><img style="cursor:pointer"
src=":'%s/ui/arrowRightDouble.png' % appUrl"
title=":_('goto_last')"
onClick="navBaseCall.replace('**v**', \
str(sNumber)+sortAndFilter)"/></td>
</tr>
</table>
</div>''')
# 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();
currentNumber=navInfo['currentNumber'];
totalNumber=navInfo['totalNumber'];
firstUrl=navInfo['firstUrl'];
previousUrl=navInfo['previousUrl'];
nextUrl=navInfo['nextUrl'];
lastUrl=navInfo['lastUrl'];
sourceUrl=navInfo['sourceUrl'];
backText=navInfo['backText']">
<!-- Go to the source URL (search or referred object) -->
<a if="sourceUrl" href=":sourceUrl"><img
var="gotoSource=_('goto_source');
goBack=backText and ('%s - %s' % (backText, gotoSource)) \
or gotoSource"
src=":'%s/ui/gotoSource.png' % appUrl" title=":goBack"/></a>
<!-- Go to the first page -->
<a if="firstUrl" href=":firstUrl"><img title=":_('goto_first')"
src=":'%s/ui/arrowLeftDouble.png' % appUrl"/></a>
<!-- Go to the previous page -->
<a if="previousUrl" href=":previousUrl"><img title=":_('goto_previous')"
src=":'%s/ui/arrowLeftSimple.png' % appUrl"/></a>
<!-- Explain which element is currently shown -->
<span class="discreet">&nbsp;
<x>:currentNumber</x>&nbsp;<b>//</b>
<x>:totalNumber</x>&nbsp;&nbsp;
</span>
<!-- Go to the next page -->
<a if="nextUrl" href=":nextUrl"><img title=":_('goto_next')"
src=":'%s/ui/arrowRightSimple.png' % appUrl"/></a>
<!-- Go to the last page -->
<a if="lastUrl" href=":lastUrl"><img title=":_('goto_last')"
src=":'%s/ui/arrowRightDouble.png' % appUrl"/></a>
</div>
</x>''')
pxNavigationStrip = Px('''
<table width="100%" class="navigate">
<tr>
<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"/>
<!-- 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>
</tr>
</table>''')
# --------------------------------------------------------------------------
# PXs for graphical elements shown on every page
# --------------------------------------------------------------------------
# Global elements included in every page.
pxPagePrologue = Px('''
<div>
<!-- Include type-specific CSS and JS. -->
<x if="cssJs">
<link for="cssFile in cssJs['css']" rel="stylesheet" type="text/css"
href=":'%s/ui/%s' % (appUrl, cssFile)"/>
<script for="jsFile in cssJs['js']" type="text/javascript"
src=":'%s/ui/%s' % (appUrl, jsFile)"></script></x>
<!-- Javascript messages -->
<script type="text/javascript">:ztool.getJavascriptMessages()</script>
<!-- Global form for deleting an object -->
<form id="deleteForm" method="post" action="do">
<input type="hidden" name="action" value="Delete"/>
<input type="hidden" name="objectUid"/>
</form>
<!-- Global form for deleting an event from an object's history -->
<form id="deleteEventForm" method="post" action="do">
<input type="hidden" name="action" value="DeleteEvent"/>
<input type="hidden" name="objectUid"/>
<input type="hidden" name="eventTime"/>
</form>
<!-- Global form for unlinking an object -->
<form id="unlinkForm" method="post" action="do">
<input type="hidden" name="action" value="Unlink"/>
<input type="hidden" name="sourceUid"/>
<input type="hidden" name="fieldName"/>
<input type="hidden" name="targetUid"/>
</form>
<!-- Global form for unlocking a page -->
<form id="unlockForm" method="post" action="do">
<input type="hidden" name="action" value="Unlock"/>
<input type="hidden" name="objectUid"/>
<input type="hidden" name="pageName"/>
</form>
<!-- Global form for generating a document from a pod template -->
<form id="podTemplateForm" name="podTemplateForm" method="post"
action=":ztool.absolute_url() + '/generateDocument'">
<input type="hidden" name="objectUid"/>
<input type="hidden" name="fieldName"/>
<input type="hidden" name="podFormat"/>
<input type="hidden" name="askAction"/>
<input type="hidden" name="queryData"/>
<input type="hidden" name="customParams"/>
</form>
</div>''')
pxPageBottom = Px('''
<script type="text/javascript">initSlaves();</script>''')
pxPortlet = Px(''' pxPortlet = Px('''
<x var="toolUrl=tool.url; <x var="toolUrl=tool.url;
@ -39,12 +241,18 @@ class AbstractWrapper(object):
rootClasses=ztool.getRootClasses(); rootClasses=ztool.getRootClasses();
phases=contextObj and contextObj.getAppyPhases() or None"> phases=contextObj and contextObj.getAppyPhases() or None">
<x if="contextObj and \ <x if="contextObj and phases and contextObj.mayNavigate()">
phases and contextObj.mayNavigate()">:self.pxPhases</x> <table class="portletContent"
var="singlePhase=phases and (len(phases) == 1);
page=req.get('page', 'main');
mayEdit=contextObj.mayEdit()">
<x for="phase in phases">:phase['px']</x>
</table>
</x>
<!-- One section for every searchable root class --> <!-- One section for every searchable root class -->
<x for="rootClass in [rc for rc in rootClasses \ <x for="rootClass in [rc for rc in rootClasses \
if tool.userMaySearch(rc)]"> if ztool.userMaySearch(rc)]">
<!-- A separator if required --> <!-- A separator if required -->
<div class="portletSep" var="nb=loop.rootClass.nb" <div class="portletSep" var="nb=loop.rootClass.nb"
@ -106,7 +314,7 @@ class AbstractWrapper(object):
<!-- Advanced search --> <!-- Advanced search -->
<div var="highlighted=(currentClass == rootClass) and \ <div var="highlighted=(currentClass == rootClass) and \
(currentPage == 'search')" (currentPage == 'search')"
class="highlighted and 'portletSearch portletCurrent' or \ class=":highlighted and 'portletSearch portletCurrent' or \
'portletSearch'" 'portletSearch'"
align=":dright"> align=":dright">
<a var="text=_('search_title')" style="font-size: 88%" <a var="text=_('search_title')" style="font-size: 88%"
@ -117,19 +325,14 @@ class AbstractWrapper(object):
<!-- Predefined searches --> <!-- Predefined searches -->
<x for="widget in searchInfo['searches']"> <x for="widget in searchInfo['searches']">
<x if="widget['type'] == 'group'"> <x if="widget['type'] == 'group'">:widget['px']</x>
<!--metal:s use-macro="app/ui/portlet/macros/group"/-->
</x>
<x if="widget['type'] != 'group'"> <x if="widget['type'] != 'group'">
<x var="search=widget"> <x var="search=widget">:search['px']</x>
<!--metal:s use-macro="app/ui/portlet/macros/search"/-->
</x>
</x> </x>
</x> </x>
</div> </div>
</x> </x>
</x> </x>''')
''')
pxMessage = Px(''' pxMessage = Px('''
<x var="messages=ztool.consumeMessages()" if="messages"> <x var="messages=ztool.consumeMessages()" if="messages">
@ -141,16 +344,14 @@ class AbstractWrapper(object):
<!-- The message content --> <!-- The message content -->
<x>::messages</x> <x>::messages</x>
</div> </div>
</x> </x>''')
''')
pxFooter = Px(''' pxFooter = Px('''
<table cellpadding="0" cellspacing="0" width="100%" class="footer"> <table cellpadding="0" cellspacing="0" width="100%" class="footer">
<tr> <tr>
<td align=":dright">Made with <td align=":dright">Made with
<a href="http://appyframework.org" target="_blank">Appy</a></td></tr> <a href="http://appyframework.org" target="_blank">Appy</a></td></tr>
</table> </table>''')
''')
pxTemplate = Px(''' pxTemplate = Px('''
<html var="tool=self.tool; ztool=tool.o; user=tool.user; <html var="tool=self.tool; ztool=tool.o; user=tool.user;
@ -310,8 +511,8 @@ class AbstractWrapper(object):
<td> <td>
<!-- Config --> <!-- Config -->
<a if="user.has_role('Manager')" href=":tool.url" <a if="user.has_role('Manager')" href=":tool.url"
title="_('%sTool' % appName)"> title=":_('%sTool' % appName)">
<img src="'%s/ui/appyConfig.gif' % appUrl"/></a> <img src=":'%s/ui/appyConfig.gif' % appUrl"/></a>
<!-- Additional icons from icons.pt --> <!-- Additional icons from icons.pt -->
<!--metal:call use-macro="app/ui/icons/macros/icons"/--> <!--metal:call use-macro="app/ui/icons/macros/icons"/-->
<!-- Log out --> <!-- Log out -->
@ -334,9 +535,7 @@ class AbstractWrapper(object):
<!-- The navigation strip --> <!-- The navigation strip -->
<tr if="contextObj and (layoutType == 'view')"> <tr if="contextObj and (layoutType == 'view')">
<td> <td>:self.pxNavigationStrip</td>
<!--metal:navigate use-macro="app/ui/navigate/macros/navigationStrip"/-->
</td>
</tr> </tr>
<tr> <tr>
<td> <td>
@ -355,8 +554,68 @@ class AbstractWrapper(object):
<tr><td>:self.pxFooter</td></tr> <tr><td>:self.pxFooter</td></tr>
</table> </table>
</body> </body>
</html> </html>''', prologue=Px.xhtmlPrologue)
''', prologue=Px.xhtmlPrologue)
# PX for viewing an object -------------------------------------------------
pxLayoutedObject = Px('''<p>Layouted object</p>''')
pxView = Px('''
<x var="x=contextObj.allows('View', raiseError=True);
errors=req.get('errors', {});
layout=contextObj.getPageLayout(layoutType);
phaseInfo=contextObj.getAppyPhases(currentOnly=True, \
layoutType='view');
phase=phaseInfo['name'];
cssJs={};
page=req.get('page',None) or contextObj.getDefaultViewPage();
x=contextObj.removeMyLock(user, page);
groupedWidgets=contextObj.getGroupedAppyTypes(layoutType, page, \
cssJs=cssJs)">
<x>:self.pxPagePrologue</x>
<x var="tagId='pageLayout'">:self.pxLayoutedObject</x>
<x>:self.pxPageBottom</x>
</x>''', template=pxTemplate, hook='content')
pxEdit = Px('''
<x var="x=contextObj.allows('Modify portal content', raiseError=True);
errors=req.get('errors', None) or {};
layout=contextObj.getPageLayout(layoutType);
cssJs={};
phaseInfo=contextObj.getAppyPhases(currentOnly=True, \
layoutType=layoutType);
phase=phaseInfo['name'];
page=req.get('page', None) or contextObj.getDefaultEditPage();
x=contextObj.setLock(user, page);
confirmMsg=req.get('confirmMsg', None);
groupedWidgets=contextObj.getGroupedAppyTypes(layoutType, page, \
cssJs=cssJs)">
<x>:self.pxPagePrologue</x>
<!-- Warn the user that the form should be left via buttons -->
<script type="text/javascript">
window.onbeforeunload = function(e){
theForm = document.getElementById('appyForm');
if (theForm.button.value == "") {
var e = e || window.event;
if (e) {e.returnValue = warn_leave_form;}
return warn_leave_form;
}
}
</script>
<form id="appyForm" name="appyForm" method="post"
enctype="multipart/form-data"
action=":contextObj.absolute_url()+'/do'">
<input type="hidden" name="action" value="Update"/>
<input type="hidden" name="button" value=""/>
<input type="hidden" name="page" value=":page"/>
<input type="hidden" name="nav" value=":req.get('nav', None)"/>
<input type="hidden" name="confirmed" value="False"/>
<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>
<x>:self.pxPageBottom</x>
</x>''', template=pxTemplate, hook='content')
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Class methods # Class methods

View file

@ -175,10 +175,12 @@ class ForAction(BufferAction):
# the loop # the loop
# * curLoop.nb gives the index (starting at 0) if the currently # * curLoop.nb gives the index (starting at 0) if the currently
# walked element. # walked element.
# * curLoop.first is True if the currently walkded element is the # * curLoop.first is True if the currently walked element is the
# first one. # first one.
# * curLoop.last is True if the currently walkded element is the # * curLoop.last is True if the currently walked element is the
# last one. # last one.
# * curLoop.odd is True if the currently walked element is odd
# * curLoop.even is True if the currently walked element is even
# For example, if you have a "for" statement like this: # For example, if you have a "for" statement like this:
# for elem in myListOfElements # for elem in myListOfElements
# Within the part of the ODT document impacted by this statement, you # Within the part of the ODT document impacted by this statement, you
@ -231,6 +233,8 @@ class ForAction(BufferAction):
loop.nb = i loop.nb = i
loop.first = i == 0 loop.first = i == 0
loop.last = i == (loop.length-1) loop.last = i == (loop.length-1)
loop.even = (i%2)==0
loop.odd = not loop.even
context[self.iter] = item context[self.iter] = item
# Cell: add a new row if we are at the end of a row # Cell: add a new row if we are at the end of a row
if isCell and (currentColIndex == nbOfColumns): if isCell and (currentColIndex == nbOfColumns):