From 242d2378686fa528b3934571e7ae7e82bba2afc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 20 Feb 2014 23:36:38 +0100 Subject: [PATCH] Fix action button sensibility Allow to run action if no record is selected. issue3685 review3611004 --- src/action.js | 2 +- src/screen.js | 9 ++++++--- src/tab.js | 31 ++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/action.js b/src/action.js index e69852d916..66880642d0 100644 --- a/src/action.js +++ b/src/action.js @@ -37,7 +37,7 @@ } var ctx = { active_model: data.res_model, - active_id: data.id || false, + active_id: data.id || null, active_ids: data.ids }; var session = Sao.Session.current_session; diff --git a/src/screen.js b/src/screen.js index 051eeffba7..b2f02ed854 100644 --- a/src/screen.js +++ b/src/screen.js @@ -446,9 +446,8 @@ if ((this.current_view.view_type == 'tree') && (!jQuery.isEmptyObject(this.group))) { this.set_current_record(this.group[0]); - } else { - return true; } + return jQuery.when(); } this.current_view.set_value(); var fields = this.current_view.get_fields(); @@ -689,8 +688,12 @@ this.display(); }, get_buttons: function() { + var selected_records = this.current_view.selected_records(); + if (jQuery.isEmptyObject(selected_records)) { + return []; + } var buttons = this.current_view.get_buttons(); - this.current_view.selected_records().forEach(function(record) { + selected_records.forEach(function(record) { buttons = buttons.filter(function(button) { var states = record.expr_eval( button.attributes.states || {}); diff --git a/src/tab.js b/src/tab.js index 867a127487..c14afb15e8 100644 --- a/src/tab.js +++ b/src/tab.js @@ -307,17 +307,26 @@ jQuery('').append(action.name)); menu.append(item); item.click(function() { - var exec_action = jQuery.extend({}, action); - // TODO test save - exec_action = Sao.Action.evaluate(exec_action, - menu_action[0], screen.current_record); - var data = { - model: screen.model_name, - id: screen.get_id(), - ids: [screen.get_id()] // TODO ids selected - }; - Sao.Action.exec_action(exec_action, data, - screen.context); + screen.save_current().then(function() { + var exec_action = jQuery.extend({}, action); + var record_id = null; + if (screen.current_record) { + record_id = screen.current_record.id; + } + var record_ids = screen.current_view + .selected_records().map(function(record) { + return record.id; + }); + exec_action = Sao.Action.evaluate(exec_action, + menu_action[0], screen.current_record); + var data = { + model: screen.model_name, + id: record_id, + ids: record_ids + }; + Sao.Action.exec_action(exec_action, data, + screen.context); + }); }); }); menu.menu({}).hide().css({