Author: jmorliaguet Date: Sat Feb 25 23:06:41 2006 New Revision: 2470 Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Log:
- fixes: the model's data is stored in model._data and the data schema definition is in model.def.data - added low-level IO methods (readData / getData) 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 Sat Feb 25 23:06:41 2006 @@ -951,11 +951,20 @@ this.storage = this._setStorageAdapter(); }, - // high-level I/O + // low-level I/O readData: function() { - return this.storage.read(); + return this._data || this.def.data; + }, + + writeData: function(data) { + this._data = data; }, + hasData: function() { + return this._data != undefined; + }, + + // high-level I/O getData: function() { this.storage.readTransaction(); /* asynchronous call */ return this.readData(); @@ -975,7 +984,7 @@ var model = this; // observers subscribes to events on the model CPSSkins.registerEventHandler('modified', view, function(event) { - var data = event.publisher.def.data; + var data = event.publisher.readData(); event.subscriber.display(data); }); CPSSkins.subscribe('modified', {'subscriber': view, 'publisher': model}); @@ -1078,7 +1087,8 @@ // low-level I/O read: function() { - return this.model.def.data; + // TODO implement a policy for reading data + return this.model.readData(); }, write: function(data) { @@ -1107,19 +1117,19 @@ _storeFields: function(data) { // filter out fields with the wrong data type var schema = this.model.schema; - var filtered_data = new Object(); + var new_data = new Object(); schema.each(function(f) { var field = f.key; var value = data[field]; if (value != null && typeof value == f.value) { - filtered_data[field] = value; + new_data[field] = value; } }); - if (!this._compareData(this.model.def.data, filtered_data)) {; - this.model.def.data = filtered_data; + if (!this.model.hasData() || !this._compareData(this.read(), new_data)) {; + this.model.writeData(new_data); CPSSkins.notify('stored', {'publisher': this}); } - return filtered_data; + return new_data; }, _compareData: function(a, b) { @@ -1903,7 +1913,7 @@ var model = CPSSkins.Canvas.getModel(selected); if (!model) return; - var data = model.def.data; + var data = model.readData(); if (!data) return; if (data.hint == null) return; -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins