From f86bc1c6a398d5ff5da9e517b92bb8cffeb5225d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 27 May 2011 09:44:42 +0200 Subject: [PATCH] [IMP] extract handlers for ListView.Groups events into separate method, so they're not a pain to override bzr revid: xmo@openerp.com-20110527074442-2wjw9aya7m8t0tlp --- addons/base/static/src/js/list.js | 55 +++++++++++++++++++++--------- addons/base/static/src/js/views.js | 2 +- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index c20e5637693..05fc586a14d 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -78,25 +78,10 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi self.do_delete(ids); }, 'action': function (e, action_name, id, callback) { - var action = _.detect(self.columns, function (field) { - return field.name === action_name; - }); - if (!action) { return; } - self.execute_action( - action, self.dataset, self.session.action_manager, - id, function () { - if (callback) { - callback(); - } - }); + self.do_action(action_name, id, callback); }, 'row_link': function (e, index, id, dataset) { - _.extend(self.dataset, { - domain: dataset.domain, - context: dataset.context - }).read_slice([], null, null, function () { - self.select_record(index); - }); + self.do_activate_record(index, id, dataset); } }); }, @@ -358,6 +343,42 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi } this.compute_aggregates(records); }, + /** + * Handles action button signals on a record + * + * @param {String} name action name + * @param {Object} id id of the record the action should be called on + * @param {Function} callback should be called after the action is executed, if non-null + */ + do_action: function (name, id, callback) { + var action = _.detect(this.columns, function (field) { + return field.name === name; + }); + if (!action) { return; } + this.execute_action( + action, this.dataset, this.session.action_manager, + id, function () { + if (callback) { + callback(); + } + }); + }, + /** + * Handles the activation of a record (clicking on it) + * + * @param {Number} index index of the record in the dataset + * @param {Object} id identifier of the activated record + * @param {openobject.base.DataSet} dataset dataset in which the record is available (may not be the listview's dataset in case of nested groups) + */ + do_activate_record: function (index, id, dataset) { + var self = this; + _.extend(this.dataset, { + domain: dataset.domain, + context: dataset.context + }).read_slice([], 0, false, function () { + self.select_record(index); + }); + }, /** * Handles signal for the addition of a new record (can be a creation, * can be the addition from a remote source, ...) diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index bb52009ae40..d4ab23af0d0 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -356,7 +356,7 @@ openerp.base.View = openerp.base.Controller.extend({ * @param {Object} [action_data.context=null] additional action context, to add to the current context * @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server * @param {openerp.base.ActionManager} action_manager object able to actually execute the action, if any is fetched - * @param {Number} [record_id] the identifier of the object on which the action is to be applied + * @param {Object} [record_id] the identifier of the object on which the action is to be applied * @param {Function} on_no_action callback to execute if the action does not generate any result (no new action) */ execute_action: function (action_data, dataset, action_manager, record_id, on_no_action) {