summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-08-09 09:21:13 +0200
committerDavid Monjoie <dmo@odoo.com>2017-08-10 08:48:32 +0200
commit1e8f6d01ffe324348ce5d75f8643f170f6478657 (patch)
treef833ee666fa709fdae4f3de1824733c6e638f4f4 /addons/web/static/src/js
parent50957038b9ebe5e249da28a9745f957ad02a0760 (diff)
[FIX] web,*: send correct context on button clicked
*account_asset When a button of type 'action' is clicked (execute a given action), special keys must be set in the context (active_id, active_ids and active_model). They must be computed regarding the record containing the clicked button, i.e. if we are in a modal, it must be the id and model of the record displayed in the modal. Before this rev., we always sent the id and model of the record displayed in the background (i.e. the id and model of the url). This caused a bug in MRP that could be reproduced as follows: - open a manufacturing order in form view - click on edit - click on one of the line of the one2many, and click on the green icon to edit a product - click on the update product quantity button on top of it - the product field must be correctly filled, which was not the case before this rev.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/chrome/view_manager.js33
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js12
-rw-r--r--addons/web/static/src/js/views/kanban/kanban_controller.js8
3 files changed, 32 insertions, 21 deletions
diff --git a/addons/web/static/src/js/chrome/view_manager.js b/addons/web/static/src/js/chrome/view_manager.js
index ebd063d7360..25f320670e9 100644
--- a/addons/web/static/src/js/chrome/view_manager.js
+++ b/addons/web/static/src/js/chrome/view_manager.js
@@ -20,7 +20,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
custom_events: {
execute_action: function(event) {
var data = event.data;
- this.do_execute_action(data.action_data, data.model, data.res_ids, data.on_closed)
+ this.do_execute_action(data.action_data, data.env, data.on_closed)
.then(data.on_success, data.on_fail);
},
search: function(event) {
@@ -551,16 +551,19 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
* @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
* @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
* @param {Object} [action_data.context=null] additional action context, to add to the current context
- * @param {DataSet} dataset a dataset object used to communicate with the server
- * @param {integer[]} [res_ids] the res_ids of the objects on which the action is to be applied (fallback on env.ids if not set)
+ * @param {Object} env
+ * @param {string} env.model the model of the record(s) triggering the action
+ * @param {integer[]} [env.resIDs] the current ids in the environment where the action is triggered
+ * @param {integer} [env.currentID] the id of the record triggering the action
+ * @param {Object} [env.context] a context to pass to the action
* @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
*/
- do_execute_action: function (action_data, model, res_ids, on_closed) {
+ do_execute_action: function (action_data, env, on_closed) {
var self = this;
var result_handler = on_closed || function () {};
- var context = new Context(this.env.context, action_data.context || {});
+ var context = new Context(env.context, action_data.context || {});
// OR NULL hereunder: pyeval waits specifically for a null value, different from undefined
- var record_id = res_ids && res_ids[0] || null;
+ var recordID = env.currentID || null;
// response handler
var handler = function (action) {
@@ -574,11 +577,11 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
}))
);
ncontext.add(action_data.context || {});
- ncontext.add({active_model: self.env.modelName});
- if (res_ids) {
+ ncontext.add({active_model: env.model});
+ if (recordID) {
ncontext.add({
- active_id: record_id,
- active_ids: res_ids,
+ active_id: recordID,
+ active_ids: [recordID],
});
}
ncontext.add(action.context || {});
@@ -595,7 +598,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
if (action_data.special === 'cancel') {
return handler({"type":"ir.actions.act_window_close"});
} else if (action_data.type === "object") {
- var args = res_ids ? [res_ids] : [this.env.ids];
+ var args = recordID ? [[recordID]] : [env.resIDs];
if (action_data.args) {
try {
// Warning: quotes and double quotes problem due to json and xml clash
@@ -607,13 +610,13 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
}
}
args.push(context);
- var dataset = new data.DataSet(this, model, this.env.context);
+ var dataset = new data.DataSet(this, env.model, env.context);
return dataset.call_button(action_data.name, args).then(handler);
} else if (action_data.type === "action") {
return data_manager.load_action(action_data.name, _.extend(pyeval.eval('context', context), {
- active_model: this.env.modelName,
- active_ids: this.env.ids,
- active_id: record_id,
+ active_model: env.model,
+ active_ids: env.resIDs,
+ active_id: recordID,
})).then(handler);
}
},
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index 3a47f65ab03..6ba9dbea477 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -232,13 +232,17 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
return self.isDestroyed() ? $.when() : self.reload();
};
record = record || this.model.get(this.handle);
- var recordID = record.data.id;
+
this.trigger_up('execute_action', {
action_data: _.extend({}, attrs, {
- context: record.getContext({additionalContext: attrs.context || {}}),
+ context: record.getContext({additionalContext: attrs.context || {}}),
}),
- model: record.model,
- res_ids: [recordID],
+ env: {
+ context: record.getContext(),
+ currentID: record.data.id,
+ model: record.model,
+ resIDs: record.res_ids,
+ },
on_closed: function (reason) {
if (!_.isObject(reason)) {
reload(reason);
diff --git a/addons/web/static/src/js/views/kanban/kanban_controller.js b/addons/web/static/src/js/views/kanban/kanban_controller.js
index 2cf6a94285e..6870dbbbe24 100644
--- a/addons/web/static/src/js/views/kanban/kanban_controller.js
+++ b/addons/web/static/src/js/views/kanban/kanban_controller.js
@@ -237,8 +237,12 @@ var KanbanController = BasicController.extend({
}
this.trigger_up('execute_action', {
action_data: attrs,
- model: record.model,
- res_ids: [record.res_id],
+ env: {
+ context: record.getContext(),
+ currentID: record.res_id,
+ model: record.model,
+ resIDs: record.res_ids,
+ },
on_closed: function () {
self.model.reload(record.id).then(function (db_id) {
var data = self.model.get(db_id);