Author: jmorliaguet
Date: Thu Jun  8 10:17:20 2006
New Revision: 3353

Modified:
   
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/common/authoring.js
   cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py
   cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/configure.zcml
   
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/element_editor.pt
   cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/views.py

Log:

- *much* simpler code by using local storage.



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
    Thu Jun  8 10:17:20 2006
@@ -3,13 +3,10 @@
 
   'selectTag': function(info) {
     var target = info.target;
-    var data = CPSSkins.getModelById('element-editor').getData();
-    var uri = data.form.uri;
     var style_data = CPSSkins.getModelById('style-editor').getData();
     var style_id = style_data.style_id;
     var selector = getSelectorInContext(target, $('previewArea'), style_id);
-    CPSSkins.getModelById('style-editor').updateData(
-    {selector: selector, uri: uri});
+    CPSSkins.getModelById('style-editor').updateData({selector: selector});
   },
 
   'updateLabel': function(info) {

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 10:17:20 2006
@@ -1,7 +1,7 @@
 <div i18n:domain="cpsskins"
      tal:define="data view/getStyleEditorData;
                  style_id context/identifier;
-                 widget_type data/widget">
+                 widget_type data/widget|nothing">
 
   <ins class="model" tal:content="view/getFormDataModelDef" />
   <ins class="model" tal:content="view/getStyleEditorDataModelDef" />

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 10:17:20 2006
@@ -25,7 +25,8 @@
 from cpsskins import configuration
 from cpsskins import minjson as json
 from cpsskins import utils
-from cpsskins.elements.interfaces import IFormattable
+from cpsskins.browser.negotiation.interfaces import INegotiation
+from cpsskins.elements.interfaces import IDisplayable, IFormattable
 from cpsskins.setup.interfaces import IResourceManager
 from cpsskins.utils import getThemeManager, getClientStorageId
 
@@ -41,8 +42,13 @@
         self.storage_id = getClientStorageId(u'style-editor-data')
 
     def getWidgetTypes(self):
-        display_id = self.element_data.get('display')
-        display = self.tmutil.getElementById(display_id)
+        element_id = self.element_data['id']
+        element = self.tmutil.getElementById(element_id)
+        negotiation = getMultiAdapter((self.context, self.request),
+                                      INegotiation, 'negotiation')
+        perspective = negotiation.getPerspective()
+        displayable = IDisplayable(element)
+        display = displayable.getEffectiveDisplay(perspective)
         widget = IFormattable(display).getFormat(u'widget')
         return widget.types
 
@@ -88,7 +94,6 @@
             'data': {
                 'selector': '',
                 'fields': [],
-                'uri': '',
             },
         })
 
@@ -117,7 +122,6 @@
                 'style_id': '',
                 'selector': '',
                 'fields': [],
-                'uri': '',
             }
         })
 
@@ -140,11 +144,10 @@
         selector = data.get(u'selector')
         if selector is None:
             raise ValueError("The CSS selector is not set.")
-        uri = data.get(u'uri')
-        if not uri:
-            raise ValueError("The style URI is not set.")
-        resources = getUtility(IResourceManager)
-        style = resources.resolve(uri, context=self.context)
+        style_id = data.get(u'style_id')
+        if not style_id:
+            raise ValueError("The style id is not set.")
+        style = self.tmutil.getElementById(style_id)
 
         props = {}
         for name in self.getFieldNames():
@@ -170,7 +173,6 @@
         widget = style_data.get(u'widget', u'')
         style_id = style_data.get(u'style_id', u'')
         selector = data.get(u'selector', u'')
-        uri = data.get(u'uri')
         resources = getUtility(IResourceManager)
 
         data = {
@@ -178,11 +180,10 @@
             'style_id': style_id,
             'selector': selector,
             'fields': [],
-            'uri': uri,
         }
 
-        if uri and selector:
-            style = resources.resolve(uri, context=self.context)
+        if style_id and selector:
+            style = self.tmutil.getElementById(style_id)
             fields = []
             sel = style.get(selector)
             if sel is None:

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  Thu Jun 
 8 10:17:20 2006
@@ -42,14 +42,9 @@
 
 function editElement(info) {
   var data = info.model.getData();
-  var id = data.id;
-  CPSSkins.getModelById('element-editor').updateData({
-    form: {id: id, format: ''}
-  });
-  CPSSkins.getControllerById('main-editor-perspectives').switchTo(
-  'element-editor');
-  var style_editor_model = CPSSkins.getModelById('style-editor');
-  if (style_editor_model) style_editor_model.updateData({widget: ''});
+  var perspectives = CPSSkins.getControllerById('main-editor-perspectives');
+  CPSSkins.getModelById('element-editor').updateData({id: data.id});
+  perspectives.switchTo('element-editor');
 }
 
 function editFormat(info) {

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       Thu Jun 
 8 10:17:20 2006
@@ -29,16 +29,9 @@
             'url': '@@element-editor.html',
             'css': '++resource++element-editor.css',
             'script': '++resource++style_editor.js',
-            'form': {
-                'id': '',
-                'display': '',
-                'format': '',
-                'uri': '',
-                'tab': '',
-                'mode': '',
-                'data': {},
-            },
-        }
+            'id': 0,
+            'tab': '',
+        },
     },
 
     # the preset editor in the site manager screen

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 
Thu Jun  8 10:17:20 2006
@@ -81,6 +81,11 @@
       permission="zope.ManageContent">
 
     <page
+      name="setEditorTab"
+      attribute="setEditorTab"
+    />
+
+    <page
       name="element-editor.html"
       template="element_editor.pt"
     />

Modified: 
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/element_editor.pt
==============================================================================
--- 
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/element_editor.pt  
    (original)
+++ 
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/element_editor.pt  
    Thu Jun  8 10:17:20 2006
@@ -1,19 +1,17 @@
 <tal:block i18n:domain="cpsskins" define="
-  init view/initialize;
   data view/data;
-  id request/form/id|nothing;
-  mode request/form/mode|string:edit;
+  id data/id;
+  tab data/tab|nothing;
   tmutil context/@@getThemeManager;
   element python: tmutil.getElementById(id);
   info element/@@edittabs/getInfo;
+  edited nocall:info/edited;
   display nocall:info/display;
   display_id display/identifier;
-  preset nocall:info/preset;
-  edited nocall:info/edited;
-  format request/form/format|nothing;
-  tab request/form/tab|nothing;
   display_name display/type:name;
+  preset nocall:info/preset;
   presets info/presets">
+
   <a class="back"
      
href="javascript:CPSSkins.getControllerById('main-editor-perspectives').goBack()">&lt;
 back to the editor</a>
   <h1 class="title" tal:define="title element/title">
@@ -24,21 +22,20 @@
   <p class="description" tal:content="description"
      tal:define="description element/description|string:No description" />
   <ul class="tabs editTabs">
-    <li tal:attributes="class python: not tab and 'selected' or nothing">
-      <a i18n:translate="" tal:content="info/element/name" tal:attributes="
-         href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: '$id', mode: 'edit', tab: ''}})" /></li>
+    <li tal:attributes="class python: tab == 'element' and 'selected' or 
nothing">
+      <a i18n:translate="" tal:content="info/element/name"
+         href="@@setEditorTab?name=element" /></li>
     <li tal:attributes="class python: tab == display_name and 'selected' or 
nothing">
-      <a i18n:translate="" tal:attributes="
-         href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: $id, tab: '$display_name'}})">Display</a></li>
+      <a i18n:translate=""
+         tal:attributes="href 
string:@@setEditorTab?name=$display_name">Display</a></li>
     <tal:block repeat="format info/formats">
       <li tal:attributes="class python: format['selected'] and 'selected' or 
nothing">
-        <a i18n:translate="" tal:attributes="
-           href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: $id, display: $display_id, format: ${format/id}, uri: '${format/uri}', 
tab: '${format/name}'}})"
+        <a i18n:translate=""
+           tal:attributes="href string:@@setEditorTab?name=${format/name}"
            tal:content="format/name" /></li>
     </tal:block>
     <li tal:attributes="class python: tab == 'preview' and 'selected' or 
nothing">
-      <a i18n:translate="" tal:attributes="
-         href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: '$id', mode: 'preview', tab: 'preview'}})">Preview</a></li>
+      <a i18n:translate="" href="@@setEditorTab?name=preview">Preview</a></li>
   </ul>
 
   <div class="form">
@@ -63,7 +60,7 @@
     <div style="clear:both" />
 
     <tal:block condition="python: not preset or preset.isLocal()">
-      <tal:block condition="python: mode == 'edit'"
+      <tal:block condition="python: tab != 'preview'"
                  define="edit_view nocall:edited/@@edit.html"
                  content="structure python:edit_view(data=data)" />
     </tal:block>
@@ -72,14 +69,15 @@
       <em>This preset is stored on the file-system. It cannot be edited.</em>
     </tal:block>
 
-    <fieldset class="panel" tal:condition="python: mode == 'preview' or preset 
and preset.isGlobal()">
+    <fieldset class="panel" tal:condition="python: tab == 'preview' or preset 
and preset.isGlobal()">
       <legend class="panelTitle">Preview
         <tal:block content="preset/name" condition="preset" />
       </legend>
       <tal:block content="structure info/preview" />
     </fieldset>
 
-    <fieldset class="panel" tal:condition="python: format and not preset">
+    <fieldset class="panel"
+      tal:condition="python: tab.startswith('format') and not preset">
       <legend class="panelTitle">Create a preset</legend>
       <p><em>You can save these settings as a preset.</em></p>
       <form enctype="multipart/form-data" method="post"

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 10:17:20 2006
@@ -43,24 +43,10 @@
         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 setEditorTab(self, name=u''):
+        data = self.data
+        data['tab'] = name
+        self.data = data
 
     def getData(self):
         """Get data from a local storage.
@@ -108,16 +94,19 @@
     def getAbsoluteURL(self, object):
         return getMultiAdapter((object, self.request), name=u'absolute_url')()
 
+
     def getInfo(self):
         context = self.context
         request = self.request
 
+        editor = getMultiAdapter((context, request), name=u'editor')
+        editor_data = editor.data
+
         tmutil = getThemeManager(context)
         resources = getUtility(IResourceManager)
 
-        form = request.form
-        element_id = form.get('id')
-        tab = form.get('tab')
+        element_id = editor_data['id']
+        tab = editor_data.get('tab')
 
         negotiation = getMultiAdapter((context, request),
                                       INegotiation, 'negotiation')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to