diff options
| author | Atul Patel (OpenERP) <atp@tinyerp.com> | 2012-10-18 17:13:11 +0530 |
|---|---|---|
| committer | Atul Patel (OpenERP) <atp@tinyerp.com> | 2012-10-18 17:13:11 +0530 |
| commit | 95f03f7c572e7affc6efc85842e79c9829805e53 (patch) | |
| tree | b46a1234568cb8078302b59dc3995b31bb4b7c6d /addons/web/static/src/js/data.js | |
| parent | 25ac221a0f6622a13d01d9b1ad14f4827adb2603 (diff) | |
| parent | 37f95838f26c2b9796bfd45e62fbb1d4df7ac6a6 (diff) | |
[MERGE]: Merged with lp:openerp-web
bzr revid: atp@tinyerp.com-20121012065816-vtbet5rlc8n3wwqo
bzr revid: atp@tinyerp.com-20121015054930-9id6fmbgjj33mr56
bzr revid: atp@tinyerp.com-20121016180101-der2mjymfd1ysgnr
bzr revid: atp@tinyerp.com-20121018114311-j7s62k8m1u3f1g74
Diffstat (limited to 'addons/web/static/src/js/data.js')
| -rw-r--r-- | addons/web/static/src/js/data.js | 102 |
1 files changed, 9 insertions, 93 deletions
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index ce85e0ac43f..77583899bf1 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -280,7 +280,8 @@ instance.web.Model = instance.web.Class.extend({ kwargs = args; args = []; } - return instance.session.rpc('/web/dataset/call_kw', { + var debug = instance.session.debug ? '/'+this.name+':'+method : ''; + return instance.session.rpc('/web/dataset/call_kw' + debug, { model: this.name, method: method, args: args, @@ -349,89 +350,6 @@ instance.web.Model = instance.web.Class.extend({ }, }); -instance.web.DataGroup = instance.web.CallbackEnabled.extend({ - /** - * Management interface between views and grouped collections of OpenERP - * records. - * - * The root DataGroup is instantiated with the relevant information - * (a session, a model, a domain, a context and a group_by sequence), the - * domain and context may be empty. It is then interacted with via - * :js:func:`~instance.web.DataGroup.list`, which is used to read the - * content of the current grouping level. - * - * @constructs instance.web.DataGroup - * @extends instance.web.CallbackEnabled - * - * @param {instance.web.CallbackEnabled} parent widget - * @param {String} model name of the model managed by this DataGroup - * @param {Array} domain search domain for this DataGroup - * @param {Object} context context of the DataGroup's searches - * @param {Array} group_by sequence of fields by which to group - * @param {Number} [level=0] nesting level of the group - */ - init: function(parent, model, domain, context, group_by, level) { - this._super(parent, null); - this.model = new instance.web.Model(model, context, domain); - this.group_by = group_by; - this.context = context; - this.domain = domain; - - this.level = level || 0; - }, - list: function (fields, ifGroups, ifRecords) { - var self = this; - var query = this.model.query(fields).order_by(this.sort).group_by(this.group_by); - $.when(query).then(function (querygroups) { - // leaf node - if (!querygroups) { - var ds = new instance.web.DataSetSearch(self, self.model.name, self.model.context(), self.model.domain()); - ds._sort = self.sort; - ifRecords(ds); - return; - } - // internal node - var child_datagroups = _(querygroups).map(function (group) { - var child_context = _.extend( - {}, self.model.context(), group.model.context()); - var child_dg = new instance.web.DataGroup( - self, self.model.name, group.model.domain(), - child_context, group.model._context.group_by, - self.level + 1); - child_dg.sort = self.sort; - // copy querygroup properties - child_dg.__context = child_context; - child_dg.__domain = group.model.domain(); - child_dg.folded = group.get('folded'); - child_dg.grouped_on = group.get('grouped_on'); - child_dg.length = group.get('length'); - child_dg.value = group.get('value'); - child_dg.openable = group.get('has_children'); - child_dg.aggregates = group.get('aggregates'); - return child_dg; - }); - ifGroups(child_datagroups); - }); - } -}); - -instance.web.StaticDataGroup = instance.web.DataGroup.extend({ - /** - * A specialization of data groups, relying on a single static - * dataset as its records provider. - * - * @constructs instance.web.StaticDataGroup - * @extends instance.web.DataGroup - * @param {openep.web.DataSetStatic} dataset a static dataset backing the groups - */ - init: function (dataset) { - this.dataset = dataset; - }, - list: function (fields, ifGroups, ifRecords) { - ifRecords(this.dataset); - } -}); - instance.web.DataSet = instance.web.CallbackEnabled.extend({ /** * Collection of OpenERP records, used to share records and the current selection between views. @@ -567,7 +485,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)}); + return this._model.call('write', [[id], data], {context: this._model.context(options.context)}).then(this.trigger('dataset_changed', id, data, options)); }, /** * Deletes an existing record from the database @@ -575,8 +493,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @param {Number|String} ids identifier of the record to delete */ unlink: function(ids) { - this.trigger('unlink', ids); - return this._model.call('unlink', [ids], {context: this._model.context()}); + return this._model.call('unlink', [ids], {context: this._model.context()}).then(this.trigger('dataset_changed', ids)); }, /** * Calls an arbitrary RPC method @@ -774,10 +691,11 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({ if (self._length) { self._length -= 1; } - if (this.index !== null) { + if (self.index !== null) { self.index = self.index <= self.ids.length - 1 ? self.index : (self.ids.length > 0 ? self.ids.length -1 : 0); } + self.trigger("dataset_changed", ids, callback, error_callback); }); }, size: function () { @@ -834,7 +752,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ } $.extend(cached.values, record.values); if (dirty) - this.on_change(); + this.trigger("dataset_changed", id, data, options); return $.Deferred().resolve(true).promise(); }, unlink: function(ids, callback, error_callback) { @@ -848,7 +766,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ this.to_write = _.reject(this.to_write, function(x) { return _.include(ids, x.id);}); this.cache = _.reject(this.cache, function(x) { return _.include(ids, x.id);}); this.set_ids(_.without.apply(_, [this.ids].concat(ids))); - this.on_change(); + this.trigger("dataset_changed", ids, callback, error_callback); return $.async_when({result: true}).then(callback); }, reset_ids: function(ids) { @@ -859,8 +777,6 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ this.cache = []; this.delete_all = false; }, - on_change: function() { - }, read_ids: function (ids, fields, options) { var self = this; var to_get = []; @@ -947,7 +863,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({ }, alter_ids: function(n_ids) { this._super(n_ids); - this.on_change(); + this.trigger("dataset_changed", n_ids); }, }); instance.web.BufferedDataSet.virtual_id_regex = /^one2many_v_id_.*$/; |
