From cd3e60aef10a74fd04580b6e5903ee319f160604 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 31 May 2011 13:23:39 +0200 Subject: [PATCH] [ADD] editability status to ListView options (hence all sub-objects of the list view) bzr revid: xmo@openerp.com-20110531112339-701lpf42p8h19mfj --- addons/base/static/src/js/list.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 2fd4aff2e1c..a64cb0c0021 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -14,7 +14,9 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi // sorted it can not be reordered anymore 'sortable': true, // whether the view rows can be reordered (via vertical drag & drop) - 'reorderable': true + 'reorderable': true, + // editability status of list rows + 'editable': null }, /** * Core class for list-type displays. @@ -39,6 +41,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi * @param {null|String} [options.addable="New"] should the new-record button be displayed, and what should its label be. Use ``null`` to hide the button. * @param {Boolean} [options.sortable=true] is it possible to sort the table by clicking on column headers * @param {Boolean} [options.reorderable=true] is it possible to reorder list rows + * @param {null|"bottom"|"top"} [options.editable=null] can rows be edited, and do new rows appear at the top or the bottom of the list * * @borrows openerp.base.ActionExecutor#execute_action as #execute_action */ @@ -270,6 +273,21 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi this.groups.apoptosis().render( $.proxy(this, 'compute_aggregates'))); }, + /** + * Sets editability status for the list, based on defaults, view + * architecture and the provided flag, if any. + * + * @param {Boolean} [force] forces the list to editability. Sets new row edition status to "bottom". + */ + set_editable: function (force) { + // If ``force``, set editability to bottom + // else if editability flag in view arch, use that + // otherwise rely on view default + this.options.editable = ( + (force && "bottom") + || this.fields_view.arch.attrs.editable + || this.defaults.editable); + }, /** * Event handler for a search, asks for the computation/folding of domains * and contexts (and group-by), then reloads the view's content. @@ -296,6 +314,8 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) { results.group_by = null; } + self.set_editable(results.context['set_editable']); + self.reload_view(!!results.group_by).then( $.proxy(self, 'reload_content')); });