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 2295ab0d5aa2511894838a2062906e496590e910 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 31 Oct 2012 15:37:23 +0100 Subject: [FIX] dataset methods to get their request context through Dataset#get_context if they go directly through the embedded model, child classes to DataSet don't get the occasion to override the generation/fetching of the context, and e.g. relational fields thus don't work correctly (as their field context isn't forwarded). bzr revid: xmo@openerp.com-20121031143723-j4q0t8cbzttela1r --- addons/web/static/src/js/data.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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..63c90f53758 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -471,7 +471,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ default_get: function(fields, options) { options = options || {}; return this._model.call('default_get', - [fields], {context: this._model.context(options.context)}); + [fields], {context: this.get_context(options.context)}); }, /** * Creates a new record in db @@ -480,7 +480,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @returns {$.Deferred} */ create: function(data) { - return this._model.call('create', [data], {context: this._model.context()}); + return this._model.call('create', [data], {context: this.get_context()}); }, /** * Saves the provided data in an existing db record @@ -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.get_context(options.context)}).then(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.get_context()}).then(this.trigger('dataset_changed', ids)); }, /** * Calls an arbitrary RPC method @@ -532,7 +532,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @returns {$.Deferred} */ name_get: function(ids) { - return this._model.call('name_get', [ids], {context: this._model.context()}); + return this._model.call('name_get', [ids], {context: this.get_context()}); }, /** * @@ -556,7 +556,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @param name */ name_create: function(name) { - return this._model.call('name_create', [name], {context: this._model.context()}); + return this._model.call('name_create', [name], {context: this.get_context()}); }, exec_workflow: function (id, signal) { return this._model.exec_workflow(id, signal); @@ -606,7 +606,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ return instance.session.rpc('/web/dataset/resequence', { model: this.model, ids: ids, - context: this._model.context(options.context), + context: this.get_context(options.context), }).pipe(function (results) { return results; }); -- cgit v1.2.3