From ea79880c3cbd178fc3182bd6658ca1b471fe6251 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 30 Sep 2011 18:15:06 +0200 Subject: [PATCH] [imp] disable buttons in form views during the execution of its action bzr revid: nicolas.vanhoren@openerp.com-20110930161506-bbffc4gjdt43pbvn --- addons/web/static/src/js/view_form.js | 30 +++++++++++++++++++++------ addons/web/static/src/js/views.js | 16 +++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 54960840db5..11ebad8d093 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -862,6 +862,7 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ template: 'WidgetButton', init: function(view, node) { this._super(view, node); + this.force_disabled = false; if (this.string) { // We don't have button key bindings in the webclient this.string = this.string.replace(/_/g, ''); @@ -876,43 +877,60 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ this.$element.find("button").click(this.on_click); }, on_click: function() { + var self = this; + this.force_disabled = true; + this.check_disable(); + this.execute_action().always(function() { + self.force_disabled = false; + self.check_disable(); + }); + }, + execute_action: function() { var self = this; var exec_action = function() { if (self.node.attrs.confirm) { + var def = $.Deferred(); var dialog = $('
' + self.node.attrs.confirm + '
').dialog({ title: 'Confirm', modal: true, buttons: { Ok: function() { - self.on_confirmed(); + self.on_confirmed().then(function() { + def.resolve(); + }); $(self).dialog("close"); }, Cancel: function() { + def.resolve(); $(self).dialog("close"); } } }); + return def.promise(); } else { - self.on_confirmed(); + return self.on_confirmed(); } }; if ((!this.node.attrs.special && this.view.dirty_for_user) || !this.view.datarecord.id) { - this.view.recursive_save().then(exec_action); + return this.view.recursive_save().pipe(exec_action); } else { - exec_action(); + return exec_action(); } }, on_confirmed: function() { var self = this; - this.view.do_execute_action( + return this.view.do_execute_action( this.node.attrs, this.view.dataset, this.view.datarecord.id, function () { self.view.reload(); }); }, update_dom: function() { this._super(); - if (!this.view.is_interactible_record()) { + this.check_disable(); + }, + check_disable: function() { + if (this.force_disabled || !this.view.is_interactible_record()) { this.$element.find("button").attr("disabled", "disabled"); this.$element.find("button").css("color", "grey"); } else { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 42e1a5b8e0d..4a9e57ebd1d 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -86,7 +86,7 @@ db.web.ActionManager = db.web.Widget.extend({ console.log("Action manager can't handle action of type " + action.type, action); return; } - this[type](action, on_close); + return this[type](action, on_close); }, ir_actions_act_window: function (action, on_close) { if (action.target === 'new') { @@ -470,7 +470,7 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View * Intercept do_action resolution from children views */ on_action_executed: function () { - new db.web.DataSet(this, 'res.log') + return new db.web.DataSet(this, 'res.log') .call('get', [], this.do_display_log); }, /** @@ -770,31 +770,31 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{ var self = this; var result_handler = function () { if (on_closed) { on_closed.apply(null, arguments); } - self.widget_parent.on_action_executed.apply(null, arguments); + return self.widget_parent.on_action_executed.apply(null, arguments); }; var handler = function (r) { var action = r.result; if (action && action.constructor == Object) { - self.rpc('/web/session/eval_domain_and_context', { + return self.rpc('/web/session/eval_domain_and_context', { contexts: [dataset.get_context(), action.context || {}, { active_id: record_id || false, active_ids: [record_id || false], active_model: dataset.model }], domains: [] - }, function (results) { + }).pipe(function (results) { action.context = results.context - self.do_action(action, result_handler); + return self.do_action(action, result_handler); }); } else { - result_handler(); + return result_handler(); } }; var context = new db.web.CompoundContext(dataset.get_context(), action_data.context || {}); if (action_data.special) { - handler({result: {"type":"ir.actions.act_window_close"}}); + return handler({result: {"type":"ir.actions.act_window_close"}}); } else if (action_data.type=="object") { return dataset.call_button(action_data.name, [[record_id], context], handler); } else if (action_data.type=="action") {