summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/data.js
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-06-21 15:52:07 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-06-21 15:52:07 +0200
commitd57bbfd2ffc43d0f3f5b8c0dbe385a2ab549349f (patch)
treee52365d007531c6173831d306b39b69065370472 /addons/web/static/src/js/data.js
parent6a82e64e4d119f3aecaa21bc39b70e46723f0f45 (diff)
parent5157561cb12719e15994ab418a2e84f84f454182 (diff)
merge trunk
bzr revid: nicolas.vanhoren@openerp.com-20130621135207-7oq7v2ubzfdrkrbr
Diffstat (limited to 'addons/web/static/src/js/data.js')
-rw-r--r--addons/web/static/src/js/data.js73
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();