From 17d87a95992e7fd006ca996a2d8bebf4217534d9 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 12 Jul 2011 16:19:34 +0200 Subject: [PATCH] [FIX] group titles should display 'Undefined' for false values, rather than 'false' bzr revid: xmo@openerp.com-20110712141934-qk3zfckzh32b8xu1 --- addons/base/static/src/js/list-editable.js | 7 +- addons/base/static/src/js/list.js | 100 +++++++++++---------- 2 files changed, 61 insertions(+), 46 deletions(-) diff --git a/addons/base/static/src/js/list-editable.js b/addons/base/static/src/js/list-editable.js index a460dfcff41..4aa06cc8152 100644 --- a/addons/base/static/src/js/list-editable.js +++ b/addons/base/static/src/js/list-editable.js @@ -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' }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 7922f690784..bfa429fd454 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -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 [ + '' + ].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( + '%.2f%%', + 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 [ - '' - ].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( - '%.2f%%', - 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 = $('').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