From ca6c49becf9ce72e4f1a37f04bc89dae417be196 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 30 Oct 2012 15:06:30 +0100 Subject: [IMP] jQuery deferred API changes refactoring. Changed 'then's in 'done'/'fail' and 'pipe's in 'then' bzr revid: fme@openerp.com-20121030140630-gf20ye8fou1ebxft --- addons/web/static/src/js/data.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index e279ade6fb3..467b74040c7 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -66,7 +66,7 @@ instance.web.Query = instance.web.Class.extend({ offset: this._offset, limit: this._limit, sort: instance.web.serialize_sort(this._order_by) - }).pipe(function (results) { + }).then(function (results) { self._count = results.length; return results.records; }, null); @@ -78,7 +78,7 @@ instance.web.Query = instance.web.Class.extend({ */ first: function () { var self = this; - return this.clone({limit: 1})._execute().pipe(function (records) { + return this.clone({limit: 1})._execute().then(function (records) { delete self._count; if (records.length) { return records[0]; } return null; @@ -132,7 +132,7 @@ instance.web.Query = instance.web.Class.extend({ offset: this._offset, limit: this._limit, orderby: instance.web.serialize_sort(this._order_by) || false - }).pipe(function (results) { + }).then(function (results) { return _(results).map(function (result) { // FIX: querygroup initialization result.__context = result.__context || {}; @@ -443,7 +443,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ return this._model.query(fields) .limit(options.limit || false) .offset(options.offset || 0) - .all().then(function (records) { + .all().done(function (records) { self.ids = _(records).pluck('id'); }); }, @@ -456,7 +456,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ */ read_index: function (fields, options) { options = options || {}; - return this.read_ids([this.ids[this.index]], fields, options).pipe(function (records) { + return this.read_ids([this.ids[this.index]], fields, options).then(function (records) { if (_.isEmpty(records)) { return $.Deferred().reject().promise(); } return records[0]; }); @@ -493,7 +493,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ */ write: function (id, data, options) { options = options || {}; - return this._model.call('write', [[id], data], {context: this._model.context(options.context)}).then(this.trigger('dataset_changed', id, data, options)); + return this._model.call('write', [[id], data], {context: this._model.context(options.context)}).done(this.trigger('dataset_changed', id, data, options)); }, /** * Deletes an existing record from the database @@ -501,7 +501,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @param {Number|String} ids identifier of the record to delete */ unlink: function(ids) { - return this._model.call('unlink', [ids], {context: this._model.context()}).then(this.trigger('dataset_changed', ids)); + return this._model.call('unlink', [ids], {context: this._model.context()}).done(this.trigger('dataset_changed', ids)); }, /** * Calls an arbitrary RPC method @@ -607,7 +607,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ model: this.model, ids: ids, context: this._model.context(options.context), - }).pipe(function (results) { + }).then(function (results) { return results; }); }, @@ -682,9 +682,9 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({ .limit(options.limit || false); q = q.order_by.apply(q, this._sort); - return q.all().then(function (records) { + return q.all().done(function (records) { // FIXME: not sure about that one, *could* have discarded count - q.count().then(function (count) { self._length = count; }); + q.count().done(function (count) { self._length = count; }); self.ids = _(records).pluck('id'); }); }, @@ -693,7 +693,7 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({ }, unlink: function(ids, callback, error_callback) { var self = this; - return this._super(ids).then(function(result) { + return this._super(ids).done(function(result) { self.ids = _(self.ids).difference(ids); if (self._length) { self._length -= 1; @@ -722,7 +722,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ this.last_default_get = {}; }, default_get: function(fields, options) { - return this._super(fields, options).then(this.on_default_get); + return this._super(fields, options).done(this.on_default_get); }, on_default_get: function(res) { this.last_default_get = res; @@ -774,7 +774,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ this.cache = _.reject(this.cache, function(x) { return _.include(ids, x.id);}); this.set_ids(_.without.apply(_, [this.ids].concat(ids))); this.trigger("dataset_changed", ids, callback, error_callback); - return $.async_when({result: true}).then(callback); + return $.async_when({result: true}).done(callback); }, reset_ids: function(ids) { this.set_ids(ids); @@ -836,7 +836,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ completion.resolve(records); }; if(to_get.length > 0) { - var rpc_promise = this._super(to_get, fields, options).then(function(records) { + var rpc_promise = this._super(to_get, fields, options).done(function(records) { _.each(records, function(record, index) { var id = to_get[index]; var cached = _.detect(self.cache, function(x) {return x.id === id;}); @@ -991,14 +991,14 @@ instance.web.DropMisordered = instance.web.Class.extend({ var res = $.Deferred(); var self = this, seq = this.lsn++; - deferred.then(function () { + deferred.done(function () { if (seq > self.rsn) { self.rsn = seq; res.resolve.apply(res, arguments); } else if (self.failMisordered) { res.reject(); } - }, function () { + }).fail(function () { res.reject.apply(res, arguments); }); -- cgit v1.2.3 From 27c872cef382ab18532b55fd675fb1e6f316d568 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Sat, 10 Nov 2012 20:34:40 +0100 Subject: remove CallbackEnabled The on_/do_ binding still happens in Widget.init, but as we now use ES5 bind() it doesnt clutter stack traces anymore. However the fate of this automatic binding feature remains uncertain. bzr revid: al@openerp.com-20121110193440-78mpwamqx7iwq2ux --- addons/web/static/src/js/data.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 2f8679794b0..5bd7267b4a9 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -358,17 +358,15 @@ instance.web.Model = instance.web.Class.extend({ }, }); -instance.web.DataSet = instance.web.CallbackEnabled.extend({ +instance.web.DataSet = instance.web.Class.extend({ /** * Collection of OpenERP records, used to share records and the current selection between views. * * @constructs instance.web.DataSet - * @extends instance.web.CallbackEnabled * * @param {String} model the OpenERP model this dataset will manage */ init: function(parent, model, context) { - this._super(parent); this.model = model; this.context = context || {}; this.index = null; -- cgit v1.2.3 From 521f52caff93353ba24921e5c6292f83fb94844a Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Sat, 10 Nov 2012 23:28:22 +0100 Subject: [FIX] dataset class bzr revid: al@openerp.com-20121110222822-ey7vzl7excr70j9k --- addons/web/static/src/js/data.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/data.js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 5bd7267b4a9..dcdeb749672 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -358,7 +358,7 @@ instance.web.Model = instance.web.Class.extend({ }, }); -instance.web.DataSet = instance.web.Class.extend({ +instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, { /** * Collection of OpenERP records, used to share records and the current selection between views. * @@ -367,6 +367,7 @@ instance.web.DataSet = instance.web.Class.extend({ * @param {String} model the OpenERP model this dataset will manage */ init: function(parent, model, context) { + instance.web.PropertiesMixin.init.call(this); this.model = model; this.context = context || {}; this.index = null; -- cgit v1.2.3