Author: jmorliaguet
Date: Sun Jun  4 15:07:50 2006
New Revision: 3300

Modified:
   cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
   cpsskins/branches/paris-sprint-2006/ui/screens/definitions.py
   
cpsskins/branches/paris-sprint-2006/ui/screens/elementeditor/element_editor.pt

Log:

- optimizations



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    Sun Jun 
 4 15:07:50 2006
@@ -23,6 +23,9 @@
   if (!debugbox) {
     var div = document.createElement("DIV");
     div.setAttribute("id", "message");
+    div.setStyle({position: 'absolute', top: '10px', left: '400px',
+                  zIndex: '10', border: '1px solid #999', padding: '0.3em',
+                  backgroundColor: '#ffc'});
     document.getElementsByTagName("body").item(0).appendChild(div);
   }
   try {
@@ -30,7 +33,7 @@
   } catch(e) {
      msg = e;
   }
-  $("message").innerHTML += msg + '</br> ';
+  $("message").innerHTML = msg;
 }
 
 var CPSSkins = {
@@ -66,10 +69,6 @@
     return this._views[id];
   },
 
-  getViews: function() {
-    return this._views.pluck('value');
-  },
-
   registerControllers: function(controllers) {
     Object.extend(this.Controllers, controllers)
   },
@@ -210,7 +209,6 @@
         CPSSkins._load(node);
         CPSSkins.unsubscribe("initialized", {scope: progress});
         CPSSkins.notify("parsed", {publisher: node});
-        CPSSkins.getViews().invoke('attachControllers');
       }
     });
     CPSSkins.subscribe("initialized",
@@ -254,7 +252,7 @@
   // second stage
   _load: function(node) {
     var elements = $A(node.getElementsByTagName("ins"));
-    ["view", "controller", "model"].each(function(type) {
+    ["controller", "view", "model"].each(function(type) {
       elements.each(function(el) {
         if (el.hasClassName(type)) {
           CPSSkins._register(node, el, type);
@@ -364,6 +362,7 @@
               el.parentNode.insertBefore(view.widget, el);
             }
             CPSSkins.notify("registered view", {publisher: view, scope: id});
+            view.resetControllers();
           }
           break;
         }
@@ -492,10 +491,8 @@
 CPSSkins.CommandController = Class.create();
 CPSSkins.CommandController.prototype = Object.extend(new 
CPSSkins.Controller(), {
 
-  register: function(view) {
-
+  setup: function() {
     var controller = this;
-
     CPSSkins.registerEventHandler("command", controller, function(event) {
       var view = event.publisher;
       var controller = event.subscriber;
@@ -512,7 +509,10 @@
         if (action_handler) action_handler(event);
       }
     });
+  },
 
+  register: function(view) {
+    var controller = this;
     CPSSkins.subscribe("command", {subscriber: controller, publisher: view});
   },
 
@@ -784,12 +784,7 @@
   },
 
   register: function(view) {
-    var dragging = this.def.dragging;
-    if (!dragging) {
-      return;
-    }
     var widget = view.widget;
-
     var getElements = document.getElementsByClassName;
 
     var shifting = this.def.shifting;
@@ -807,14 +802,16 @@
       }
     }
 
-    this._dragEvent = this.dragEvent.bindAsEventListener(
-                      Object.extend(this, {widget: widget}));
-    Event.observe(widget, "mousedown", this._dragEvent);
+    this.dragEvent = this.dragEvent.bindAsEventListener(
+                                    Object.extend(this, {widget: widget}));
+    Event.observe(widget, "mousedown", this.dragEvent);
   },
 
   unregister: function(view) {
     var widget = view.widget;
-    Event.stopObserving(widget, "mousedown", this._dragEvent);
+    this.dragEvent = this.dragEvent.bindAsEventListener(
+                                    Object.extend(this, {widget: widget}));
+    Event.stopObserving(widget, "mousedown", this.dragEvent);
   },
 
   _findDraggable: function(e) {
@@ -1110,11 +1107,9 @@
     var current_perspective = this._current;
     $A(view.def.perspectives).each(function(p) {
       if (!(p in visible)) {
-        visible[p] = [];
-      }
-      if (visible[p].indexOf(view_id) < 0) {
-        visible[p].push(view_id);
+        visible[p] = new CPSSkins.Set();
       }
+      visible[p].add(view_id);
     });
   },
 
@@ -1130,7 +1125,7 @@
     this._current = perspective;
     var to_show = this._visible_views[perspective] || [];
     var to_hide = this.views.entries().select(function(v) {
-      return to_show.indexOf(v) < 0;
+      return !to_show.contains(v);
     });
     to_hide.each(function(v) { CPSSkins.getViewById(v).hide(); });
     to_show.each(function(v) { CPSSkins.getViewById(v).show(); });
@@ -1902,7 +1897,7 @@
     return this.def.controllers || []
   },
 
-  attachControllers: function() {
+  resetControllers: function() {
     var view = this;
     var view_id = view.hash();
     var controllers_ids = view.getControllers();
@@ -1910,24 +1905,9 @@
       var controller = CPSSkins.getControllerById(c);
       if (controller) {
         controller.views.add(view_id);
-        if (!controller.registered.contains(view_id)) {
-          controller.register(view);
-          controller.update(view);
-          controller.registered.add(view_id);
-        }
-      }
-    });
-  },
-
-  detachControllers: function() {
-    var view = this;
-    var view_id = view.hash();
-    var controllers_ids = view.getControllers();
-    controllers_ids.each(function(c) {
-      var controller = CPSSkins.getControllerById(c);
-      if (controller) {
         controller.unregister(view);
-        controller.registered.remove(view_id);
+        controller.register(view);
+        controller.update(view);
       }
     });
   },
@@ -1966,9 +1946,8 @@
   reload: function() {
     var data = this.getData();
     if (data) {
-      this.detachControllers();
       this.display(data);
-      this.attachControllers();
+      this.resetControllers();
     }
   },
 
@@ -2190,9 +2169,8 @@
           var old_html = widget.innerHTML;
           widget.innerHTML = req.responseText;
           if (widget.innerHTML != old_html) {
-            view.detachControllers();
             CPSSkins._parse(widget);
-            view.attachControllers();
+            view.resetControllers();
           }
         }
       };
@@ -2540,7 +2518,7 @@
 
   /* Event handlers */
   showEvent: function(e) {
-    var selected = $(Event.element(e));
+    var selected = Event.element(e);
 
     var model = CPSSkins.Canvas.getModel(selected);
     if (!model) return;

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       Sun Jun 
 4 15:07:50 2006
@@ -25,7 +25,7 @@
         'data': {
             'url': '@@element-editor.html',
             'css': '++resource++element-editor.css',
-            'script': '',
+            'script': '++resource++style_editor.js',
             'form': {
                 'id': '',
                 'format': '',

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  
    Sun Jun  4 15:07:50 2006
@@ -30,7 +30,7 @@
          href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: $id, tab: '${display/type:name}'}})" /></li>
     <li tal:repeat="format info/formats">
       <a i18n:translate="" tal:attributes="
-         href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({script: 
'/++skin++cpsskins/++resource++style_editor.js', form: {id: $id, display: 
$display_id, format: ${format/id}, uri: '${format/uri}', tab: 
'${format/name}'}})"
+         href 
string:javascript:CPSSkins.getModelById('element-editor').updateData({form: 
{id: $id, display: $display_id, format: ${format/id}, uri: '${format/uri}', 
tab: '${format/name}'}})"
        tal:content="format/name" /></li>
     <li>
       <a i18n:translate="" tal:attributes="
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to