Author: jmorliaguet
Date: Thu Jun  8 21:13:59 2006
New Revision: 3363

Modified:
   
cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/configure.zcml
   
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/views.py

Log:

- using the new clientstorage



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 
    Thu Jun  8 21:13:59 2006
@@ -51,10 +51,11 @@
   </browser:pages>
 
   <browser:page
-    for="*"
-    name="style-editor-form.html"
-    permission="zope.ManageContent"
-    template="style_editor_form.ctal"
+      for="*"
+      name="style-editor-form.html"
+      permission="zope.ManageContent"
+      class=".views.StyleEditor"
+      template="style_editor_form.ctal"
   />
 
 </configure>

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
    Thu Jun  8 21:13:59 2006
@@ -1,7 +1,7 @@
 <div i18n:domain="cpsskins"
-     tal:define="data view/getStyleEditorData;
+     tal:define="style_data view/style_data;
                  style_id context/identifier;
-                 widget_type data/widget|nothing">
+                 widget_type style_data/widget|nothing">
 
   <ins class="model" tal:content="view/getFormDataModelDef" />
   <ins class="model" tal:content="view/getStyleEditorDataModelDef" />
@@ -19,12 +19,26 @@
   }}
   </ins>
 
+  <fieldset class="panel">
+    <legend class="panelTitle">Widgets</legend>
+    <ul class="inlineButtons">
+      <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>
+
   <table style="width: 100%">
     <tr>
       <td style="width: 50%; vertical-align: top">
-        <fieldset id="previewArea" class="panel" style="cursor: pointer">
+        <fieldset id="previewArea" class="panel" style="cursor: pointer"
+                  tal:define="preview view/renderWidgetPreview"
+                  tal:condition="preview">
           <legend class="panelTitle">Preview</legend>
-          <tal:block content="structure view/renderWidgetPreview" />
+          <tal:block content="structure preview" />
         </fieldset>
         <div class="floatingHint" style="display: none"
              id="labelInfo">&nbsp;</div>
@@ -38,16 +52,4 @@
     </tr>
   </table>
 
-  <fieldset class="panel">
-    <legend class="panelTitle">Widgets</legend>
-    <ul class="inlineButtons">
-      <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>
-
 </div>

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   
Thu Jun  8 21:13:59 2006
@@ -17,7 +17,6 @@
 """
 __docformat__ = "reStructuredText"
 
-from urllib import quote, unquote
 from zope.app.cache.ram import RAMCache
 from zope.component import getUtility, getMultiAdapter
 from zope.traversing.api import getPath
@@ -26,9 +25,10 @@
 from cpsskins import minjson as json
 from cpsskins import utils
 from cpsskins.browser.negotiation.interfaces import INegotiation
+from cpsskins.clientstorage import ClientStorage
 from cpsskins.elements.interfaces import IDisplayable, IFormattable
 from cpsskins.setup.interfaces import IResourceManager
-from cpsskins.utils import getThemeManager, getClientStorageId
+from cpsskins.utils import getThemeManager
 
 cache = RAMCache()
 
@@ -39,7 +39,8 @@
         self.context = context
         self.request = request
         self.tmutil = getThemeManager(context)
-        self.storage_id = getClientStorageId(u'style-editor-data')
+        self.element_data = ClientStorage(u'element-editor')
+        self.style_data = ClientStorage(u'style-editor-data')
 
     def getWidgetTypes(self):
         element_id = self.element_data['id']
@@ -55,37 +56,16 @@
     def renderWidgetPreview(self):
         """Render a style preview based on the specified widget.
         """
-        style_data = self.getStyleEditorData()
-        widget_type = style_data.get('widget')
-        style_id = style_data.get('style_id')
+        widget_type = self.style_data['widget']
         if not widget_type:
             return u''
+        style_id = self.style_data['style_id']
         widget = getUtility(configuration.IWidget, widget_type)
         markup = widget.view(None, None).renderPreview()
         markup = utils.insertCSSClass(markup, utils.camelize(widget_type))
         markup = utils.insertCSSClass(markup, u'style' + unicode(style_id))
         return markup
 
-    def getStyleEditorData(self):
-        element_data = self.element_data
-        init = element_data['init']
-        if init:
-            element_data['init'] = False
-            self.element_data = element_data
-            return {}
-        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({
@@ -164,20 +144,22 @@
 
         style[selector] = props
 
+    def getFieldNames(self):
+        return (u'font', u'color', u'background-color', 'background-image',
+                u'padding', u'margin', u'border', u'text-transform')
+
+    def setStyleEditorData(self, widget=u'', style_id=u''):
+        self.style_data.setData({'widget': widget, 'style_id': style_id})
+
     def setStyleData(self, data):
         self.data = json.read(data)
         self.request.response.setHeader('content-type', 'text/x-json')
         return self.getStyleData()
 
-    def getFieldNames(self):
-        return (u'font', u'color', u'background-color', 'background-image',
-                u'padding', u'margin', u'border', u'text-transform')
-
     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'')
+        widget = self.style_data[u'widget']
+        style_id = self.style_data[u'style_id']
         selector = data.get(u'selector', u'')
         resources = getUtility(IResourceManager)
 
@@ -210,20 +192,11 @@
 
     ### Storage  ######################################################
 
-    def getEditorFormData(self):
+    def getData(self):
         return cache.query('style-editor-form', {}, {})
 
-    def setEditorFormData(self, data):
+    def setData(self, data):
         cache.set(data, 'style-editor-form', {})
 
-    data = property(getEditorFormData, setEditorFormData)
-
-    def getElementData(self):
-        editor = getMultiAdapter((self.context, self.request), name="editor")
-        return editor.data
-
-    def setElementData(self, data):
-        editor = getMultiAdapter((self.context, self.request), name="editor")
-        editor.data = data
+    data = property(getData, setData)
 
-    element_data = property(getElementData, setElementData)

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       
Thu Jun  8 21:13:59 2006
@@ -17,52 +17,31 @@
 """
 __docformat__ = "reStructuredText"
 
-from urllib import quote, unquote
 from zope.formlib import form
 from zope.component import getMultiAdapter, getUtility
 from zope.location.pickling import locationCopy
 from zope.security.proxy import removeSecurityProxy
 from zope.traversing.api import getParent
 
-from cpsskins import minjson as json
 from cpsskins.browser.negotiation.interfaces import INegotiation
 from cpsskins.browser.rendering.interfaces import IViewer
+from cpsskins.clientstorage import ClientStorage
 from cpsskins.elements.interfaces import IDisplay, IFormat
 from cpsskins.elements.interfaces import IDisplayable, IFormattable
 from cpsskins.setup.interfaces import IType, IIdentifiable
 from cpsskins.setup.interfaces import IResourceManager, IResource, IPreset
-from cpsskins.setup.io import importSite, exportSite
-from cpsskins.setup.snapshot import Snapshot
 from cpsskins.storage.interfaces import IStorage
-from cpsskins.utils import getThemeManager, getClientStorageId
+from cpsskins.utils import getThemeManager
 
 class ElementEditor(object):
 
     def __init__(self, context, request):
         self.context = context
         self.request = request
-        self.storage_id = getClientStorageId(u'element-editor')
+        self.data = ClientStorage(u'element-editor')
 
     def setEditorTab(self, name=u''):
-        data = self.data
-        data['tab'] = name
-        self.data = data
-
-    def getData(self):
-        """Get data from a local storage.
-        """
-        value = self.request.cookies.get(self.storage_id)
-        if value is not None:
-            return json.read(unquote(value))
-        return None
-
-    def setData(self, data):
-        """Set data in the local storage.
-        """
-        value = quote(json.write(data))
-        self.request.response.setCookie(self.storage_id, value, path='/')
-
-    data = property(getData, setData)
+        self.data['tab'] = name
 
 class Form(object):
     """An edit form for elements.
@@ -90,6 +69,7 @@
     def __init__(self, context, request):
         self.context = context
         self.request = request
+        self.data = ClientStorage(u'element-editor')
 
     def getAbsoluteURL(self, object):
         return getMultiAdapter((object, self.request), name=u'absolute_url')()
@@ -99,14 +79,11 @@
         context = self.context
         request = self.request
 
-        editor = getMultiAdapter((context, request), name=u'editor')
-        editor_data = editor.data
-
         tmutil = getThemeManager(context)
         resources = getUtility(IResourceManager)
 
-        element_id = editor_data['id']
-        tab = editor_data.get('tab')
+        element_id = self.data['id']
+        tab = self.data['tab']
 
         negotiation = getMultiAdapter((context, request),
                                       INegotiation, 'negotiation')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to