Author: jmorliaguet
Date: Mon Jun 12 15:33:24 2006
New Revision: 3399

Modified:
   cpsskins/branches/paris-sprint-2006/browser/skin/template.pt
   cpsskins/branches/paris-sprint-2006/clientstorage.py
   cpsskins/branches/paris-sprint-2006/ftests/test_permissions.py
   cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
   cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/tests/ctal.js
   cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml
   cpsskins/branches/paris-sprint-2006/standard/filters/style/css.py
   cpsskins/branches/paris-sprint-2006/standard/screens/styleeditor/views.py
   cpsskins/branches/paris-sprint-2006/ui/screens/common/add_content_selector.pt
   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/content_factory.pt
   cpsskins/branches/paris-sprint-2006/ui/screens/common/views.py
   cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py

Log:

- cpsskins.js: added subviews, i.e when a view get loaded or refreshed all
  the subviews get loaded or refreshed

  as a result the remote scripting controller only needs to refresh the current
  view, and other views that also need to be refreshed now need to be subviews,
  e.g.:

  theme tabs > page tabs > rendered page

- added an 'init' method that can be overridden this called when views have
  just been registered. load() recurses through all the subviews.

- fixed a typo in storeFields() (should be this.model._data instead of
  this._data)

- optimized the stylesheet renderer, the css in inserted inline to avoid
  the delay when the stylesheet is fetched over the net via <link rel="..." />.

- the content factory box can be closed with a [x] button



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        Mon Jun 
12 15:33:24 2006
@@ -13,7 +13,7 @@
       <style type="text/css" media="all"
       tal:content="string:@import 
url(${context/++resource++widgets.css});"></style>
       <style type="text/css" media="all"
-      tal:content="string:@import url(./renderCSS);"></style>
+      tal:content="string:@import url(./styles.css);"></style>
     </head>
     <tal:block content="structure python:pageviewer(
       location=context,

Modified: cpsskins/branches/paris-sprint-2006/clientstorage.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/clientstorage.py        (original)
+++ cpsskins/branches/paris-sprint-2006/clientstorage.py        Mon Jun 12 
15:33:24 2006
@@ -61,5 +61,6 @@
         if data is None:
             return []
         return data.keys()
+
     data = property(getData, setData)
 

Modified: cpsskins/branches/paris-sprint-2006/ftests/test_permissions.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ftests/test_permissions.py      
(original)
+++ cpsskins/branches/paris-sprint-2006/ftests/test_permissions.py      Mon Jun 
12 15:33:24 2006
@@ -35,7 +35,7 @@
         self.assertEquals(response.getStatus(), 200)
 
     def test_css_view_permission(self):
-        response = self.publish('/++skin++cpsskins/renderCSS')
+        response = self.publish('/++skin++cpsskins/styles.css')
         self.assertEquals(response.getStatus(), 200)
 
 def test_suite():

Modified: cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
==============================================================================
--- cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    
(original)
+++ cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    Mon Jun 
12 15:33:24 2006
@@ -23,7 +23,7 @@
   if (!debugbox) {
     var div = document.createElement("DIV");
     div.setAttribute("id", "message");
-    div.setStyle({position: 'absolute', top: '10px', left: '400px',
+    div.setStyle({position: 'absolute', top: '10px', left: '800px',
                   zIndex: '10', border: '1px solid #999', padding: '0.3em',
                   backgroundColor: '#ffc'});
     document.getElementsByTagName("body").item(0).appendChild(div);
@@ -33,7 +33,7 @@
   } catch(e) {
      msg = e;
   }
-  $("message").innerHTML = msg;
+  $("message").innerHTML += msg + ' ';
 }
 
 var CPSSkins = {
@@ -55,6 +55,7 @@
 
   init: function() {
     CPSSkins._parse(document);
+    CPSSkins.getViews().invoke('init');
   },
 
   getModelById: function(id) {
@@ -69,6 +70,10 @@
     return this._views[id];
   },
 
+  getViews: function() {
+    return this._views.pluck('value');
+  },
+
   registerControllers: function(controllers) {
     Object.extend(this.Controllers, controllers)
   },
@@ -362,6 +367,7 @@
               el.parentNode.insertBefore(view.widget, el);
             }
             CPSSkins.notify("registered view", {publisher: view, scope: id});
+            view.load();
             view.resetControllers();
           }
           break;
@@ -633,12 +639,6 @@
     Event.stopObserving(view.widget, "submit", this.submitEvent);
   },
 
-  refreshViews: function() {
-    this.views.entries().each(function(v) {
-      CPSSkins.getViewById(v).refresh();
-    });
-  },
-
   submitEvent: function(e) {
     var target = Event.findElement(e, 'form');
     if (target && target != document) {
@@ -716,6 +716,7 @@
   },
 
   _request: function(views, view, method, params) {
+    var controller = this;
     var options = {
       onComplete: function(req) {
         var disp = req.getResponseHeader('content-disposition');
@@ -731,9 +732,7 @@
           var data = JSON.parse(req.responseText);
           view.model.updateData(data);
         }
-        views.entries().each(function(v) {
-          CPSSkins.getViewById(v).refresh();
-        });
+        view.refresh();
       }
     };
     options.parameters = params;
@@ -1595,9 +1594,9 @@
 
   initialize: function(model) {
     this.model = model;
-    this.setup();
     this._queue = [];
     this._queued_data = {};
+    this.setup();
   },
 
   readTransaction: function(data) {
@@ -1684,7 +1683,8 @@
         new_data[field] = current_data[field];
       }
     });
-    if (!this._data || !this._compareData(this.read(), new_data)) {;
+    if (this.model._data == undefined ||
+       !this._compareData(current_data, new_data)) {
       this.model.writeData(new_data);
       CPSSkins.notify('stored', {publisher: this});
     }
@@ -1814,7 +1814,7 @@
     });
   }
 
-});
+})
 
 CPSSkins.UnifiedStorage = Class.create();
 CPSSkins.UnifiedStorage.prototype = Object.extend(
@@ -1865,6 +1865,7 @@
   initialize: function(widget, def) {
     this.widget = widget;
     this.def = def;
+    this.subviews = def.subviews || $A([]);
     this._visible = false;
     this._displayed = true;
 
@@ -1884,6 +1885,10 @@
     /* to override: setup the view */
   },
 
+  init: function() {
+    /* to override: initialize the view */
+  },
+
   render: function(data) {
     /* to override: render the view from the data */
   },
@@ -1945,6 +1950,19 @@
     if (data) {
       this.display(data);
     }
+    // refresh the sub-views
+    this.subviews.entries().each(function(v) {
+      var view = CPSSkins.getViewById(v);
+      if (view) { view.refresh()};
+    });
+  },
+
+  load: function() {
+    this.init();
+    this.subviews.entries().each(function(v) {
+      var view = CPSSkins.getViewById(v);
+      if (view) { view.load()};
+    });
   },
 
   reload: function() {
@@ -2128,8 +2146,9 @@
     if (this.source) {
       var node = document.createElement("div");
       node.innerHTML = this.source;
-      ctal.process_ctal(node, data);
+      ctal.parse(node, data);
       this.widget.innerHTML = node.innerHTML;
+      delete node;
     }
   }
 

Modified: cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/tests/ctal.js
==============================================================================
--- cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/tests/ctal.js  
(original)
+++ cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/tests/ctal.js  Mon Jun 
12 15:33:24 2006
@@ -160,28 +160,32 @@
   var marker = tmpl.nextSibling;
 
   // the iterator variable has the same name as the looped through array.
-  if (nmx[0] == nmx[1]) {
+  var iterator = nmx[0];
+  if (iterator == nmx[1]) {
     throw new ctal.TALError(nmx[0] +
-      " iterator variable overwrites loop variable.");
+      " iterator variable shadows loop variable.");
   }
 
   // do a deep copy of the data structure traversed by the repeat loop
   // to avoid corrupting it.
-  var saved_data = ctal.deepcopy(data);
   for (var i=0; i<datas.length; i++) {
-    data[nmx[0]] = datas[i];
+    data[iterator] = datas[i];
 
     var newnode = tmpl.cloneNode(true);
     ctal.node_insertbefore(parent, newnode, marker);
     // recurse
     ctal.process_ctal(newnode, data);
-    data = ctal.deepcopy(saved_data);
   }
   parent.removeChild(tmpl);
 }
 
 /* general processor */
 
+ctal.parse = function(tmpl, data) {
+  var cloned_data = ctal.deepcopy(data);
+  ctal.process_ctal(tmpl, cloned_data);
+}
+
 ctal.process_ctal = function(tmpl, data) {
   var recurse = true;
   var parsers, ctal_attr, ctal_attr_name, attr;

Modified: 
cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/style/configure.zcml   
Mon Jun 12 15:33:24 2006
@@ -21,16 +21,28 @@
       for="cpsskins.standard.formats.style.IStyle"
   />
 
+  <browser:view
+      for="*"
+      provides=".css.IStylesheetView"
+      class=".css.StylesheetView"
+      permission="zope.Public"
+  />
+
   <browser:pages
       for="*"
       layer="cpsskins.browser.skin.cpsskins"
-      permission="zope.View"
+      permission="zope.Public"
       class=".css.StylesheetView"
       >
 
     <browser:page
         name="renderCSS"
-        attribute="renderCSS"
+        attribute="render"
+    />
+
+    <browser:page
+        name="styles.css"
+        attribute="publish"
     />
 
   </browser:pages>

Modified: cpsskins/branches/paris-sprint-2006/standard/filters/style/css.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/style/css.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/style/css.py   Mon Jun 
12 15:33:24 2006
@@ -29,8 +29,11 @@
 
 class IStylesheetView(Interface):
 
-    def renderCSS():
-        """Render the styles in CSS"""
+    def render():
+        """Render the styles"""
+
+    def publish():
+        """Publish the stylesheet"""
 
 class StylesheetView:
     """A stylesheet renderer
@@ -41,9 +44,7 @@
         self.context = context
         self.request = request
 
-    def renderCSS(self):
-        """Render the styles in CSS
-        """
+    def render(self):
         formats = getThemeManager(self.context).getFormatStorage()
         resources = getUtility(IResourceManager)
         isStyle = IStyle.providedBy
@@ -56,9 +57,11 @@
         rendered = []
         for s in styles:
             rendered.append(ICSSRenderer(s)())
+        return '\n'.join(rendered)
 
+    def publish(self):
         self.request.response.setHeader('Content-Type', 'text/css')
-        return '\n'.join(rendered)
+        return self.render()
 
 class ICSSRenderer(Interface):
     """Renders a style in CSS"""

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   
Mon Jun 12 15:33:24 2006
@@ -17,6 +17,8 @@
 """
 __docformat__ = "reStructuredText"
 
+import time
+
 from zope.app.cache.ram import RAMCache
 from zope.component import getUtility, getMultiAdapter
 from zope.traversing.api import getPath
@@ -123,6 +125,7 @@
                             path,
             },
             'model': 'style-editor',
+            'subviews': ['stylesheet'],
             'controllers': ['style-editor-behaviour',
                             'main-editor-perspectives'],
             'perspectives': ['element-editor'],

Modified: 
cpsskins/branches/paris-sprint-2006/ui/screens/common/add_content_selector.pt
==============================================================================
--- 
cpsskins/branches/paris-sprint-2006/ui/screens/common/add_content_selector.pt   
    (original)
+++ 
cpsskins/branches/paris-sprint-2006/ui/screens/common/add_content_selector.pt   
    Mon Jun 12 15:33:24 2006
@@ -1,5 +1,5 @@
 <ul class="inlineButtons" style="float:left">
   <li>
-    <a 
href="javascript:CPSSkins.getControllerById('panel-perspectives').switchTo('content-factory');">Add
 a portlet</a></li>
+    <a 
href="javascript:CPSSkins.getControllerById('panel-perspectives').switchTo('content-factory')">Add
 a portlet</a></li>
 </ul>
 

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  Mon Jun 
12 15:33:24 2006
@@ -81,13 +81,6 @@
   new Ajax.Request(url, options);
 }
 
-StyleSheet = Class.create();
-StyleSheet.prototype = Object.extend(new CPSSkins.View(), {
-  render: function(data) {
-    this.widget.href = './renderCSS?timestamp=' + new Date().getTime();
-  }
-});
-
 /* Register actions */
 CPSSkins.addActions({
   'insert portlet': insertPortlet,
@@ -103,10 +96,23 @@
 CPSSkins.registerWidgets({
   'stylesheet': function(def) {
     var widget = CPSSkins.Canvas.createNode({
-      tag: "link",
-      attributes: {rel: 'stylesheet', type: 'text/css'}
+      tag: "style",
+      attributes: {type: 'text/css'}
     });
     return new StyleSheet(widget, def);
   }
 });
 
+StyleSheet = Class.create();
+StyleSheet.prototype = Object.extend(new CPSSkins.View(), {
+  init: function() {
+    var data = this.getData();
+    if (data) {
+      this.render(data);
+    }
+  },
+  render: function(data) {
+    this.widget.innerHTML = data.text;
+  }
+});
+

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        
Mon Jun 12 15:33:24 2006
@@ -111,6 +111,11 @@
           attribute="renderPage"
       />
 
+      <page
+          name="renderStylesheet"
+          attribute="renderStylesheet"
+      />
+
   </pages>
 
   <pages

Modified: 
cpsskins/branches/paris-sprint-2006/ui/screens/common/content_factory.pt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/ui/screens/common/content_factory.pt    
(original)
+++ cpsskins/branches/paris-sprint-2006/ui/screens/common/content_factory.pt    
Mon Jun 12 15:33:24 2006
@@ -1,4 +1,4 @@
-<div class="toolbox" i18n:domain="cpsskins">
+<div id="toolbox" class="toolbox" i18n:domain="cpsskins">
   <div class="header">
     <a class="button" 
href="javascript:CPSSkins.getControllerById('panel-perspectives').hide('content-factory')"><img
 src="++resource++close-button.png" /></a>
    Portlets

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      Mon Jun 
12 15:33:24 2006
@@ -45,6 +45,7 @@
 from cpsskins.setup.interfaces import IResourceManager, IIdentifiable, IType
 from cpsskins.ui.screens.definitions import MODELS, VIEWS, CONTROLLERS
 from cpsskins.utils import getThemeManager
+from cpsskins.standard.filters.style.css import IStylesheetView
 
 _ = MessageFactory("cpsskins")
 
@@ -133,6 +134,16 @@
         viewer = getMultiAdapter((page, self.request), IViewer)
         return viewer(engine=engine)
 
+    def renderStylesheet(self):
+        """Render the stylesheet.
+        """
+        stylesheet = getMultiAdapter((self.context, self.request),
+                                     IStylesheetView)
+        self.request.response.setHeader('content-type', 'text/x-json')
+        return json.write({
+            'text': stylesheet.render()
+        })
+
 class Panels(object):
     """Panels view
     """

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       Mon Jun 
12 15:33:24 2006
@@ -8,7 +8,15 @@
     # the stylesheet in which the styles created with the editor are rendered
     'stylesheet': {
         'id': 'stylesheet',
-        'data': {}
+        'storage': {
+            'type': 'remote',
+            'accessors': {
+                'get': '@@renderStylesheet',
+            },
+        },
+        'data': {
+            'text': '',
+        },
     },
 
     # the main editor's action buttons
@@ -23,7 +31,7 @@
     'element-editor': {
         'id': 'element-editor',
         'storage': {
-           'type': 'local'
+           'type': 'local',
         },
         'data': {
             'url': '@@element-editor.html',
@@ -222,9 +230,8 @@
             'type': 'stylesheet',
         },
         'model': 'stylesheet',
-        'perspectives': ['page-designer', 'content-author',
-                         'element-editor'],
-        'controllers': ['main-editor-perspectives', 'element-editor-actions'],
+        'perspectives': ['page-designer', 'content-author', 'element-editor'],
+        'controllers': ['main-editor-perspectives'],
     },
 
     # the main editor action buttons
@@ -239,17 +246,6 @@
         'controllers': ['main-editor-perspectives'],
     },
 
-    # the element editor panel
-    'element-editor': {
-        'id': 'element-editor',
-        'widget': {
-            'type': 'panel',
-        },
-        'model': 'element-editor',
-        'perspectives': ['element-editor'],
-        'controllers': ['main-editor-perspectives'],
-    },
-
     # the preset editor panel
     'preset-editor': {
         'id': 'preset-editor',
@@ -286,6 +282,7 @@
         'widget': {
             'type': 'panel',
         },
+        'subviews': ['page-designer'],
         'model': 'perspective-selector',
         'perspectives': ['page-designer', 'content-author',
                          'element-editor'],
@@ -298,6 +295,7 @@
         'widget': {
             'type': 'panel',
         },
+        'subviews': ['page-tabs'],
         'model': 'theme-tabs',
         'perspectives': ['page-designer'],
         'controllers': ['main-editor-perspectives', 'main-editor-actions'],
@@ -309,6 +307,7 @@
         'widget': {
             'type': 'panel',
         },
+        'subviews': ['wysiwyg-mode', 'layout-mode'],
         'model': 'page-tabs',
         'perspectives': ['page-designer'],
         'controllers': ['main-editor-perspectives', 'main-editor-actions'],
@@ -482,14 +481,6 @@
         'perspectives': ['content-factory'],
         'controllers': ['main-editor-perspectives', 'content-factory',
                         'factory-actions', 'panel-perspectives'],
-        'show_effect': {
-            'transition': 'fadein',
-            'duration': 400,
-        },
-        'hide_effect': {
-            'transition': 'fadeout',
-            'duration': 400,
-        },
     },
 
     # Contextual menu
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to