diff options
| author | Christophe Simonis <chs@openerp.com> | 2013-06-13 19:39:00 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@openerp.com> | 2013-06-13 19:39:00 +0200 |
| commit | a61e7cb0c80ae773cab9753bd8a4e7e888bbf415 (patch) | |
| tree | 019a235869a5e087055700895d4584c80e2f9afb /addons/web/static/src/js/data.js | |
| parent | 5ed0ac2614b9430e61dae472d657a21c037d6ee9 (diff) | |
| parent | 180e6e41d81e28df43b41e3cb6131225d4169a28 (diff) | |
[MERGE] forward port of branch saas-1 up to revid 4887 chs@openerp.com-20130612153934-qyp6pb3bc4za4taf
bzr revid: chs@openerp.com-20130613172414-dln3g4j0ykcwaa02
bzr revid: chs@openerp.com-20130613173900-xl7rh321nnw2b04b
Diffstat (limited to 'addons/web/static/src/js/data.js')
| -rw-r--r-- | addons/web/static/src/js/data.js | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index f1b043bacf9..679afe77bcd 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -112,24 +112,27 @@ instance.web.Query = instance.web.Class.extend({ * @returns {jQuery.Deferred<Array<openerp.web.QueryGroup>> | null} */ group_by: function (grouping) { - if (grouping === undefined) { - return null; + var ctx = instance.web.pyeval.eval( + 'context', this._model.context(this._context)); + + // undefined passed in explicitly (!) + if (_.isUndefined(grouping)) { + grouping = []; } if (!(grouping instanceof Array)) { grouping = _.toArray(arguments); } - if (_.isEmpty(grouping)) { return null; } + if (_.isEmpty(grouping) && !ctx['group_by_no_leaf']) { + return null; + } var self = this; - - var ctx = instance.web.pyeval.eval( - 'context', this._model.context(this._context)); return this._model.call('read_group', { groupby: grouping, fields: _.uniq(grouping.concat(this._fields || [])), domain: this._model.domain(this._filter), - context: this._model.context(this._context), + context: ctx, offset: this._offset, limit: this._limit, orderby: instance.web.serialize_sort(this._order_by) || false @@ -325,7 +328,7 @@ instance.web.Model = instance.web.Class.extend({ * Fetches the model's domain, combined with the provided domain if any * * @param {Array} [domain] to combine with the model's internal domain - * @returns The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain + * @returns {instance.web.CompoundDomain} The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain */ domain: function (domain) { if (!domain) { return this._domain; } @@ -337,7 +340,7 @@ instance.web.Model = instance.web.Class.extend({ * combined with the provided context if any * * @param {Object} [context] to combine with the model's internal context - * @returns The union of the user's context and the model's internal context, as well as the provided context if any. In that order. + * @returns {instance.web.CompoundContext} The union of the user's context and the model's internal context, as well as the provided context if any. In that order. */ context: function (context) { return new instance.web.CompoundContext( @@ -487,7 +490,12 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, * @returns {$.Deferred} */ create: function(data, options) { - return this._model.call('create', [data], {context: this.get_context()}); + var self = this; + return this._model.call('create', [data], { + context: this.get_context() + }).done(function () { + self.trigger('dataset_changed', data, options) + }); }, /** * Saves the provided data in an existing db record @@ -502,7 +510,12 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, */ write: function (id, data, options) { options = options || {}; - return this._model.call('write', [[id], data], {context: this.get_context(options.context)}).done(this.trigger('dataset_changed', id, data, options)); + var self = this; + return this._model.call('write', [[id], data], { + context: this.get_context(options.context) + }).done(function () { + self.trigger('dataset_changed', id, data, options) + }); }, /** * Deletes an existing record from the database @@ -510,7 +523,12 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, * @param {Number|String} ids identifier of the record to delete */ unlink: function(ids) { - return this._model.call('unlink', [ids], {context: this.get_context()}).done(this.trigger('dataset_changed', ids)); + var self = this; + return this._model.call('unlink', [ids], { + context: this.get_context() + }).done(function () { + self.trigger('dataset_changed', ids) + }); }, /** * Calls an arbitrary RPC method @@ -604,6 +622,13 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, alter_ids: function(n_ids) { this.ids = n_ids; }, + remove_ids: function (ids) { + this.alter_ids(_(this.ids).difference(ids)); + }, + add_ids: function(ids, at) { + var args = [at, 0].concat(_.difference(ids, this.ids)); + this.ids.splice.apply(this.ids, args); + }, /** * Resequence records. * @@ -701,22 +726,28 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({ get_domain: function (other_domain) { this._model.domain(other_domain); }, + alter_ids: function (ids) { + this._super(ids); + if (this.index !== null && this.index >= this.ids.length) { + this.index = this.ids.length > 0 ? this.ids.length - 1 : 0; + } + }, + remove_ids: function (ids) { + var before = this.ids.length; + this._super(ids); + if (this._length) { + this._length -= (before - this.ids.length); + } + }, unlink: function(ids, callback, error_callback) { var self = this; return this._super(ids).done(function(result) { - self.ids = _(self.ids).difference(ids); - if (self._length) { - self._length -= 1; - } - if (self.index !== null) { - self.index = self.index <= self.ids.length - 1 ? - self.index : (self.ids.length > 0 ? self.ids.length -1 : 0); - } + self.remove_ids( ids); self.trigger("dataset_changed", ids, callback, error_callback); }); }, size: function () { - if (this._length !== undefined) { + if (this._length != null) { return this._length; } return this._super(); |
