Author: jmorliaguet
Date: Sun Mar 19 12:52:19 2006
New Revision: 2659

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

- added a "Location Controller", which intercepts click events on links and
  make it possible to update the model without reloading the entire page.

  (useful to navigate inside a same panel, or to get data / perform an action
   on the server without changing the page's url)



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 Sun Mar 19 
12:52:19 2006
@@ -469,6 +469,10 @@
     return new CPSSkins.FormController(node, def);
   },
 
+  'location': function(node, def) {
+    return new CPSSkins.LocationController(node, def);
+  },
+
   'focus observer': function(node, def) {
     return new CPSSkins.FocusObserver(node, def);
   },
@@ -535,8 +539,7 @@
           var handler_name = s.value;
           var handler = CPSSkins._handlers[handler_name];
           selector.each(function(el) {
-            Event.observe(el, event_name,
-              handler.bindAsEventListener(info));
+            Event.observe(el, event_name, handler.bindAsEventListener(info));
           });
         })
       }
@@ -581,6 +584,41 @@
 
 });
 
+CPSSkins.LocationController = Class.create();
+CPSSkins.LocationController.prototype = Object.extend(
+  new CPSSkins.Controller(), {
+
+  setup: function() {
+    this.clickEvent = this.clickEvent.bindAsEventListener(this);
+  },
+
+  register: function(view) {
+    Event.observe(view.widget, "click", this.clickEvent);
+  },
+
+  unregister: function(view) {
+    Event.stopObserving(view.widget, "click", this.clickEvent);
+  },
+
+  clickEvent: function(e) {
+    var target = Event.element(e);
+    if (target.tagName.toLowerCase() == 'a') {
+      var url = target.href;
+
+      var views = this.views;
+      var location_field = this.def.location_field || 'url';
+      views.each(function(v) {
+        var view = CPSSkins.getViewById(v);
+        var model = view.model;
+        if (model) model.setData({location_field: url});
+      });
+
+      Event.stop(e);
+    }
+  }
+
+});
+
 CPSSkins.FocusObserver = Class.create();
 CPSSkins.FocusObserver.prototype = Object.extend(new CPSSkins.Controller(), {
 
@@ -1543,7 +1581,7 @@
     }
     var parts = url.split('?');
     if (parts.length == 2) {
-      var url = parts[0];
+      url = parts[0];
       options.parameters = parts[1];
     }
     new Ajax.Request(url, options);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to