[ADD] switch to adding special group and count columns, correctly indent inner groups in tree-like structure
bzr revid: xmo@openerp.com-20110524065205-rxulby7dn9gk7qzj
This commit is contained in:
parent
96c7c16b5f
commit
7321970cf9
|
@ -22,15 +22,16 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
|
|||
* @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(session, model, domain, context, group_by) {
|
||||
init: function(session, model, domain, context, group_by, level) {
|
||||
if (group_by) {
|
||||
if (group_by.length) {
|
||||
return new openerp.base.ContainerDataGroup(
|
||||
session, model, domain, context, group_by);
|
||||
session, model, domain, context, group_by, level);
|
||||
} else {
|
||||
return new openerp.base.GrouplessDataGroup(
|
||||
session, model, domain, context);
|
||||
session, model, domain, context, level);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +39,10 @@ openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.bas
|
|||
this.model = model;
|
||||
this.context = context;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
this.level = level || 0;
|
||||
},
|
||||
cls: 'DataGroup'
|
||||
});
|
||||
openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
|
||||
/** @lends openerp.base.ContainerDataGroup# */ {
|
||||
|
@ -52,9 +56,10 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
|
|||
* @param domain
|
||||
* @param context
|
||||
* @param group_by
|
||||
* @param level
|
||||
*/
|
||||
init: function (session, model, domain, context, group_by) {
|
||||
this._super(session, model, domain, context);
|
||||
init: function (session, model, domain, context, group_by, level) {
|
||||
this._super(session, model, domain, context, null, level);
|
||||
|
||||
this.group_by = group_by;
|
||||
},
|
||||
|
@ -159,7 +164,8 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend(
|
|||
return _.extend(
|
||||
new openerp.base.DataGroup(
|
||||
self.session, self.model, group.__domain,
|
||||
child_context, child_context.group_by),
|
||||
child_context, child_context.group_by,
|
||||
self.level + 1),
|
||||
group);
|
||||
}));
|
||||
});
|
||||
|
@ -176,9 +182,10 @@ openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend(
|
|||
* @param model
|
||||
* @param domain
|
||||
* @param context
|
||||
* @param level
|
||||
*/
|
||||
init: function (session, model, domain, context) {
|
||||
this._super(session, model, domain, context);
|
||||
init: function (session, model, domain, context, level) {
|
||||
this._super(session, model, domain, context, null, level);
|
||||
},
|
||||
list: function (ifGroups, ifRecords) {
|
||||
ifRecords(_.extend(
|
||||
|
@ -400,7 +407,7 @@ openerp.base.DataSetMany2Many = openerp.base.DataSetStatic.extend({
|
|||
|
||||
unlink: function(ids) {
|
||||
// just do nothing
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -196,14 +196,15 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
|||
this.columns.push.apply(
|
||||
this.columns,
|
||||
_(this.fields_view.arch.children).map(field_to_column));
|
||||
|
||||
_(groupby_columns).each(function (column_id, index) {
|
||||
var column_index = _(self.columns).chain()
|
||||
.pluck('id').indexOf(column_id).value();
|
||||
var column = self.columns.splice(column_index, 1)[0];
|
||||
delete column.invisible;
|
||||
self.columns.splice(index, 0, column);
|
||||
});
|
||||
if (groupby_columns && groupby_columns.length) {
|
||||
this.columns.unshift({
|
||||
id: '_group', tag: '', string: "Group", meta: true,
|
||||
attrs_for: function () { return {}; }
|
||||
}, {
|
||||
id: '_count', tag: '', string: '#', meta: true,
|
||||
attrs_for: function () { return {}; }
|
||||
});
|
||||
}
|
||||
|
||||
this.visible_columns = _.filter(this.columns, function (column) {
|
||||
return column.invisible !== '1';
|
||||
|
@ -535,6 +536,20 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
|
|||
.removeClass('ui-icon-triangle-1-e')
|
||||
.addClass('ui-icon-triangle-1-s');
|
||||
},
|
||||
/**
|
||||
* Prefixes ``$node`` with floated spaces in order to indent it relative
|
||||
* to its own left margin/baseline
|
||||
*
|
||||
* @param {jQuery} $node jQuery object to indent
|
||||
* @param {Number} level current nesting level, >= 1
|
||||
* @returns {jQuery} the indentation node created
|
||||
*/
|
||||
indent: function ($node, level) {
|
||||
return $('<span>')
|
||||
.css({'float': 'left', 'white-space': 'pre'})
|
||||
.text(new Array(level).join(' '))
|
||||
.prependTo($node);
|
||||
},
|
||||
render_groups: function (datagroups) {
|
||||
var self = this;
|
||||
var placeholder = this.make_fragment();
|
||||
|
@ -557,13 +572,13 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
|
|||
_(self.columns).chain()
|
||||
.filter(function (column) {return !column.invisible;})
|
||||
.each(function (column) {
|
||||
if (column.id === group.grouped_on) {
|
||||
$('<th>')
|
||||
.text(_.sprintf("%s (%d)",
|
||||
group.value instanceof Array ? group.value[1] : group.value,
|
||||
group.length))
|
||||
if (column.id === '_group') {
|
||||
self.indent($('<th>')
|
||||
.text((group.value instanceof Array ? group.value[1] : group.value))
|
||||
.prepend('<span class="ui-icon ui-icon-triangle-1-e">')
|
||||
.appendTo($row);
|
||||
.appendTo($row), group.level);
|
||||
} else if (column.id === '_count') {
|
||||
$('<td>').text(group.length).appendTo($row);
|
||||
} else if (column.id in group.aggregates) {
|
||||
var value = group.aggregates[column.id];
|
||||
var format;
|
||||
|
|
|
@ -210,12 +210,12 @@
|
|||
<t t-if="!attrs.invisible">
|
||||
<t t-set="is_button" t-value="column.tag === 'button'"/>
|
||||
<!-- TODO: get correct widget from form -->
|
||||
<t t-if="!is_button and row['data'][column.id].value !== false">
|
||||
<t t-if="!is_button and !column.meta and row['data'][column.id].value !== false">
|
||||
<t t-set="value" t-value="row['data'][column.id].value"/>
|
||||
<t t-esc="value instanceof Array ? value[1] : value"/>
|
||||
</t>
|
||||
<button type="button" t-att-title="column.help"
|
||||
t-if="is_button">
|
||||
t-if="is_button and !column.meta">
|
||||
<img t-att-src="'/base/static/src/img/icons/' + column.icon + '.png'"
|
||||
t-att-alt="column.string"/>
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue