diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 89bc2f013ae..cb9409327f2 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -50,7 +50,15 @@ openerp.base.ListView = openerp.base.Controller.extend( return _.extend({id: name, tag: field.tag}, field.attrs, fields[name]); }).value(); + this.visible_columns = _.filter(this.columns, function (column) { + return column.invisible !== '1'; + }); this.$element.html(QWeb.render("ListView", this)); + + // Head hook + this.$element.find('#oe-list-delete').click(this.do_delete_selected); + + // Cell events this.$element.find('table').delegate( 'th.oe-record-selector', 'click', function (e) { // A click in the selection cell should not activate the @@ -59,6 +67,8 @@ openerp.base.ListView = openerp.base.Controller.extend( }); this.$element.find('table').delegate( 'td.oe-record-delete button', 'click', this.do_delete); + + // Global rows handlers this.$element.find('table').delegate( 'tr', 'click', this.on_select_row); @@ -163,6 +173,15 @@ openerp.base.ListView = openerp.base.Controller.extend( this.dataset.unlink( [this.rows[$(e.currentTarget).closest('tr').prevAll().length].id]); }, + /** + * Handles deletion of all selected lines + */ + do_delete_selected: function () { + var selection = this.get_selection(); + if (selection.length) { + this.dataset.unlink(selection); + } + }, /** * Gets the ids of all currently selected records, if any * @returns a list of ids, empty if no record is selected (or the list view is not selectable diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml index c3682051e54..4fb208c6088 100644 --- a/addons/base/static/src/xml/base.xml +++ b/addons/base/static/src/xml/base.xml @@ -171,6 +171,13 @@ + + + + + @@ -180,6 +187,7 @@ + diff --git a/addons/base/static/test/list.js b/addons/base/static/test/list.js index 9e675125004..4a5bb3795fe 100644 --- a/addons/base/static/test/list.js +++ b/addons/base/static/test/list.js @@ -103,4 +103,24 @@ $(document).ready(function () { start(); }); }); + asyncTest('multiple records deletion', 1, function () { + var deleted; + var listview = new openerp.base.ListView( + {}, null, 'qunit-fixture', {model: null, unlink: function (ids) { + deleted = ids; + }}); + + listview.on_loaded(fvg); + + listview.do_fill_table([{id: 1}, {id: 2}, {id: 3}]).then(function () { + listview.$element.find('tbody th input:eq(2)') + .attr('checked', true); + listview.$element.find('tbody th input:eq(1)') + .attr('checked', true); + + listview.$element.find('#oe-list-delete').click(); + deepEqual(deleted, [2, 3]); + start(); + }); + }); });