Author: jmorliaguet
Date: Wed Jun  7 23:29:07 2006
New Revision: 3351

Modified:
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
   cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py
   cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/configure.zcml
   cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/views.py

Log:

- saving work: part of the style editor's data is stored in a client storage
  the code is still a mess though.



Modified: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml
==============================================================================
--- 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml 
    (original)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml 
    Wed Jun  7 23:29:07 2006
@@ -43,6 +43,11 @@
         attribute="setStyleData"
     />
 
+    <browser:page
+        name="setStyleEditorData"
+        attribute="setStyleEditorData"
+    />
+
   </browser:pages>
 
   <browser:page

Modified: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
==============================================================================
--- 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
    (original)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.js
    Wed Jun  7 23:29:07 2006
@@ -57,7 +57,6 @@
   }
   // reverse the array
   selectors.reverse();
-  selectors.shift();
   return selectors.join(" ");
 }
 

Modified: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
==============================================================================
--- 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
    (original)
+++ 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/style_editor.pt
    Wed Jun  7 23:29:07 2006
@@ -1,7 +1,10 @@
 <div i18n:domain="cpsskins"
-     tal:define="widget_types view/getWidgetTypes;
-                 style_id context/identifier">
+     tal:define="data view/getStyleEditorData;
+                 style_id context/identifier;
+                 widget_type data/widget">
 
+  <ins class="model" tal:content="view/getFormDataModelDef" />
+  <ins class="model" tal:content="view/getStyleEditorDataModelDef" />
   <ins class="model" tal:content="view/getModelDef" />
 
   <ins class="controller">
@@ -21,7 +24,7 @@
       <td style="width: 50%; vertical-align: top">
         <fieldset id="previewArea" class="panel" style="cursor: pointer">
           <legend class="panelTitle">Preview</legend>
-          <ins class="view" tal:content="view/getPreviewDef" />
+          <tal:block content="structure view/renderWidgetPreview" />
         </fieldset>
         <div class="floatingHint" style="display: none"
              id="labelInfo">&nbsp;</div>
@@ -38,9 +41,11 @@
   <fieldset class="panel">
     <legend class="panelTitle">Widgets</legend>
     <ul class="inlineButtons">
-      <li tal:repeat="type widget_types">
-        <a i18n:translate="" tal:content="string:widget.${type}"
-           tal:attributes="href 
string:javascript:CPSSkins.getModelById('style-editor').updateData({widget: 
'$type', selector: '', style_id: '$style_id'});" /></li>
+      <tal:block tal:repeat="type view/getWidgetTypes">
+        <li tal:attributes="class python: widget_type == type and 'selected' 
or nothing">
+          <a i18n:translate="" tal:content="string:widget.${type}"
+             tal:attributes="href 
string:@@setStyleEditorData?widget=$type&style_id=$style_id" /></li>
+      </tal:block>
     </ul>
     <div style="clear:both"></div>
   </fieldset>

Modified: 
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py   
Wed Jun  7 23:29:07 2006
@@ -17,9 +17,9 @@
 """
 __docformat__ = "reStructuredText"
 
+from urllib import quote, unquote
 from zope.app.cache.ram import RAMCache
-from zope.app.session.interfaces import ISession
-from zope.component import getUtility
+from zope.component import getUtility, getMultiAdapter
 from zope.traversing.api import getPath
 
 from cpsskins import configuration
@@ -27,7 +27,7 @@
 from cpsskins import utils
 from cpsskins.elements.interfaces import IFormattable
 from cpsskins.setup.interfaces import IResourceManager
-from cpsskins.utils import getThemeManager
+from cpsskins.utils import getThemeManager, getClientStorageId
 
 cache = RAMCache()
 
@@ -37,26 +37,21 @@
     def __init__(self, context, request):
         self.context = context
         self.request = request
-
-        self.session = ISession(request)['cpsskins']
         self.tmutil = getThemeManager(context)
+        self.storage_id = getClientStorageId(u'style-editor-data')
 
     def getWidgetTypes(self):
-        readonly = self.request.form.get('readonly')
-        if readonly:
-            return []
-        else:
-            display_id = self.request.form.get('display')
-            display = self.tmutil.getElementById(display_id)
-            widget = IFormattable(display).getFormat(u'widget')
-            return widget.types
+        display_id = self.element_data.get('display')
+        display = self.tmutil.getElementById(display_id)
+        widget = IFormattable(display).getFormat(u'widget')
+        return widget.types
 
     def renderWidgetPreview(self):
         """Render a style preview based on the specified widget.
         """
-        data = self.data
-        widget_type = data.get(u'widget', u'')
-        style_id = data.get(u'style_id')
+        style_data = self.getStyleEditorData()
+        widget_type = style_data.get('widget')
+        style_id = style_data.get('style_id')
         if not widget_type:
             return u''
         widget = getUtility(configuration.IWidget, widget_type)
@@ -65,10 +60,24 @@
         markup = utils.insertCSSClass(markup, u'style' + unicode(style_id))
         return markup
 
-    def getModelDef(self):
+    def getStyleEditorData(self):
+        value = self.request.cookies.get(self.storage_id)
+        if value is not None:
+            return json.read(unquote(value))
+        return {}
+
+    def setStyleEditorData(self, widget, style_id):
+        data = {
+            'widget': widget,
+            'style_id': style_id,
+        }
+        value = quote(json.write(data))
+        self.request.response.setCookie(self.storage_id, value, path='/')
+
+    def getFormDataModelDef(self):
         path = getPath(self.context)
         return json.write({
-            'id': 'style-editor',
+            'id': 'style-editor-form',
             'storage': {
                 'type': 'remote',
                 'accessors': {
@@ -77,26 +86,39 @@
                 }
             },
             'data': {
-                'preview_url': '/++skin++cpsskins/%s/@@renderWidgetPreview' % \
-                               path,
-                'widget': '',
                 'selector': '',
                 'fields': [],
-                'style_id': '',
                 'uri': '',
             },
         })
 
-    def getPreviewDef(self):
+    def getStyleEditorDataModelDef(self):
         return json.write({
-            'id': 'style-editor-preview',
-            'widget': {
-                'type': 'panel',
-                'url': 'preview_url',
+            'id': 'style-editor-data',
+            'storage': {
+                'type': 'local',
             },
-            'model': 'style-editor',
-            'controllers': ['style-editor-actions', 
'main-editor-perspectives'],
-            'perspectives': ['element-editor'],
+            'data': {
+                'widget': '',
+                'style_id': '',
+            }
+        })
+
+    def getModelDef(self):
+        path = getPath(self.context)
+        return json.write({
+            'id': 'style-editor',
+            'storage': {
+                'type': 'unified',
+                'units': ['style-editor-form', 'style-editor-data'],
+            },
+            'data': {
+                'widget': '',
+                'style_id': '',
+                'selector': '',
+                'fields': [],
+                'uri': '',
+            }
         })
 
     def getFormDef(self):
@@ -144,18 +166,19 @@
 
     def getStyleData(self):
         data = self.data
+        style_data = self.getStyleEditorData()
+        widget = style_data.get(u'widget', u'')
+        style_id = style_data.get(u'style_id', u'')
         selector = data.get(u'selector', u'')
-        widget = data.get(u'widget', u'')
         uri = data.get(u'uri')
-        style_id = data.get(u'style_id', u'')
         resources = getUtility(IResourceManager)
 
         data = {
             'widget': widget,
+            'style_id': style_id,
             'selector': selector,
             'fields': [],
             'uri': uri,
-            'style_id': style_id,
         }
 
         if uri and selector:
@@ -178,12 +201,22 @@
         self.request.response.setHeader('content-type', 'text/x-json')
         return json.write(data)
 
-    ### Session  ######################################################
+    ### Storage  ######################################################
+
+    def getEditorFormData(self):
+        return cache.query('style-editor-form', {}, {})
+
+    def setEditorFormData(self, data):
+        cache.set(data, 'style-editor-form', {})
+
+    data = property(getEditorFormData, setEditorFormData)
 
-    def getSessionData(self):
-        return cache.query('style-editor-data', {}, {})
+    def getElementData(self):
+        editor = getMultiAdapter((self.context, self.request), name="editor")
+        return editor.data
 
-    def setSessionData(self, data):
-        cache.set(data, 'style-editor-data', {})
+    def setElementData(self, data):
+        editor = getMultiAdapter((self.context, self.request), name="editor")
+        editor.data = data
 
-    data = property(getSessionData, setSessionData)
+    element_data = property(getElementData, setElementData)

Modified: 
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/configure.zcml 
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/configure.zcml 
Wed Jun  7 23:29:07 2006
@@ -18,13 +18,21 @@
   />
 
   <view
-      for="cpsskins.elements.interfaces.IElement"
       name="edittabs"
+      for="cpsskins.elements.interfaces.IElement"
       class=".views.Tabs"
       permission="zope.ManageContent"
       layer="cpsskins.browser.skin.cpsskins"
   />
 
+  <view
+      name="editor"
+      for="*"
+      class=".views.ElementEditor"
+      permission="zope.ManageContent"
+      layer="cpsskins.browser.skin.cpsskins"
+  />
+
   <pages
       for="cpsskins.elements.interfaces.IElement"
       layer="cpsskins.browser.skin.cpsskins"

Modified: cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/views.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/views.py       
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/views.py       
Wed Jun  7 23:29:07 2006
@@ -43,6 +43,25 @@
         self.request = request
         self.storage_id = getClientStorageId(u'element-editor')
 
+    def initialize(self):
+        """Initialize element editor data
+        """
+        context = self.context
+        request = self.request
+
+        tmutil = getThemeManager(context)
+        element_id = request.form.get('id')
+        element = tmutil.getElementById(element_id)
+        negotiation = getMultiAdapter((context, request),
+                                      INegotiation, 'negotiation')
+        perspective = negotiation.getPerspective()
+        displayable = IDisplayable(element)
+        display = displayable.getEffectiveDisplay(perspective)
+
+        self.data = {
+            'display': display.identifier
+        }
+
     def getData(self):
         """Get data from a local storage.
         """
@@ -55,7 +74,7 @@
         """Set data in the local storage.
         """
         value = quote(json.write(data))
-        self.request.cookies.set(self.storage_id, value, path='/')
+        self.request.response.setCookie(self.storage_id, value, path='/')
 
     data = property(getData, setData)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to