From f0c294e58423365eb5e7d860d85f81365722a43a Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 10 Jan 2012 15:35:13 +0100 Subject: [ADD] Add options arguments to Dataset#read_index in order to provide custom contexts bzr revid: fme@openerp.com-20120110143513-00p14goadekz0y4z --- addons/web/static/src/js/data.js | 5 +++-- 1 file changed, 3 insertions(+), 2 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 c24325a9327..3b444dffc78 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -322,16 +322,17 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet * Reads the current dataset record (from its index) * * @params {Array} [fields] fields to read and return, by default all fields are returned + * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context * @params {Function} callback function called with read_index result * @returns {$.Deferred} */ - read_index: function (fields, callback) { + read_index: function (fields, options, callback) { var def = $.Deferred().then(callback); if (_.isEmpty(this.ids)) { def.reject(); } else { fields = fields || false; - this.read_ids([this.ids[this.index]], fields).then(function(records) { + this.read_ids([this.ids[this.index]], fields, options).then(function(records) { def.resolve(records[0]); }, function() { def.reject.apply(def, arguments); -- cgit v1.2.3 From e9ca86dd63a8b6c89ed4f9b263ae98bbe9be52a2 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 10 Jan 2012 17:54:51 +0100 Subject: [IMP] More dataset refactoring bzr revid: fme@openerp.com-20120110165451-pvchn668y0b1p645 --- addons/web/static/src/js/data.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 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 3b444dffc78..b75f241c047 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -293,16 +293,16 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet * * @param {Array} ids identifiers of the records to read * @param {Array} fields fields to read and return, by default all fields are returned - * @param {Function} callback function called with read result * @returns {$.Deferred} */ - read_ids: function (ids, fields, callback) { + read_ids: function (ids, fields, options) { + var options = options || {}; return this.rpc('/web/dataset/get', { model: this.model, ids: ids, fields: fields, - context: this.get_context() - }, callback); + context: this.get_context(options.context) + }); }, /** * Read a slice of the records represented by this DataSet, based on its @@ -312,22 +312,20 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet * @params {Object} options * @param {Number} [options.offset=0] The index from which selected records should be returned * @param {Number} [options.limit=null] The maximum number of records to return - * @param {Function} callback function called with read_slice result * @returns {$.Deferred} */ - read_slice: function (fields, options, callback) { - return null; + read_slice: function (fields, options) { + return null; }, /** * Reads the current dataset record (from its index) * * @params {Array} [fields] fields to read and return, by default all fields are returned * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context - * @params {Function} callback function called with read_index result * @returns {$.Deferred} */ - read_index: function (fields, options, callback) { - var def = $.Deferred().then(callback); + read_index: function (fields, options) { + var def = $.Deferred(); if (_.isEmpty(this.ids)) { def.reject(); } else { @@ -344,15 +342,16 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet * Reads default values for the current model * * @param {Array} [fields] fields to get default values for, by default all defaults are read - * @param {Function} callback function called with default_get result + * @param {Object} [options.context] context data to add to the request payload, on top of the DataSet's own context * @returns {$.Deferred} */ - default_get: function(fields, callback) { + default_get: function(fields, options) { + var options = options || {}; return this.rpc('/web/dataset/default_get', { model: this.model, fields: fields, - context: this.get_context() - }, callback); + context: this.get_context(options.context) + }); }, /** * Creates a new record in db @@ -504,14 +503,14 @@ openerp.web.DataSetStatic = openerp.web.DataSet.extend({ // all local records this.ids = ids || []; }, - read_slice: function (fields, options, callback) { + read_slice: function (fields, options) { // TODO remove fields from options var self = this, offset = options.offset || 0, limit = options.limit || false, fields = fields || false; var end_pos = limit && limit !== -1 ? offset + limit : this.ids.length; - return this.read_ids(this.ids.slice(offset, end_pos), fields, callback); + return this.read_ids(this.ids.slice(offset, end_pos), fields); }, set_ids: function (ids) { this.ids = ids; @@ -558,10 +557,9 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D * @param {Array} [options.domain] domain data to add to the request payload, ANDed with the dataset's domain * @param {Number} [options.offset=0] The index from which selected records should be returned * @param {Number} [options.limit=null] The maximum number of records to return - * @param {Function} callback function called with read_slice result * @returns {$.Deferred} */ - read_slice: function (fields, options, callback) { + read_slice: function (fields, options) { var self = this; var options = options || {}; var offset = options.offset || 0; @@ -577,7 +575,7 @@ openerp.web.DataSetSearch = openerp.web.DataSet.extend(/** @lends openerp.web.D self.ids = result.ids; self.offset = offset; return result.records; - }).then(callback); + }); }, get_domain: function (other_domain) { if (other_domain) { @@ -700,7 +698,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ this.delete_all = false; }, on_change: function() {}, - read_ids: function (ids, fields, callback) { + read_ids: function (ids, fields) { var self = this; var to_get = []; _.each(ids, function(id) { @@ -714,7 +712,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ to_get.push(id); } }); - var completion = $.Deferred().then(callback); + var completion = $.Deferred(); var return_records = function() { var records = _.map(ids, function(id) { return _.extend({}, _.detect(self.cache, function(c) {return c.id === id;}).values, {"id": id}); -- cgit v1.2.3 From 25283f304bc4e8dda595be608723188fb556c729 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 11 Jan 2012 09:49:52 +0100 Subject: [FIX] Refactoring leftovers bzr revid: fme@openerp.com-20120111084952-n7ghlby6uos5i0nb --- addons/web/static/src/js/data.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 b75f241c047..663e596acc5 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -629,8 +629,8 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ this.reset_ids([]); this.last_default_get = {}; }, - default_get: function(fields, callback) { - return this._super(fields).then(this.on_default_get).then(callback); + default_get: function(fields, options) { + return this._super(fields, options).then(this.on_default_get); }, on_default_get: function(res) { this.last_default_get = res; @@ -698,7 +698,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ this.delete_all = false; }, on_change: function() {}, - read_ids: function (ids, fields) { + read_ids: function (ids, fields, options) { var self = this; var to_get = []; _.each(ids, function(id) { @@ -725,7 +725,7 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({ completion.resolve(records); }; if(to_get.length > 0) { - var rpc_promise = this._super(to_get, fields, function(records) { + var rpc_promise = this._super(to_get, fields, options).then(function(records) { _.each(records, function(record, index) { var id = to_get[index]; var cached = _.detect(self.cache, function(x) {return x.id === id;}); @@ -774,8 +774,8 @@ openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({ return this._super.apply(this, arguments); } }, - default_get: function(fields, callback) { - return this._super(fields, callback).then(this.on_default_get); + default_get: function(fields, options) { + return this._super(fields, options).then(this.on_default_get); }, on_default_get: function(result) {}, create: function(data, callback, error_callback) { -- cgit v1.2.3 From 88eb2db8f93ee4770657bb36de67ffb10b3d9318 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 11 Jan 2012 17:29:23 +0100 Subject: [FIX] doc typo bzr revid: xmo@openerp.com-20120111162923-v1icuslj5jtcfme8 --- addons/web/static/src/js/data.js | 2 +- 1 file changed, 1 insertion(+), 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 663e596acc5..447b95d17cf 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -422,7 +422,7 @@ openerp.web.DataSet = openerp.web.Widget.extend( /** @lends openerp.web.DataSet * @param {Number} [domain_index] index of a domain to evaluate in the args array * @param {Number} [context_index] index of a context to evaluate in the args array * @param {Function} callback - * @param {Function }error_callback + * @param {Function} error_callback * @returns {$.Deferred} */ call_and_eval: function (method, args, domain_index, context_index, callback, error_callback) { -- cgit v1.2.3