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