Author: jmorliaguet
Date: Tue Mar  7 22:11:16 2006
New Revision: 2557

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- controllers must be registered again when panels are loaded

- fixed the drag-and-drop controller so that only draggable areas
  are dragged.



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Tue Mar  7 
22:11:16 2006
@@ -598,15 +598,10 @@
   new CPSSkins.Controller(), {
 
   setup: function() {
-    var dragEvent = this.dragEvent = this.dragEvent.bindAsEventListener(this);
+    this.dragEvent = this.dragEvent.bindAsEventListener(this);
     this.moveEvent = this.moveEvent.bindAsEventListener(this);
     this.dropEvent = this.dropEvent.bindAsEventListener(this);
 
-    (this.def.draggable || []).each(function(d) {
-      $$(d).each(function(el) {
-        Event.observe(el, "mousedown", dragEvent); });
-    });
-
     var dropzones = this._dropzones = [];
     (this.def.droppable || []).each(function(d) {
       $$(d).each(function(el) { dropzones.push(el); });
@@ -614,11 +609,25 @@
   },
 
   register: function(view) {
-    Event.observe(view.widget, "mousedown", this.dragEvent);
+    var dragEvent = this.dragEvent;
+    (this.def.draggable || []).each(function(d) {
+      $$(d).each(function(el) {
+        Event.observe(el, "mousedown", dragEvent);
+        el._cpsskins_draggable = true;
+      });
+    });
+  },
+
+  _findDraggable: function(e) {
+    var element = Event.element(e);
+    while (element.parentNode && !element._cpsskins_draggable) {
+      element = element.parentNode;
+    }
+    return element;
   },
 
   dragEvent: function(e) {
-    this.moved = Event.element(e);
+    this.moved = this._findDraggable(e);
     var pos = Position.page(this.moved);
     this.x0 = Event.pointerX(e) - pos[0];
     this.y0 = Event.pointerY(e) - pos[1];
@@ -651,7 +660,7 @@
 
 });
 
-CPSSkins.PerspectiveSelector= Class.create();
+CPSSkins.PerspectiveSelector = Class.create();
 CPSSkins.PerspectiveSelector.prototype = Object.extend(
   new CPSSkins.Controller(), {
 
@@ -1393,6 +1402,8 @@
     this.def = def;
 
     this.setup();
+
+    this.widget._is_cpsskins_widget = true;
   },
 
   hash: function() {
@@ -1421,6 +1432,10 @@
   },
 
   /* Private API */
+  getControllers: function() {
+    return this.def.controllers || []
+  },
+
   observe: function(model) {
     model.addObserver(this);
     this.model = model;
@@ -1620,6 +1635,18 @@
 CPSSkins.Panel = Class.create();
 CPSSkins.Panel.prototype = Object.extend(new CPSSkins.View(), {
 
+  setup: function() {
+    CPSSkins.registerEventHandler("panel loaded", this, function(event) {
+      var view = event.subscriber;
+      var controllers_id = view.getControllers();
+      controllers_id.each(function(c) {
+        var controller = CPSSkins.getControllerById(c);
+        if (controller) { controller.register(view); }
+      });
+    });
+    CPSSkins.subscribe("panel loaded", {'subscriber': this});
+  },
+
   inspect: function() {
     return '[CPSSkins Panel]';
   },
@@ -1641,11 +1668,13 @@
       CPSSkins.Canvas.addStyleSheet(this.css_id, css);
     }
 
+    var view = this;
     if (url) {
       var widget = this.widget;
       var options = {
         onComplete: function() {
           CPSSkins._parse(widget);
+          CPSSkins.notify("panel loaded", {'subscriber': view});
         }
       };
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to