[Z3lab-checkins] r2266 - azax/branches/snowsprint/tests

2006-02-02 Thread svn
Author: bree
Date: Thu Feb  2 09:07:30 2006
New Revision: 2266

Modified:
   azax/branches/snowsprint/tests/test_azaxview.py
Log:
test code import changing

Modified: azax/branches/snowsprint/tests/test_azaxview.py
==
--- azax/branches/snowsprint/tests/test_azaxview.py (original)
+++ azax/branches/snowsprint/tests/test_azaxview.py Thu Feb  2 09:07:30 2006
@@ -28,8 +28,6 @@
 from Globals import InitializeClass
 from OFS.SimpleItem import SimpleItem
 from zope.publisher.browser import TestRequest
-import Products.Five
-from Products.Five.zcml import load_string, load_config
 from textwrap import dedent
 
 # Fake content
@@ -52,22 +50,29 @@
 fakerequest = TestRequest()
 self.view = AzaxBaseView(fakecontent, fakerequest)
 # Allow traversing
-load_config('meta.zcml', package=Products.Five)
-load_string(dedent('''\
-configure xmlns=http://namespaces.zope.org/zope;
-   xmlns:five=http://namespaces.zope.org/five;
-include package=zope.app.traversing /
-adapter
-  for=*
-  factory=Products.Five.traversable.FiveTraversable
-  
provides=zope.app.traversing.interfaces.ITraversable
-  /
-  !--adapter
-  for=*
-  factory=zope.app.traversing.adapters.Traverser
-  provides=zope.app.traversing.interfaces.ITraverser
-  /--
-/configure'''))
+try:
+import Products.Five
+except ImportError:
+# probably zope 3
+pass
+else:
+from Products.Five.zcml import load_string, load_config
+load_config('meta.zcml', package=Products.Five)
+load_string(dedent('''\
+configure xmlns=http://namespaces.zope.org/zope;
+   xmlns:five=http://namespaces.zope.org/five;
+include package=zope.app.traversing /
+adapter
+  for=*
+  
factory=Products.Five.traversable.FiveTraversable
+  
provides=zope.app.traversing.interfaces.ITraversable
+  /
+  !--adapter
+  for=*
+  factory=zope.app.traversing.adapters.Traverser
+  
provides=zope.app.traversing.interfaces.ITraverser
+  /--
+/configure'''))
 
 class TestAzaxView(AzaxViewTestCase):
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins


[Z3lab-checkins] r2267 - azax/branches/snowsprint

2006-02-02 Thread svn
Author: bree
Date: Thu Feb  2 10:36:44 2006
New Revision: 2267

Added:
   azax/branches/snowsprint/BeautifulSoup.py
Modified:
   azax/branches/snowsprint/azaxview.py
Log:
Fixing HTML namespace problem (needed for IE)

- by introducing wrapped parsers, at the moment BeautifulSoup
  is used


Added: azax/branches/snowsprint/BeautifulSoup.py
==
--- (empty file)
+++ azax/branches/snowsprint/BeautifulSoup.py   Thu Feb  2 10:36:44 2006
@@ -0,0 +1,1080 @@
+Beautiful Soup
+Elixir and Tonic
+The Screen-Scraper's Friend
+v2.1.1
+http://www.crummy.com/software/BeautifulSoup/
+
+Beautiful Soup parses arbitrarily invalid XML- or HTML-like substance
+into a tree representation. It provides methods and Pythonic idioms
+that make it easy to search and modify the tree.
+
+A well-formed XML/HTML document will yield a well-formed data
+structure. An ill-formed XML/HTML document will yield a
+correspondingly ill-formed data structure. If your document is only
+locally well-formed, you can use this library to find and process the
+well-formed part of it. The BeautifulSoup class has heuristics for
+obtaining a sensible parse tree in the face of common HTML errors.
+
+Beautiful Soup has no external dependencies. It works with Python 2.2
+and up.
+
+Beautiful Soup defines classes for four different parsing strategies:
+
+ * BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific
+   language that kind of looks like XML.
+
+ * BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid
+   or invalid.
+
+ * ICantBelieveItsBeautifulSoup, for parsing valid but bizarre HTML
+   that trips up BeautifulSoup.
+
+ * BeautifulSOAP, for making it easier to parse XML documents that use
+   lots of subelements containing a single string, where you'd prefer
+   they put that string into an attribute (such as SOAP messages).
+
+You can subclass BeautifulStoneSoup or BeautifulSoup to create a
+parsing strategy specific to an XML schema or a particular bizarre
+HTML document. Typically your subclass would just override
+SELF_CLOSING_TAGS and/or NESTABLE_TAGS.
+
+from __future__ import generators
+
+__author__ = Leonard Richardson ([EMAIL PROTECTED])
+__version__ = 2.1.1
+__date__ = $Date: 2004/10/18 00:14:20 $
+__copyright__ = Copyright (c) 2004-2005 Leonard Richardson
+__license__ = PSF
+
+from sgmllib import SGMLParser, SGMLParseError
+import types
+import re
+import sgmllib
+
+#This code makes Beautiful Soup able to parse XML with namespaces
+sgmllib.tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*')
+
+class NullType(object):
+
+Similar to NoneType with a corresponding singleton instance
+'Null' that, unlike None, accepts any message and returns itself.
+
+Examples:
+ Null(send, a, message)(and one more,
+...  and what you get still) is Null
+True
+
+
+def __new__(cls):return Null
+def __call__(self, *args, **kwargs): return Null
+##def __getstate__(self, *args):   return Null
+def __getattr__(self, attr): return Null
+def __getitem__(self, item): return Null
+def __setattr__(self, attr, value):  pass
+def __setitem__(self, item, value):  pass
+def __len__(self):   return 0
+# FIXME: is this a python bug? otherwise ``for x in Null: pass``
+#never terminates...
+def __iter__(self):  return iter([])
+def __contains__(self, item):return False
+def __repr__(self):  return Null
+Null = object.__new__(NullType)
+
+class PageElement:
+Contains the navigational information for some part of the page
+(either a tag or a piece of text)
+
+def setup(self, parent=Null, previous=Null):
+Sets up the initial relations between this element and
+other elements.
+self.parent = parent
+self.previous = previous
+self.next = Null
+self.previousSibling = Null
+self.nextSibling = Null
+if self.parent and self.parent.contents:
+self.previousSibling = self.parent.contents[-1]
+self.previousSibling.nextSibling = self
+
+def findNext(self, name=None, attrs={}, text=None):
+Returns the first item that matches the given criteria and
+appears after this Tag in the document.
+return self._first(self.fetchNext, name, attrs, text)
+firstNext = findNext
+
+def fetchNext(self, name=None, attrs={}, text=None, limit=None):
+Returns all items that match the given criteria and appear
+before after Tag in the document.
+return self._fetch(name, attrs, text, limit, self.nextGenerator)
+
+def findNextSibling(self, name=None, attrs={}, text=None):
+Returns the closest sibling to this Tag that matches the
+given criteria and appears after this Tag in the document.
+return self._first(self.fetchNextSiblings, name, attrs, text)

[Z3lab-checkins] r2268 - cpsskins/branches/jmo-perspectives/ui/framework

2006-02-02 Thread svn
Author: jmorliaguet
Date: Thu Feb  2 13:51:09 2006
New Revision: 2268

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

- added a simple event system to make it possible for the model to send events
  and the views to react to events.

  this is needed for compound storages

  observers now use the event system (they subscribe to the 'modified' event)



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 Thu Feb  2 
13:51:09 2006
@@ -34,7 +34,9 @@
 }
 
 var CPSSkins = {
-  Version: 0.5,
+  Version: 0.6,
+
+  Subscribers: $H({}),
 
   Models: $H({}),
 
@@ -73,10 +75,56 @@
 return controller;
   },
 
+  /* Public events */
   registerHandlers: function(handlers) {
 Object.extend(CPSSkins.Handlers, handlers);
   },
 
+  /* Internal events */
+  subscribe: function(obj, event) {
+if (!(event in CPSSkins.Subscribers)) {
+  CPSSkins.Subscribers[event] = $A([]);
+}
+CPSSkins.Subscribers[event].push(obj);
+  },
+
+  unsubscribe: function(obj, event) {
+new_subscribers = $A([]);
+CPSSkins.Subscribers[event].each(function(s) {
+  if (obj != s) {
+new_subscribers.push(s);
+  }
+});
+CPSSkins.Subscribers[event] = new_subscribers;
+  },
+
+  notify: function(context, event) {
+var subscribers = CPSSkins.Subscribers[event];
+$A(subscribers).each(function(s) {
+  var handler = CPSSkins.getEventHandler(s, event);
+  if (handler) handler(s, context);
+});
+  },
+
+  registerEventHandler: function(subscriber, event, handler) {
+var handlers = subscriber._handlers;
+if (!handlers) {
+  subscriber._handlers = new Object();
+}
+subscriber._handlers[event] = handler;
+  },
+
+  getEventHandler: function(subscriber, event) {
+var handlers = subscriber._handlers;
+if (handlers) {
+  return handlers[event];
+} else {
+  return null;
+}
+  },
+
+  /* Document parsing */
+
   jsonParse: function(el) {
 var res = null;
 var text = el.innerHTML;
@@ -567,8 +615,6 @@
   initialize: function(node, def) {
 this.node = this.node;
 this.def = def;
-// observers
-this.observers = $H({});
 // set the storage adapter
 this._setStorageAdapter();
   },
@@ -589,7 +635,13 @@
   },
 
   addObserver: function(view) {
-this.observers[view.id] = view;
+// register an event handler for the 'modified' event
+view.registerEventHandler('modified', function(v, context) {
+  var data = v.model.def.data;
+  v.render(data);
+});
+// subscribe to 'modified' events
+view.subscribeTo('modified');
 // create a back-reference
 view.model = this;
 // initialize the view
@@ -597,14 +649,7 @@
   },
 
   removeObserver: function(view) {
-delete this.observers[view.id];
-  },
-
-  notifyObservers: function(data) {
-// XXX: should use notify() instead, but there is no event system.
-$H(this.observers).each(function(m) {
-  m[1].render(data);
-});
+view.unsubscribeFrom('modified');
   },
 
   _setStorageAdapter: function() {
@@ -674,7 +719,6 @@
 var model = this.model;
 $A(this.models).each(function(m) {
   m.storage.requestData();
-  Object.extend(model.def.data, m.def.data);
 });
   },
 
@@ -704,7 +748,7 @@
   storeData: function(data) {
 /* Store the data directly */
 this.model.def.data = data;
-this.model.notifyObservers(data);
+CPSSkins.notify(this.model, 'modified');
   }
 
 });
@@ -720,7 +764,7 @@
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-model.notifyObservers(data);
+CPSSkins.notify(model, 'modified');
   }
 });
   },
@@ -738,7 +782,7 @@
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-model.notifyObservers(data);
+CPSSkins.notify(model, 'modified');
   }
 });
   }
@@ -783,6 +827,18 @@
 
   /* Private API */
 
+  subscribeTo: function(event) {
+CPSSkins.subscribe(this, event);
+  },
+
+  registerEventHandler: function(event, handler) {
+CPSSkins.registerEventHandler(this, event, handler);
+  },
+
+  unsubscribeFrom: function(event) {
+CPSSkins.unsubscribe(this, event);
+  },
+
   observe: function(model) {
 model.addObserver(this);
 this.model = model;
@@ -1195,7 +1251,7 @@
 if (confirm) {
   if (!window.confirm(confirm)) return;
 }
-/* notify the controller */
+/* notify the controller to take action */
 this.handleAction(this.selected, action, choice);
 this.active = false;
   },
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins


[Z3lab-checkins] r2269 - cpsskins/branches/jmo-perspectives/ui/framework

2006-02-02 Thread svn
Author: jmorliaguet
Date: Thu Feb  2 13:56:51 2006
New Revision: 2269

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

- removed by accident



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 Thu Feb  2 
13:56:51 2006
@@ -719,6 +719,7 @@
 var model = this.model;
 $A(this.models).each(function(m) {
   m.storage.requestData();
+  Object.extend(model.def.data, m.def.data)
 });
   },
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins


[Z3lab-checkins] r2271 - in azax/branches/snowsprint: . browser tests

2006-02-02 Thread svn
Author: bree
Date: Thu Feb  2 16:40:42 2006
New Revision: 2271

Added:
   azax/branches/snowsprint/tests/kukitresponse_test.pt
Modified:
   azax/branches/snowsprint/azaxview.py
   azax/branches/snowsprint/browser/kukitresponse.pt
Log:
Fixing IE support for entities.

(test is not yet finished)

Modified: azax/branches/snowsprint/azaxview.py
==
--- azax/branches/snowsprint/azaxview.py(original)
+++ azax/branches/snowsprint/azaxview.pyThu Feb  2 16:40:42 2006
@@ -58,8 +58,8 @@
 
 def __init__(self, value):
 self.soup = self.BeautifulSoup(value)
-for param in self.soup.fetch('kukit:param', {'name': 'html'}):
-param['xmlns'] = http://www.w3.org/1999/xhtml;
+for tag in self.soup:
+tag['xmlns'] = http://www.w3.org/1999/xhtml;
 
 def __call__(self):
 return str(self.soup)
@@ -121,6 +121,15 @@
 # XML output gets rendered via a page template
 render = ViewPageTemplateFile('browser/kukitresponse.pt', 
content_type='text/xml')
 
+# XXX test only, hardcoded HTML for the first button of the first demo
+##render = ViewPageTemplateFile('tests/kukitresponse_test.pt', 
content_type='text/xml')
+
+# fix for IE
+_render = render
+def render(self):
+result = self._render()
+return result.replace('nbsp;', '#160;')
+
 def __init__(self, context, request):
 BrowserView.__init__(self, context, request)
 self.commands = []

Modified: azax/branches/snowsprint/browser/kukitresponse.pt
==
--- azax/branches/snowsprint/browser/kukitresponse.pt   (original)
+++ azax/branches/snowsprint/browser/kukitresponse.pt   Thu Feb  2 16:40:42 2006
@@ -1,4 +1,4 @@
-!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
file:///var/lib/zope2.8/instance/kukit/Products/azax/dtds/xhtml1-transitional.dtd
+!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
   xmlns:kukit=http://www.kukit.org/commands/1.0;
   xmlns:tal=http://xml.zope.org/namespaces/tal;

Added: azax/branches/snowsprint/tests/kukitresponse_test.pt
==
--- (empty file)
+++ azax/branches/snowsprint/tests/kukitresponse_test.ptThu Feb  2 
16:40:42 2006
@@ -0,0 +1,16 @@
+!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
+html xmlns=http://www.w3.org/1999/xhtml; 
+ xmlns:kukit=http://www.kukit.org/commands/1.0;
+   body
+   kukit:command selector=div#demo name=setHtmlAsChild
+   kukit:param name=html
+   h1 xmlns=http://www.w3.org/1999/xhtml;it 
worked/h1
+   /kukit:param
+   /kukit:command
+   kukit:command selector=div#demo name=setHtmlAsChild
+   kukit:param name=html
+   h1 xmlns=http://www.w3.org/1999/xhtml;it 
workednbsp;again (test)/h1
+   /kukit:param
+   /kukit:command
+   /body
+/html
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins


[Z3lab-checkins] r2273 - cpsskins/branches/jmo-perspectives/ui/framework/tests/unit

2006-02-02 Thread svn
Author: jmorliaguet
Date: Thu Feb  2 20:11:15 2006
New Revision: 2273

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
Log:

- added tests for subscribers



Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
==
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html   
(original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html   
Thu Feb  2 20:11:15 2006
@@ -378,6 +378,47 @@
 
 }},
 
+/* Events */
+
+testSubscribe: function() { with(this) {
+  var info;
+  var handler1 = function(subscriber, context) {
+info = {'subscriber': subscriber.id, 'context': context.id};
+  }
+
+  var obj1 = new Object({'id': 'object1'});
+  var context1 = new Object({'id': 'context1'});
+  var context2 = new Object({'id': 'context2'});
+
+  CPSSkins.registerEventHandler(obj1, 'event1', handler1);
+  CPSSkins.subscribe(obj1, 'event1');
+
+  assertEqual($H(info).inspect(), $H({}).inspect());
+
+  var info = null;
+  CPSSkins.notify(context1, 'event2');
+  assertEqual($H(info).inspect(), $H({}).inspect());
+
+  var info = null;
+  CPSSkins.notify(context1, 'event1');
+  assertEqual($H(info).inspect(),
+  $H({subscriber:object1,context:context1}).inspect());
+
+  var info = null;
+  CPSSkins.notify(context2, 'event1');
+  assertEqual($H(info).inspect(),
+  $H({subscriber:object1,context:context2}).inspect());
+
+  CPSSkins.unsubscribe(obj1, 'event1');
+
+  var info = null;
+  CPSSkins.notify(context1, 'event1');
+  assertEqual($H(info).inspect(), $H({}).inspect());
+
+}},
+
+/* Perspectives */
+
 testSwitchPerspectives: function() { with(this) {
   var p1 = $(p1).parentNode;
   var p1_2 = $(p1_2).parentNode;
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins


[Z3lab-checkins] r2274 - in cpsskins/branches/jmo-perspectives/ui/framework: . tests/unit tests/zope3

2006-02-02 Thread svn
Author: jmorliaguet
Date: Thu Feb  2 23:03:24 2006
New Revision: 2274

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
Log:

- the event object now specifies both a subscriber and a target
  (the observed object) otherwise too many events need to be handled and
  it becomes difficult to get access the targetted object.



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 Thu Feb  2 
23:03:24 2006
@@ -81,43 +81,45 @@
   },
 
   /* Internal events */
-  subscribe: function(obj, event) {
-if (!(event in CPSSkins.Subscribers)) {
-  CPSSkins.Subscribers[event] = $A([]);
+  subscribe: function(eventid, event) {
+if (!(eventid in CPSSkins.Subscribers)) {
+  CPSSkins.Subscribers[eventid] = $A([]);
 }
-CPSSkins.Subscribers[event].push(obj);
+CPSSkins.Subscribers[eventid].push(event);
   },
 
-  unsubscribe: function(obj, event) {
+  unsubscribe: function(eventid, event) {
 new_subscribers = $A([]);
-CPSSkins.Subscribers[event].each(function(s) {
-  if (obj != s) {
-new_subscribers.push(s);
+CPSSkins.Subscribers[eventid].each(function(e) {
+  if (event.subscriber != e.subscriber  event.target != e.target) {
+new_subscribers.push(e);
   }
 });
-CPSSkins.Subscribers[event] = new_subscribers;
+CPSSkins.Subscribers[eventid] = new_subscribers;
   },
 
-  notify: function(context, event) {
-var subscribers = CPSSkins.Subscribers[event];
-$A(subscribers).each(function(s) {
-  var handler = CPSSkins.getEventHandler(s, event);
-  if (handler) handler(s, context);
+  notify: function(eventid, target) {
+var subscribers = CPSSkins.Subscribers[eventid];
+$A(subscribers).each(function(e) {
+  if (e.target == target) {
+var handler = CPSSkins.getEventHandler(eventid, e.subscriber);
+if (handler) handler(e);
+  }
 });
   },
 
-  registerEventHandler: function(subscriber, event, handler) {
+  registerEventHandler: function(eventid, subscriber, handler) {
 var handlers = subscriber._handlers;
 if (!handlers) {
   subscriber._handlers = new Object();
 }
-subscriber._handlers[event] = handler;
+subscriber._handlers[eventid] = handler;
   },
 
-  getEventHandler: function(subscriber, event) {
+  getEventHandler: function(eventid, subscriber) {
 var handlers = subscriber._handlers;
 if (handlers) {
-  return handlers[event];
+  return handlers[eventid];
 } else {
   return null;
 }
@@ -635,21 +637,22 @@
   },
 
   addObserver: function(view) {
+var model = this;
 // register an event handler for the 'modified' event
-view.registerEventHandler('modified', function(v, context) {
-  var data = v.model.def.data;
-  v.render(data);
+CPSSkins.registerEventHandler('modified', view, function(event) {
+var data = event.target.def.data;
+event.subscriber.render(data);
 });
-// subscribe to 'modified' events
-view.subscribeTo('modified');
+// subscribe to 'modified' events on the model
+CPSSkins.subscribe('modified', {'subscriber': view, 'target': model});
 // create a back-reference
-view.model = this;
+view.model = model;
 // initialize the view
 view.update();
   },
 
   removeObserver: function(view) {
-view.unsubscribeFrom('modified');
+CPSSkins.unsubscribe('modified', {'subscriber': view, 'target': model});
   },
 
   _setStorageAdapter: function() {
@@ -749,7 +752,7 @@
   storeData: function(data) {
 /* Store the data directly */
 this.model.def.data = data;
-CPSSkins.notify(this.model, 'modified');
+CPSSkins.notify('modified', this.model);
   }
 
 });
@@ -765,7 +768,7 @@
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-CPSSkins.notify(model, 'modified');
+CPSSkins.notify('modified', model);
   }
 });
   },
@@ -783,7 +786,7 @@
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-CPSSkins.notify(model, 'modified');
+CPSSkins.notify('modified', model);
   }
 });
   }
@@ -828,18 +831,6 @@
 
   /* Private API */
 
-  subscribeTo: function(event) {
-CPSSkins.subscribe(this, event);
-  },
-
-  registerEventHandler: function(event, handler) {
-CPSSkins.registerEventHandler(this, event, handler);
-  },
-
-  unsubscribeFrom: function(event) {
-CPSSkins.unsubscribe(this, event);
-  },
-
   observe: function(model) {
 model.addObserver(this);
   

[Z3lab-checkins] r2276 - cpsskins/branches/jmo-perspectives/ui/framework

2006-02-02 Thread svn
Author: jmorliaguet
Date: Thu Feb  2 23:29:07 2006
New Revision: 2276

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

- better decoupling between storage / model / view: 

  the storage notifies the model when some data gets stored and the model
  notifies the view that the data as changed (which can be done asynchronously).



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 Thu Feb  2 
23:29:07 2006
@@ -638,12 +638,11 @@
 
   addObserver: function(view) {
 var model = this;
-// register an event handler for the 'modified' event
+// observers subscribes to events on the model
 CPSSkins.registerEventHandler('modified', view, function(event) {
 var data = event.target.def.data;
 event.subscriber.render(data);
 });
-// subscribe to 'modified' events on the model
 CPSSkins.subscribe('modified', {'subscriber': view, 'target': model});
 // create a back-reference
 view.model = model;
@@ -661,6 +660,15 @@
   storage_def = {type: volatile};
 }
 this.storage = Storages[storage_def.type](this);
+
+var model = this;
+// the model reacts to events on the storage and notifies observers
+CPSSkins.registerEventHandler('stored', model, function(event) {
+  CPSSkins.notify('modified', model);
+});
+
+CPSSkins.subscribe('stored', {'subscriber': model, 'target': 
this.storage});
+
   }
 
 }
@@ -752,7 +760,7 @@
   storeData: function(data) {
 /* Store the data directly */
 this.model.def.data = data;
-CPSSkins.notify('modified', this.model);
+CPSSkins.notify('stored', this);
   }
 
 });
@@ -763,12 +771,14 @@
 
   requestData: function() {
 var model = this.model;
+var storage = this;
+
 var url = model.def.storage.accessors.get;
 new Ajax.Request(url, {
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-CPSSkins.notify('modified', model);
+CPSSkins.notify('stored', storage);
   }
 });
   },
@@ -776,6 +786,7 @@
   storeData: function(data) {
 var model = this.model;
 model.def.data = data;
+var storage = this;
 
 var url = model.def.storage.accessors.set;
 new Ajax.Request(url, {
@@ -786,7 +797,7 @@
   onComplete: function(req) {
 var data = JSON.parse(req.responseText);
 model.def.data = data;
-CPSSkins.notify('modified', model);
+CPSSkins.notify('stored', storage);
   }
 });
   }
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins