[ADD] method to get the selection (list of identifiers) from a list view
bzr revid: xmo@openerp.com-20110407124639-tua9qkcl4w8mhtdc
This commit is contained in:
parent
acaf85e762
commit
02636b4622
|
@ -143,6 +143,20 @@ openerp.base.ListView = openerp.base.Controller.extend(
|
||||||
do_update: function () {
|
do_update: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.dataset.fetch(self.dataset.fields, 0, self.limit, self.do_fill_table);
|
self.dataset.fetch(self.dataset.fields, 0, self.limit, self.do_fill_table);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
get_selection: function () {
|
||||||
|
if (!this.options.selectable) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
var rows = this.rows;
|
||||||
|
return this.$element.find('th.oe-record-selector input:checked')
|
||||||
|
.closest('tr').map(function () {
|
||||||
|
return rows[$(this).prevAll().length].id;
|
||||||
|
}).get();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
asyncTest('render no checkbox if selectable=false', 1, function () {
|
asyncTest('render no checkbox if selectable=false', 1, function () {
|
||||||
|
|
||||||
var listview = new openerp.base.ListView(
|
var listview = new openerp.base.ListView(
|
||||||
{}, null,
|
{}, null,
|
||||||
'qunit-fixture', {model: null}, false,
|
'qunit-fixture', {model: null}, false,
|
||||||
|
@ -58,4 +57,19 @@ $(document).ready(function () {
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
asyncTest('select a bunch of records', 2, function () {
|
||||||
|
var listview = new openerp.base.ListView(
|
||||||
|
{}, null, 'qunit-fixture', {model: null});
|
||||||
|
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);
|
||||||
|
deepEqual(listview.get_selection(), [3]);
|
||||||
|
listview.$element.find('tbody th input:eq(1)')
|
||||||
|
.attr('checked', true);
|
||||||
|
deepEqual(listview.get_selection(), [2, 3]);
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue