Author: jmorliaguet Date: Tue Jul 4 09:57:23 2006 New Revision: 3607 Added: cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/align-16.png (contents, props changed) Modified: cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py cpsskins/branches/paris-sprint-2006/browser/skin/template.pt cpsskins/branches/paris-sprint-2006/browser/tree/slot.py cpsskins/branches/paris-sprint-2006/setup/snapshot.py cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.zcml cpsskins/branches/paris-sprint-2006/ui/screens/common/authoring.js cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/configure.zcml cpsskins/branches/paris-sprint-2006/ui/screens/common/perspective_selector.pt cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/io_section.pt cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/presets.pt cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py
Log: - saving work: - added an align (left, cengter, right) option to the context menu - negotiation fixes, removed session-based negotiation, using cookies instead Modified: cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py (original) +++ cpsskins/branches/paris-sprint-2006/browser/rendering/viewer.py Tue Jul 4 09:57:23 2006 @@ -77,15 +77,11 @@ tmutil = getThemeManager(element) relations = tmutil.getRelationStorage() - negotiation = getMultiAdapter((rendering.location, request), - INegotiation, 'negotiation') - perspective = negotiation.getPerspective() resources = getUtility(IResourceManager) # set other global variables rendering.update({ 'request': request, - 'perspective': perspective, 'relations': relations, 'resources': resources, }) Modified: cpsskins/branches/paris-sprint-2006/browser/skin/template.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/browser/skin/template.pt (original) +++ cpsskins/branches/paris-sprint-2006/browser/skin/template.pt Tue Jul 4 09:57:23 2006 @@ -6,6 +6,7 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" tal:define="negotiation nocall:context/@@negotiation; engine negotiation/getEngine; + perspective negotiation/getPerspective; page negotiation/getPage; pageviewer nocall:page/@@viewer"> <head> @@ -17,6 +18,8 @@ tal:content="string:@import url(./styles.css);" /> </head> <tal:block content="structure python:pageviewer(location=context, - view=view, template=template, engine=engine)" /> + view=view, template=template, engine=engine, + perspective=perspective)" /> + <tal:block content="perspective" /> </html> </metal:block> Modified: cpsskins/branches/paris-sprint-2006/browser/tree/slot.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/browser/tree/slot.py (original) +++ cpsskins/branches/paris-sprint-2006/browser/tree/slot.py Tue Jul 4 09:57:23 2006 @@ -50,17 +50,8 @@ request = self.request relations = getRelationStorage(context) - # The slot can override the perspective from which portlets are looked - # up unless the assigned perspective is '.' - slot_perspective = context.perspective - if slot_perspective == u'': + if context.perspective == u'': perspective = None - elif slot_perspective != u'.': - perspective = slot_perspective - else: - negotiation = getMultiAdapter((context, request), INegotiation, - name='negotiation') - perspective = negotiation.getPerspective() if perspective is None: portlets = relations.getSeconds(predicate=hasPortlet, first=context) Modified: cpsskins/branches/paris-sprint-2006/setup/snapshot.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/setup/snapshot.py (original) +++ cpsskins/branches/paris-sprint-2006/setup/snapshot.py Tue Jul 4 09:57:23 2006 @@ -31,7 +31,7 @@ filename = TextLine( title=u"Filename", description=u"The snapshot's filename", - ) + ) def read(): """Return the file's data""" Modified: cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py (original) +++ cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.py Tue Jul 4 09:57:23 2006 @@ -23,9 +23,9 @@ from zope.traversing.interfaces import IPhysicallyLocatable from cpsskins.browser.negotiation.scheme import NegotiationScheme -from cpsskins.standard.negotiation import ISessionNegotiationScheme from cpsskins.standard.negotiation import ILocationNegotiationScheme from cpsskins.standard.negotiation import ICookieLocationNegotiationScheme +from cpsskins.standard.negotiation import ICookieNegotiationScheme from cpsskins.utils import guessPath class Location(NegotiationScheme): @@ -56,20 +56,11 @@ return location() return None -class Session(NegotiationScheme): - """Look for a perspective in the session. +class Cookie(NegotiationScheme): + """Look for a perspective whose name is stored in a cookie """ - implements(ISessionNegotiationScheme) + implements(ICookieNegotiationScheme) def __call__(self): - pkg_id = 'cpsskins' - s = ISession(self.request, None) - if s is None: - return None - session = s[pkg_id] - try: - perspective = session['perspective'] - except KeyError: - perspective = None - return perspective + return self.request.cookies.get('cpsskins_perspective') Modified: cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.zcml ============================================================================== --- cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.zcml (original) +++ cpsskins/branches/paris-sprint-2006/standard/negotiation/perspective.zcml Tue Jul 4 09:57:23 2006 @@ -6,11 +6,6 @@ <negotiationchain name="perspective" strategy="default"> <scheme - class=".perspective.Session" - interface=".interfaces.ISessionNegotiationScheme" - /> - - <scheme class=".perspective.Location" interface=".interfaces.ILocationNegotiationScheme" /> @@ -35,8 +30,8 @@ <negotiationchain name="perspective" strategy="page-designer"> <scheme - class=".perspective.Session" - interface=".interfaces.ISessionNegotiationScheme" + class=".perspective.Cookie" + interface=".interfaces.ICookieNegotiationScheme" /> </negotiationchain> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/authoring.js ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/authoring.js (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/authoring.js Tue Jul 4 09:57:23 2006 @@ -48,6 +48,21 @@ perspectives.switchTo('element-editor'); } +function alignElement(info) { + var data = info.model.getData(); + var id = info.target.getAttribute('id'); + var model = CPSSkins.getModelById('m' + id) + var args = { + id: id, + align: info.options.choice + } + var options = { + parameters: $H(args).toQueryString(), + onComplete: function(req) {info.controller.refreshViews();} + }; + new Ajax.Request('@@alignElement', options); +} + function editFormat(info) { var data = info.model.getData(); var options = info.options; @@ -125,6 +140,7 @@ 'paste element': pasteElement, 'delete element': deleteElement, 'edit element': editElement, + 'align element': alignElement, 'edit format': editFormat, 'set as default': setAsDefault, 'cancel event': function(e) {return false;} Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/configure.zcml Tue Jul 4 09:57:23 2006 @@ -204,6 +204,11 @@ /> <page + name="getPerspective" + attribute="getPerspective" + /> + + <page name="setPage" attribute="setPage" /> @@ -259,6 +264,11 @@ /> <page + name="alignElement" + attribute="alignElement" + /> + + <page name="copyElement" attribute="copyElement" /> Added: cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/align-16.png ============================================================================== Binary file. No diff available. Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/configure.zcml ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/configure.zcml (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/icons/configure.zcml Tue Jul 4 09:57:23 2006 @@ -19,6 +19,10 @@ layer="cpsskins.browser.skin.cpsskins" /> <resource + name="align-16.png" file="align-16.png" + layer="cpsskins.browser.skin.cpsskins" /> + + <resource name="paste-16.png" file="paste-16.png" layer="cpsskins.browser.skin.cpsskins" /> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/perspective_selector.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/perspective_selector.pt (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/perspective_selector.pt Tue Jul 4 09:57:23 2006 @@ -3,7 +3,7 @@ action="@@setPerspective" method="post" tal:define="tmutil context/@@getThemeManager; perspectives tmutil/listPerspectives; - current context/@@negotiation/getPerspective" + current context/@@getPerspective" tal:condition="perspectives"> <select name="perspective"> <option value="_" i18n:translate="">(no perspective)</option> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py Tue Jul 4 09:57:23 2006 @@ -93,7 +93,33 @@ request = self.request id = context.identifier - formats = IFormattable(context).getFormats() + formattable = IFormattable(context) + formats = formattable.getFormats() + + align_list = [] + formats_list = [] + for f in formats: + # layout + type_name = str(IType(f)) + if type_name == u'format-layout': + if u'alignable' in f.types: + align_list.extend([{ + 'choice': u'left', + 'label': _(u'Left'), + }, + {'choice': u'center', + 'label': _(u'Center'), + }, + {'choice': u'right', + 'label': _(u'Right'), + }]) + + # formats + formats_list.append({ + 'choice': type_name, + 'label': _(type_name), + 'format': f.identifier, + }) return json.write({ 'id': u'm%s' % id, @@ -103,13 +129,10 @@ 'order': info is not None and info.order or 0, 'container': IInnerNode.providedBy(context), 'uri': IIdentifiable(context).getURI(), - 'formattable': True, - 'formats': [ - {'choice': str(IType(f)), - 'label': _(str(IType(f))), - 'format': f.identifier, - } for f in formats - ], + 'formattable': bool(formats_list), + 'formats': formats_list, + 'alignable': bool(align_list), + 'alignments': align_list, }, }) @@ -127,8 +150,9 @@ INegotiation, 'negotiation') negotiation.strategy = strategy page = negotiation.getPage() + perspective = negotiation.getPerspective() viewer = getMultiAdapter((page, self.request), IViewer) - return viewer(engine=engine) + return viewer(engine=engine, perspective=perspective) def renderStylesheet(self): """Render the stylesheet. @@ -203,11 +227,6 @@ def getThemeManager(self): return self.tmutil - def _redirect(self): - request = self.request - target = request.get('HTTP_REFERER', '.') - request.response.redirect(target) - def draw(self, **kw): """Draws a the canvas element in edit mode """ @@ -220,7 +239,6 @@ kw.update(self.request.form) session_info = self.getSessionInfo() session_info['selection'] = kw - self._redirect() def getSelection(self): session_info = self.getSessionInfo() @@ -231,17 +249,16 @@ """ self.tmutil.addPerspective(name=name, title=name) + def getPerspective(self): + return self.request.cookies.get('cpsskins_perspective', u'') + def setPerspective(self, perspective=u''): """Set the perspective """ if perspective == u'_': perspective = u'' - session_info = self.getSessionInfo() - if not perspective: - del session_info['perspective'] - else: - session_info['perspective'] = perspective - self._redirect() + response = self.request.response + response.setCookie('cpsskins_perspective', perspective) def setPage(self, name=u''): """Set the work page. @@ -252,7 +269,6 @@ name = u'%s:%s' % (name, theme.getDefaultPage().name) response = self.request.response response.setCookie('cpsskins_page', name) - response.redirect('.') def setLocation(self, location=u''): """Set the current location @@ -262,14 +278,12 @@ return response = self.request.response response.setCookie('cpsskins_location', location) - response.redirect('.') def addTheme(self): """Add a theme. """ response = self.request.response addThemeSkeleton(self.tmutil) - response.redirect('.') def addPage(self, theme_name=u''): """Add a page. 'theme_name' is the name of the theme in which is page is @@ -280,7 +294,6 @@ if theme is None: raise ValueError("No such theme: %s" % theme_name) addPageSkeleton(self.tmutil, theme) - response.redirect('.') ### Presentation ################################################# @@ -292,19 +305,16 @@ perspectives = getUtility(IResourceManager, 'perspectives') perspective = perspectives.lookup(perspective, context=self.context) IPresentable(self.context).clonePresentation(perspective) - self._redirect() def addPresentation(self, perspective=None): perspectives = getUtility(IResourceManager, 'perspectives') perspective = perspectives.lookup(perspective, context=self.context) IPresentable(self.context).addPresentation(perspective) - self._redirect() def removePresentation(self, perspective=None): perspectives = getUtility(IResourceManager, 'perspectives') perspective = perspectives.lookup(perspective, context=self.context) IPresentable(self.context).removePresentation(perspective) - self._redirect() ### Format ####################################################### @@ -312,13 +322,11 @@ perspectives = getUtility(IResourceManager, 'perspectives') perspective = perspectives.lookup(perspective, context=self.context) IPresentable(self.context).customizeFormat(name, perspective) - self._redirect() def uncustomizeFormat(self, name=u'', perspective=None): perspectives = getUtility(IResourceManager, 'perspectives') perspective = perspectives.lookup(perspective, context=self.context) IPresentable(self.context).uncustomizeFormat(name, perspective) - self._redirect() ### Elements ##################################################### @@ -342,6 +350,14 @@ else: element[name] = value + def alignElement(self, id, align): + """Align an element. + """ + request = self.request + element = self.tmutil.getElementById(id) + layout = IFormattable(element).getFormat('layout') + layout[u'align'] = align + def copyElement(self, id): """Copy an element to the clipboard. """ Modified: cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py Tue Jul 4 09:57:23 2006 @@ -581,6 +581,17 @@ }, ] }, + {'type': 'submenu', + 'label': _('Align'), + 'visible': 'alignable', + 'icon': '++resource++align-16.png', + 'items': [ + {'type': 'selection', + 'action': 'align element', + 'choices': 'alignments', + }, + ] + }, {'type': 'separator', }, {'type': 'item', Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/io_section.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/io_section.pt (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/io_section.pt Tue Jul 4 09:57:23 2006 @@ -1,17 +1,19 @@ <div class="sections" tal:define="section request/form/section|nothing; - snapshot request/form/snapshot|nothing; + snapshot_id request/form/snapshot_id|nothing; + snapshot_filename request/form/snapshot_filename|nothing; snapshots context/@@listSnapshots"> + <div tal:condition="section"> <div tal:condition="python: section == 'export'"> <h3>Export site</h3> <a href="@@createSnapshot">Create a snapshot</a> - - <tal:block condition="snapshot"> + + <tal:block condition="snapshot_id"> <h4>Download snapshot</h4> - <a tal:attributes="href string:@@downloadSnapshot?filename=$snapshot" - tal:content="snapshot" /> + <a tal:attributes="href string:@@downloadSnapshot?filename=$snapshot_filename&id=$snapshot_id" + tal:content="snapshot_filename" /> </tal:block> </div> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/presets.pt ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/presets.pt (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/presets.pt Tue Jul 4 09:57:23 2006 @@ -15,7 +15,7 @@ <td class="section"> <div class="sections"> <ul class="items"> - <li tal:repeat="section python: ['perspective', 'format-widget', 'format-style', 'field-color', 'field-image']"> + <li tal:repeat="section python: ['perspective', 'format-widget', 'format-style', 'format-layout', 'format-effect', 'field-color', 'field-image']"> <a i18n:translate="" tal:attributes="href string:javascript:CPSSkins.getModelById('presets-section').setData({'form': {'section': '$section'}})" tal:content="section">SECTION</a></li> Modified: cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py ============================================================================== --- cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py (original) +++ cpsskins/branches/paris-sprint-2006/ui/screens/sitemanager/views.py Tue Jul 4 09:57:23 2006 @@ -19,6 +19,7 @@ from zope.component import getUtility, createObject from zope.formlib import form +from zope.traversing.api import getName from cpsskins import minjson as json from cpsskins.locations import Location @@ -112,7 +113,8 @@ self.request.response.setHeader('content-type', 'text/x-json') return json.write({'form': { - 'snapshot': snapshot.filename, + 'snapshot_filename': snapshot.filename, + 'snapshot_id': getName(snapshot), 'section': 'export', }}) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins