From 71bbb149fb027b2173daddd3ae1e57e678c8d59e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 17 Oct 2012 12:52:13 +0200 Subject: [PATCH] [MOVE] datagroup to a private ListView API bzr revid: xmo@openerp.com-20121017105213-sfosutg26zg0w2ax --- addons/web/doc/async.rst | 4 +- addons/web/doc/changelog-7.0.rst | 9 ++- addons/web/doc/rpc.rst | 4 +- addons/web/static/src/js/data.js | 83 --------------------------- addons/web/static/src/js/view_list.js | 62 ++++++++++++++++++-- 5 files changed, 69 insertions(+), 93 deletions(-) diff --git a/addons/web/doc/async.rst b/addons/web/doc/async.rst index 23b3409bd8f..bd23d5a31d3 100644 --- a/addons/web/doc/async.rst +++ b/addons/web/doc/async.rst @@ -1,5 +1,5 @@ -Don't stop the world now: asynchronous development and Javascript -================================================================= +Asynchronous Operations +======================= As a language (and runtime), javascript is fundamentally single-threaded. This means any blocking request or computation will diff --git a/addons/web/doc/changelog-7.0.rst b/addons/web/doc/changelog-7.0.rst index dd08f1bcde7..b801c11b945 100644 --- a/addons/web/doc/changelog-7.0.rst +++ b/addons/web/doc/changelog-7.0.rst @@ -95,8 +95,8 @@ DataGroup -> also Model ----------------------- Alongside the deprecation of ``DataSet`` for -:js:class:`~openerp.web.Model`, OpenERP Web 7.0 also deprecates -``DataGroup`` and its subtypes in favor of a single method on +:js:class:`~openerp.web.Model`, OpenERP Web 7.0 removes +``DataGroup`` and its subtypes as public objects in favor of a single method on :js:class:`~openerp.web.Query`: :js:func:`~openerp.web.Query.group_by`. @@ -116,3 +116,8 @@ Because it is heavily related to ``DataSet`` (as it *yields* ``DataGroup`` (if we want to stay consistent), which is a good time to make the API more imperative and look more like what most developers are used to. + +But as ``DataGroup`` users in 6.1 were rare (and there really was little reason +to use it), it has been removed as a public API. + + diff --git a/addons/web/doc/rpc.rst b/addons/web/doc/rpc.rst index 4787978e187..db6fcb4fa4b 100644 --- a/addons/web/doc/rpc.rst +++ b/addons/web/doc/rpc.rst @@ -1,5 +1,5 @@ -Outside the box: network interactions -===================================== +RPC Calls +========= Building static displays is all nice and good and allows for neat effects (and sometimes you're given data to display from third parties diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 76c2eb41ec1..77583899bf1 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -350,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. diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index d1b8f0ae7c2..e3a95c11c2d 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -64,9 +64,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi this.set_groups(new (this.options.GroupsType)(this)); if (this.dataset instanceof instance.web.DataSetStatic) { - this.groups.datagroup = new instance.web.StaticDataGroup(this.dataset); + this.groups.datagroup = new StaticDataGroup(this.dataset); } else { - this.groups.datagroup = new instance.web.DataGroup( + this.groups.datagroup = new DataGroup( this, this.model, dataset.get_domain(), dataset.get_context()); @@ -554,7 +554,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi */ do_search: function (domain, context, group_by) { this.page = 0; - this.groups.datagroup = new instance.web.DataGroup( + this.groups.datagroup = new DataGroup( this, this.model, domain, context, group_by); this.groups.datagroup.sort = this.dataset._sort; @@ -1150,7 +1150,7 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we passtrough_events: 'action deleted row_link', /** * Grouped display for the ListView. Handles basic DOM events and interacts - * with the :js:class:`~instance.web.DataGroup` bound to it. + * with the :js:class:`~DataGroup` bound to it. * * Provides events similar to those of * :js:class:`~instance.web.ListView.List` @@ -1555,6 +1555,60 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we } }); +var DataGroup = instance.web.Class.extend({ + 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); + }); + } +}); +var StaticDataGroup = DataGroup.extend({ + init: function (dataset) { + this.dataset = dataset; + }, + list: function (fields, ifGroups, ifRecords) { + ifRecords(this.dataset); + } +}); + /** * @mixin Events */