[FIX] group titles should display 'Undefined' for false values, rather than 'false'

bzr revid: xmo@openerp.com-20110712141934-qk3zfckzh32b8xu1
This commit is contained in:
Xavier Morel 2011-07-12 16:19:34 +02:00
parent ab755d5000
commit 17d87a9599
2 changed files with 61 additions and 46 deletions

View File

@ -247,7 +247,12 @@ openerp.base.list.editable = function (openerp) {
this.render_row_as_form();
}
});
openerp.base.list = {form: {}};
if (!openerp.base.list) {
openerp.base.list = {};
}
if (!openerp.base.list.form) {
openerp.base.list.form = {};
}
openerp.base.list.form.WidgetFrame = openerp.base.form.WidgetFrame.extend({
template: 'ListView.row.frame'
});

View File

@ -1,5 +1,50 @@
openerp.base.list = function (openerp) {
openerp.base.views.add('list', 'openerp.base.ListView');
openerp.base.list = {
/**
* Formats the rendring of a given value based on its field type
*
* @param {Object} row_data record whose values should be displayed in the cell
* @param {Object} column column descriptor
* @param {"button"|"field"} column.tag base control type
* @param {String} column.type widget type for a field control
* @param {String} [column.string] button label
* @param {String} [column.icon] button icon
* @param {String} [value_if_empty=''] what to display if the field's value is ``false``
*/
render_cell: function (row_data, column, value_if_empty) {
var attrs = column.modifiers_for(row_data);
if (attrs.invisible) { return ''; }
if (column.tag === 'button') {
return [
'<button type="button" title="', column.string || '', '">',
'<img src="/base/static/src/img/icons/', column.icon, '.png"',
' alt="', column.string || '', '"/>',
'</button>'
].join('')
}
var record = row_data[column.id];
if (record.value === false) {
return value_if_empty === undefined ? '' : value_if_empty;
}
switch (column.widget || column.type) {
case 'many2one':
// name_get value format
return record.value[1];
case 'float_time':
return _.sprintf("%02d:%02d",
Math.floor(record.value),
Math.round((record.value % 1) * 60));
case 'progressbar':
return _.sprintf(
'<progress value="%.2f" max="100.0">%.2f%%</progress>',
record.value, record.value);
default:
return record.value;
}
}
};
openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListView# */ {
defaults: {
// records can be selected one by one
@ -634,7 +679,7 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
this.$current = this.$_element.clone(true);
this.$current.empty().append(
QWeb.render('ListView.rows', _.extend({
render_cell: this.render_cell}, this)));
render_cell: openerp.base.list.render_cell}, this)));
},
/**
* Gets the ids of all currently selected records, if any
@ -765,49 +810,9 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
row: this.rows[record_index],
row_parity: (record_index % 2 === 0) ? 'even' : 'odd',
row_index: record_index,
render_cell: this.render_cell
render_cell: openerp.base.list.render_cell
});
},
/**
* Formats the rendring of a given value based on its field type
*
* @param {Object} row_data record whose values should be displayed in the cell
* @param {Object} column column descriptor
* @param {"button"|"field"} column.tag base control type
* @param {String} column.type widget type for a field control
* @param {String} [column.string] button label
* @param {String} [column.icon] button icon
*/
render_cell: function (row_data, column) {
var attrs = column.modifiers_for(row_data);
if (attrs.invisible) { return ''; }
if (column.tag === 'button') {
return [
'<button type="button" title="', column.string || '', '">',
'<img src="/base/static/src/img/icons/', column.icon, '.png"',
' alt="', column.string || '', '"/>',
'</button>'
].join('')
}
var record = row_data[column.id];
if (record.value === false) { return ''; }
switch (column.widget || column.type) {
case 'many2one':
// name_get value format
return record.value[1];
case 'float_time':
return _.sprintf("%02d:%02d",
Math.floor(record.value),
Math.round((record.value % 1) * 60));
case 'progressbar':
return _.sprintf(
'<progress value="%.2f" max="100.0">%.2f%%</progress>',
record.value, record.value);
default:
return record.value;
}
},
/**
* Stops displaying the records matching the provided ids.
*
@ -959,10 +964,15 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
placeholder.appendChild($row[0]);
var $group_column = $('<th class="oe-group-name">').appendTo($row);
// Don't fill this if group_by_no_leaf but no group_by
if (group.grouped_on) {
// Don't fill this if group_by_no_leaf but no group_by
$group_column
.text((group.value instanceof Array ? group.value[1] : group.value));
var row_data = {};
row_data[group.grouped_on] = group;
var group_column = _(self.columns).detect(function (column) {
return column.id === group.grouped_on; });
$group_column.text(openerp.base.list.render_cell(
row_data, group_column, "Undefined"
));
if (group.openable) {
// Make openable if not terminal group & group_by_no_leaf
$group_column