diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index bb190e068c6..c3683ed592e 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -37,7 +37,19 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas group_by_fields: this.group_by }, function () { }).then(function (response) { self.groups = response.result; - d.resolveWith(self, [response.result]); + // read_group results are annoying: they use the name of the + // field grouped on to hold the value and the count, so no + // generic access to those values is possible. + // Alias them to `value` and `length`. + d.resolveWith(self, [_(response.result).map(function (group) { + var field_name = self.group_by[0]; + return _.extend({}, group, { + // provide field used for grouping + grouped_on: field_name, + length: group[field_name + '_count'], + value: group[field_name] + }); + })]); }, function () { d.rejectWith.apply(d, self, [arguments]); }); @@ -52,9 +64,14 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas * :js:func:`~openerp.base.DataGroup.list` beforehand will likely result * in an error. * + * The resulting :js:class:`~openerp.base.DataGroup` or + * :js:class:`~openerp.base.DataSet` will be provided through the relevant + * callback function. In both functions, the current DataGroup will be + * provided as context (``this``) + * * @param {Number} index the index of the group to open in the datagroup's collection - * @param {Function} ifDataSet executed if the item results in a DataSet, provided with the dataset as parameter and as context - * @param {Function} ifDataGroup executed if the item results in a DataSet, provided with the datagroup as parameter and as context + * @param {Function} ifDataSet executed if the item results in a DataSet, provided with the new dataset as parameter + * @param {Function} ifDataGroup executed if the item results in a DataSet, provided with the new datagroup as parameter */ get: function (index, ifDataSet, ifDataGroup) { var group = this.groups[index]; diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index f4a2e481418..87a59f0a469 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -61,7 +61,11 @@ openerp.base.ListView = openerp.base.Controller.extend( columns: this.columns, rows: this.rows }); - $(this.list).bind({ + this.groups = new openerp.base.ListView.Groups({ + options: this.options, + columns: this.columns + }); + $([this.list, this.groups]).bind({ 'selected': function (e, selection) { self.$element.find('#oe-list-delete') .toggle(!!selection.length); @@ -291,16 +295,10 @@ openerp.base.ListView = openerp.base.Controller.extend( self.dataset.context = results.context; self.dataset.domain = results.domain; if (results.group_by.length) { - var group = new openerp.base.DataGroup( + self.groups.datagroup = new openerp.base.DataGroup( self.session, results.group_by, self.dataset); - group.list().then(function (lst) { - console.log(this, lst); - this.get(0, function () { - console.log('set', this); - }, function () { - console.log('group', this); - }); - }); + self.$element.html(self.groups.render()); + return; } return self.do_reload(); }); @@ -476,7 +474,55 @@ openerp.base.ListView.List = Class.extend( // drag and drop // editable? }); - +openerp.base.ListView.Groups = Class.extend( + /** @lends openerp.base.ListView.Groups# */{ + /** + * Grouped display for the ListView. Handles basic DOM events and interacts + * with the :js:class:`~openerp.base.DataGroup` bound to it. + * + * Provides events similar to those of + * :js:class:`~openerp.base.ListView.List` + */ + init: function (opts) { + this.options = opts.options; + this.columns = opts.columns; + this.datagroup = {}; + }, + make_level: function (datagroup) { + var self = this, $root = $('