From dee000be14fd55f7d287eee8569f769505f339ac Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Fri, 9 May 2014 11:48:36 +0200 Subject: [PATCH] [FIX]modal: when closing a modal, focus previous one to allow several escape hit key bzr revid: csn@openerp.com-20140509094836-yhncaqp60od67w7k --- addons/web/static/src/js/chrome.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index fca55957fd7..80851395520 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -46,6 +46,8 @@ instance.web.Notification = instance.web.Widget.extend({ } }); +var opened_modal = []; + instance.web.action_notify = function(element, action) { element.do_notify(action.params.title, action.params.text, action.params.sticky); }; @@ -113,6 +115,8 @@ instance.web.Dialog = instance.web.Widget.extend({ this.init_dialog(); } this.$buttons.insertAfter(this.$dialog_box.find(".modal-body")); + //add to list of currently opened modal + opened_modal.push(this.$dialog_box); return this; }, _add_buttons: function(buttons) { @@ -212,9 +216,13 @@ instance.web.Dialog = instance.web.Widget.extend({ //we need this to put the instruction to remove modal from DOM at the end //of the queue, otherwise it might already have been removed before the modal-backdrop //is removed when pressing escape key - var $parent = this.$el.parents('.modal'); setTimeout(function () { - $parent.remove(); + //remove last modal from list of opened modal since we just destroy it + opened_modal.pop().remove(); + if (opened_modal.length > 0){ + //we still have other opened modal so we should focus it + opened_modal[opened_modal.length-1].focus() + } },0); } this._super();