[ADD] multiple records deletion
bzr revid: xmo@openerp.com-20110407153527-6r8cb7oym1fp5r6x
This commit is contained in:
parent
e8a6a4e1e2
commit
0fe1fdb06a
|
@ -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
|
||||
|
|
|
@ -171,6 +171,13 @@
|
|||
</t>
|
||||
<t t-name="ListView.header">
|
||||
<thead t-if="options.header">
|
||||
<tr t-if="options.selectable and options.deletable">
|
||||
<th t-att-colspan="visible_columns.length + 2">
|
||||
<button type="button" id="oe-list-delete">
|
||||
Delete Selected
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th t-if="options.selectable"/>
|
||||
<t t-foreach="columns" t-as="column">
|
||||
|
@ -180,6 +187,7 @@
|
|||
</t>
|
||||
</th>
|
||||
</t>
|
||||
<th t-if="options.deletable"/>
|
||||
</tr>
|
||||
</thead>
|
||||
</t>
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue