[ADD] display groups in a most dreadful manner, need to cleanup the generation function and to handle displaying it in the correct table
bzr revid: xmo@openerp.com-20110510110723-ic13ty3rs92zg9z9
This commit is contained in:
parent
0dcd78a54e
commit
45f47ae65c
|
@ -37,7 +37,19 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
|
||||||
group_by_fields: this.group_by
|
group_by_fields: this.group_by
|
||||||
}, function () { }).then(function (response) {
|
}, function () { }).then(function (response) {
|
||||||
self.groups = response.result;
|
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 () {
|
}, function () {
|
||||||
d.rejectWith.apply(d, self, [arguments]);
|
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
|
* :js:func:`~openerp.base.DataGroup.list` beforehand will likely result
|
||||||
* in an error.
|
* 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 {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} 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 datagroup as parameter and as context
|
* @param {Function} ifDataGroup executed if the item results in a DataSet, provided with the new datagroup as parameter
|
||||||
*/
|
*/
|
||||||
get: function (index, ifDataSet, ifDataGroup) {
|
get: function (index, ifDataSet, ifDataGroup) {
|
||||||
var group = this.groups[index];
|
var group = this.groups[index];
|
||||||
|
|
|
@ -61,7 +61,11 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
columns: this.columns,
|
columns: this.columns,
|
||||||
rows: this.rows
|
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) {
|
'selected': function (e, selection) {
|
||||||
self.$element.find('#oe-list-delete')
|
self.$element.find('#oe-list-delete')
|
||||||
.toggle(!!selection.length);
|
.toggle(!!selection.length);
|
||||||
|
@ -291,16 +295,10 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
self.dataset.context = results.context;
|
self.dataset.context = results.context;
|
||||||
self.dataset.domain = results.domain;
|
self.dataset.domain = results.domain;
|
||||||
if (results.group_by.length) {
|
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);
|
self.session, results.group_by, self.dataset);
|
||||||
group.list().then(function (lst) {
|
self.$element.html(self.groups.render());
|
||||||
console.log(this, lst);
|
return;
|
||||||
this.get(0, function () {
|
|
||||||
console.log('set', this);
|
|
||||||
}, function () {
|
|
||||||
console.log('group', this);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return self.do_reload();
|
return self.do_reload();
|
||||||
});
|
});
|
||||||
|
@ -476,7 +474,55 @@ openerp.base.ListView.List = Class.extend(
|
||||||
// drag and drop
|
// drag and drop
|
||||||
// editable?
|
// 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 = $('<dl>');
|
||||||
|
datagroup.list().then(function (list) {
|
||||||
|
_(list).each(function (group, index) {
|
||||||
|
var $title = $('<dt>')
|
||||||
|
.text(group.grouped_on + ': ' + group.value + ' (' + group.length + ')')
|
||||||
|
.appendTo($root);
|
||||||
|
$title.click(function () {
|
||||||
|
datagroup.get(index, function (new_dataset) {
|
||||||
|
var $content = $('<ul>').appendTo(
|
||||||
|
$('<dd>').insertAfter($title));
|
||||||
|
new_dataset.read_slice([], null, null, function (records) {
|
||||||
|
_(records).each(function (record) {
|
||||||
|
$('<li>')
|
||||||
|
.appendTo($content)
|
||||||
|
.text(_(record).map(function (value, key) {
|
||||||
|
return key + ': ' + value;
|
||||||
|
}).join(', '));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, function (new_datagroup) {
|
||||||
|
console.log(new_datagroup);
|
||||||
|
$('<dd>')
|
||||||
|
.insertAfter($title)
|
||||||
|
.append(self.make_level(new_datagroup));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return $root;
|
||||||
|
},
|
||||||
|
render: function () {
|
||||||
|
return this.make_level(this.datagroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
openerp.base.TreeView = openerp.base.Controller.extend({
|
openerp.base.TreeView = openerp.base.Controller.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue