summaryrefslogtreecommitdiff
path: root/addons/base/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-05-25 11:28:13 +0200
committerXavier Morel <xmo@openerp.com>2011-05-25 11:28:13 +0200
commit3dbc88c6960dbfb16577d7ac8a4180f9a5f2d95b (patch)
treef21aae8e098fe42ba30a57bc7e9d68278d64135c /addons/base/static/src
parent069da6ed5e5702196c271f396b6f09dc94836884 (diff)
[IMP] make get_selection call and selected ListView event provide both ids of selected records and the selected records themselves
bzr revid: xmo@openerp.com-20110525092813-ciahklygwshkpdl0
Diffstat (limited to 'addons/base/static/src')
-rw-r--r--addons/base/static/src/js/list.js59
1 files changed, 41 insertions, 18 deletions
diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js
index 1a03b7d4526..7d7c53e18b6 100644
--- a/addons/base/static/src/js/list.js
+++ b/addons/base/static/src/js/list.js
@@ -61,9 +61,8 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
columns: this.columns
});
$(this.groups).bind({
- 'selected': function (e, selection) {
- self.$element.find('#oe-list-delete')
- .toggle(!!selection.length);
+ 'selected': function (e, ids, records) {
+ self.do_select(ids, records);
},
'deleted': function (e, ids) {
self.do_delete(ids);
@@ -331,6 +330,16 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
});
},
/**
+ * Handles the signal indicating that a new record has been selected
+ *
+ * @param {Array} ids selected record ids
+ * @param {Array} records selected record values
+ */
+ do_select: function (ids, records) {
+ this.$element.find('#oe-list-delete')
+ .toggle(!!ids.length);
+ },
+ /**
* Handles signal for the addition of a new record (can be a creation,
* can be the addition from a remote source, ...)
*
@@ -344,7 +353,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
* Handles deletion of all selected lines
*/
do_delete_selected: function () {
- this.do_delete(this.groups.get_selection());
+ this.do_delete(this.groups.get_selection().ids);
}
// TODO: implement reorder (drag and drop rows)
});
@@ -389,7 +398,8 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
.appendTo(document.body)
.delegate('th.oe-record-selector', 'click', function (e) {
e.stopPropagation();
- $(self).trigger('selected', [self.get_selection()]);
+ var selection = self.get_selection();
+ $(self).trigger('selected', [selection.ids, selection.records]);
})
.delegate('td.oe-record-delete button', 'click', function (e) {
e.stopPropagation();
@@ -422,17 +432,24 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
},
/**
* Gets the ids of all currently selected records, if any
- * @returns {Array} empty if no record is selected (or the list view is not selectable)
+ * @returns {Object} object with the keys ``ids`` and ``records``, holding respectively the ids of all selected records and the records themselves.
*/
get_selection: function () {
if (!this.options.selectable) {
return [];
}
var rows = this.rows;
- return this.$current.find('th.oe-record-selector input:checked')
- .closest('tr').map(function () {
- return rows[$(this).prevAll().length].data.id.value;
- }).get();
+ var result = {ids: [], records: []};
+ this.$current.find('th.oe-record-selector input:checked')
+ .closest('tr').each(function () {
+ var record = {};
+ _(rows[$(this).prevAll().length].data).each(function (obj, key) {
+ record[key] = obj.value;
+ });
+ result.ids.push(record.id);
+ result.records.push(record);
+ });
+ return result;
},
/**
* Returns the index of the row in the list of rows.
@@ -615,7 +632,8 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
self = this;
$(child).bind('selected', function (e) {
// can have selections spanning multiple links
- $this.trigger(e, [self.get_selection()]);
+ var selection = self.get_selection();
+ $this.trigger(e, [selection.ids, selection.records]);
}).bind('action', function (e, name, id, callback) {
if (!callback) {
callback = function () {
@@ -683,15 +701,20 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr
return $element;
},
/**
- * Returns the ids of all selected records for this group
+ * Returns the ids of all selected records for this group, and the records
+ * themselves
*/
get_selection: function () {
- return _(this.children).chain()
- .map(function (child) {
- return child.get_selection();
- })
- .flatten()
- .value();
+ var ids = [], records = [];
+
+ _(this.children)
+ .each(function (child) {
+ var selection = child.get_selection();
+ ids.push.apply(ids, selection.ids);
+ records.push.apply(records, selection.records);
+ });
+
+ return {ids: ids, records: records};
},
apoptosis: function () {
_(this.children).each(function (child) {