Improved navigation between pages.

This commit is contained in:
Gaetan Delannay 2010-01-08 18:03:59 +01:00
parent 24d0370892
commit c37fa93858
3 changed files with 36 additions and 21 deletions

View file

@ -91,6 +91,7 @@ class AbstractMixin:
the "final" object in the database. If the object is not a temporary
one, this method updates its fields in the database.'''
rq = self.REQUEST
# Dict for storing validation errors
errors = {}
errorMessage = self.translate(
'Please correct the indicated errors.', domain='plone')
@ -101,11 +102,10 @@ class AbstractMixin:
# Go back to the Plone site (no better solution at present).
urlBack = self.portal_url.getPortalObject().absolute_url()
else:
urlBack = '%s/skyn/view?phase=%s&pageName=%s' % (
self.absolute_url(), rq.get('phase'), rq.get('pageName'))
urlBack = '%s/skyn/view' % self.absolute_url()
self.plone_utils.addPortalMessage(
self.translate('Changes canceled.', domain='plone'))
return self.goto(urlBack)
return self.goto(urlBack, True)
# Trigger field-specific validation
self.validate(REQUEST=rq, errors=errors, data=1, metadata=0)
@ -128,9 +128,8 @@ class AbstractMixin:
# Go to the consult view for this object
obj.plone_utils.addPortalMessage(
obj.translate('Changes saved.', domain='plone'))
urlBack = '%s/skyn/view?phase=%s&pageName=%s' % (
obj.absolute_url(), rq.get('phase'), rq.get('pageName'))
return self.goto(urlBack)
urlBack = '%s/skyn/view' % obj.absolute_url()
return self.goto(urlBack, True)
elif rq.get('buttonPrevious', None):
# Go to the edit view (previous page) for this object
rq.set('fieldset', rq.get('previousPage'))
@ -145,7 +144,7 @@ class AbstractMixin:
msg = self.translate('delete_done')
self.delete()
self.plone_utils.addPortalMessage(msg)
self.goto(rq['HTTP_REFERER'])
self.goto(rq['HTTP_REFERER'], True)
def rememberPreviousData(self):
'''This method is called before updating an object and remembers, for
@ -184,9 +183,20 @@ class AbstractMixin:
histKey = self.workflow_history.keys()[0]
self.workflow_history[histKey] += (event,)
def goto(self, url):
def goto(self, url, addParams=False):
'''Brings the user to some p_url after an action has been executed.'''
return self.REQUEST.RESPONSE.redirect(url)
rq = self.REQUEST
if not addParams: return rq.RESPONSE.redirect(url)
# Add some context-related parameters if needed.
params = []
if rq.get('phase', ''): params.append('phase=%s' % rq['phase'])
if rq.get('pageName', ''): params.append('pageName=%s' % rq['pageName'])
if rq.get('nav', ''): params.append('nav=%s' % rq['nav'])
params = '&'.join(params)
if not params: return rq.RESPONSE.redirect(url)
if url.find('?') != -1: params = '&' + params
else: params = '?' + params
return rq.RESPONSE.redirect(url+params)
def getAppyValue(self, name, appyType=None, useParamValue=False,value=None):
'''Returns the value of field (or method) p_name for this object
@ -741,7 +751,7 @@ class AbstractMixin:
msg = self.translate(label)
if (resultType == 'computation') or not successfull:
self.plone_utils.addPortalMessage(msg)
return self.goto(rq['HTTP_REFERER'])
return self.goto(rq['HTTP_REFERER'], True)
else:
# msg does not contain a message, but a complete file to show as is.
# (or, if your prefer, the message must be shown directly to the

View file

@ -75,6 +75,7 @@
<input type="hidden" name="fieldset" tal:attributes="value fieldset"/>
<input type="hidden" name="pageName" tal:attributes="value pageName"/>
<input type="hidden" name="phase" tal:attributes="value phase"/>
<input type="hidden" name="nav" tal:attributes="value python:request.get('nav', '')"/>
<input type="hidden" name="is_new"
tal:attributes="value python: '/portal_factory/' in contextObj.absolute_url()"/>

View file

@ -504,9 +504,11 @@
<span tal:replace="python:tool.translate('%s_phase_%s' % (contextObj.meta_type, phase))"/>
</span>
<tal:comment replace="nothing">When no tabs are shown, we provide an edit icon.</tal:comment>
<img tal:define="editPageName python:test(pageName=='main', 'default', pageName)"
<img tal:define="editPageName python:test(pageName=='main', 'default', pageName);
nav request/nav|nothing;
nav python: test(nav, '&nav=%s' % nav, '')"
title="Edit" i18n:domain="plone" i18n:attributes="title" style="cursor:pointer"
tal:attributes="onClick python: 'href: window.location=\'%s/skyn/edit?fieldset=%s&phase=%s\'' % (contextObj.absolute_url(), editPageName, phase);
tal:attributes="onClick python: 'href: window.location=\'%s/skyn/edit?fieldset=%s&phase=%s%s\'' % (contextObj.absolute_url(), editPageName, phase, nav);
src string: $portal_url/skyn/edit.gif"
tal:condition="python: (len(appyPages)==1) and member.has_permission('Modify portal content', contextObj)"/>
</td>
@ -583,9 +585,11 @@
<a tal:content="pageLabel"
tal:attributes="href python: contextObj.absolute_url() + '/skyn/view?phase=%s&pageName=%s' % (phase, thePage)">
</a>
<img tal:define="editPageName python:test(thePage=='main', 'default', thePage)"
<img tal:define="editPageName python:test(thePage=='main', 'default', thePage);
nav request/nav|nothing;
nav python: test(nav, '&nav=%s' % nav, '')"
title="Edit" i18n:domain="plone" i18n:attributes="title" style="cursor:pointer" class="appyPlusImg"
tal:attributes="onClick python: 'href: window.location=\'%s/skyn/edit?fieldset=%s&phase=%s\'' % (contextObj.absolute_url(), editPageName, phase);
tal:attributes="onClick python: 'href: window.location=\'%s/skyn/edit?fieldset=%s&phase=%s%s\'' % (contextObj.absolute_url(), editPageName, phase, nav);
src string: $portal_url/skyn/edit.gif"
tal:condition="python: member.has_permission('Modify portal content', contextObj)"/>
</tal:tab>
@ -679,12 +683,12 @@
excepted for workflow state (which is not a field): in this case it is simply the
string "workflowState".</tal:comment>
<tal:comment replace="nothing">Headers, with filters and sort arrows</tal:comment>
<tal:comment replace="nothing">Headers, with (disabled) filters and sort arrows</tal:comment>
<tr>
<tal:comment replace="nothing">Mandatory column "Title"/"Name"</tal:comment>
<th><img tal:attributes= "src string: $portal_url/arrowDown.gif;
<th><!--img tal:attributes= "src string: $portal_url/arrowDown.gif;
onClick python:'javascript:onSort(\'title\')';"
id="arrow_title" style="cursor:pointer"/>
id="arrow_title" style="cursor:pointer"/-->
<span tal:content="python: tool.translate('ref_name')"/>
<!--input id="filter_title" type="text" size="5" onkeyup="javascript:onTextEntered('title')"/-->
<tal:comment replace="nothing">Input fields like this have been commented out because they will
@ -695,10 +699,10 @@
<tal:comment replace="nothing">Columns corresponding to other fields</tal:comment>
<tal:columnHeader repeat="fieldDescr fieldDescrs">
<th tal:define="fieldName fieldDescr/atField/getName|string:workflow_state">
<img tal:attributes= "src string: $portal_url/arrowDown.gif;
<!--img tal:attributes= "src string: $portal_url/arrowDown.gif;
onClick python:'javascript:onSort(\'%s\')' % fieldName;
id python: 'arrow_%s' % fieldName"
style="cursor:pointer"/>
style="cursor:pointer"/-->
<tal:comment replace="nothing">Display header for a "standard" field</tal:comment>
<tal:standardField condition="python: fieldName != 'workflow_state'">
<span tal:replace="python: tool.translate(fieldDescr['atField'].widget.label_msgid)"/>
@ -714,10 +718,10 @@
</tal:columnHeader>
<tal:comment replace="nothing">Column "Object type", shown if instances of several types are shown</tal:comment>
<th tal:condition="severalTypes"><img
<th tal:condition="severalTypes"><!--img
tal:attributes= "src string: $portal_url/arrowDown.gif;
onClick python:'javascript:onSort(\'root_type\')';"
id = "arrow_root_type" style="cursor:pointer"/>
id = "arrow_root_type" style="cursor:pointer"/-->
<span tal:replace="python: tool.translate('root_type')"/>
<!--input type="text" size="5" id="filter_root_type"
tal:attributes="onkeyup python:'javascript:onTextEntered(\'root_type\')'"/-->