[MOVE] datagroup to a private ListView API
bzr revid: xmo@openerp.com-20121017105213-sfosutg26zg0w2ax
This commit is contained in:
parent
8d3fd60178
commit
71bbb149fb
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue