Fixes issue when:
1. 2 dialogs are opened
2. top dialog's close button is focused
3. user presses enter to execute 'close' action
4. dialog is immediately closed (enter key is still pressed)
5. second dialog automatically receives focus (it's top dialog now)
6. user releases the key
7. second dialog reacts to keyup event - which is by default confirmation mixin's confirm event
8. UNDESIRED behavior occurs

Now confirmation mixin remembers which keys were pressed and released and reacts only to those which originated there.

https://fedorahosted.org/freeipa/ticket/4098
--
Petr Vobornik
From 38b586a287dba18abab885072db067a0411820e5 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Tue, 14 Jan 2014 17:29:47 +0100
Subject: [PATCH] webui: Don't act on keyboard events which originated in
 different dialog

Fixes issue when:
1. 2 dialogs are opened
2. top dialog's close button is focused
3. user presses enter to execute 'close' action
4. dialog is immediately closed (enter key is still pressed)
5. second dialog automatically receives focus (it's top dialog now)
6. user releases the key
7. second dialog reacts to keyup event - which is by default confirmation mixin's confirm event
8. UNDESIRED behavior occurs

Now confirmation mixin remembers which keys were pressed and released and reacts only to those which originated there.

https://fedorahosted.org/freeipa/ticket/4098
---
 install/ui/src/freeipa/dialog.js | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/install/ui/src/freeipa/dialog.js b/install/ui/src/freeipa/dialog.js
index cf9c7c304b8033552a84215fbb1966d664fdf222..941ff8a292e0263217c3fae900d3afc9e6380a76 100644
--- a/install/ui/src/freeipa/dialog.js
+++ b/install/ui/src/freeipa/dialog.js
@@ -1249,7 +1249,16 @@ IPA.confirm_mixin = function() {
             },
 
             /**
+             * Map of keys which are down
+             * @property {Object}
+             */
+            keysdown: {},
+
+            /**
              * Test if event is confirmation event
+             *
+             * Clears  event's keyCode in `keysdown` map
+             *
              * @param {Event} event
              * @return {boolean}
              */
@@ -1257,9 +1266,11 @@ IPA.confirm_mixin = function() {
 
                 var ir = this.ignore_enter_rules,
                     t = event.target,
-
+                    key = event.keyCode,
                     ignore = ir.src_elements.indexOf(t.tagName.toLowerCase()) > -1 ||
-                             ir.src_types.indexOf(t.type) > -1;
+                             ir.src_types.indexOf(t.type) > -1 ||
+                             !this.keysdown[key];
+                    delete this.keysdown[key];
 
                 return ignore;
             },
@@ -1270,8 +1281,10 @@ IPA.confirm_mixin = function() {
             register_listeners: function() {
                 var self = this;
                 this._on_key_up_listener = function(e) { self.on_key_up(e); };
+                this._on_key_down_listener = function(e) { self._on_key_down(e); };
                 var dialog_container = this.dom_node;
                 dialog_container.bind('keyup', this._on_key_up_listener);
+                dialog_container.bind('keydown', this._on_key_down_listener);
             },
 
             /**
@@ -1280,6 +1293,7 @@ IPA.confirm_mixin = function() {
             remove_listeners: function() {
                 var dialog_container = this.dom_node;
                 dialog_container.unbind('keyup', this._on_key_up_listener);
+                dialog_container.unbind('keydown', this._on_key_down_listener);
             },
 
             /**
@@ -1298,6 +1312,23 @@ IPA.confirm_mixin = function() {
                     event.preventDefault();
                     this.on_cancel();
                 }
+                delete this.keysdown[event.keyCode];
+            },
+
+            /**
+             * Internal listener for saving which keys were pressed to
+             * prevent reaction to event which originated in completely different
+             * control.
+             *
+             * Example: first dialog is closed by keydown event, second is
+             * therefore focused and consumes keyup event which can lead to undesired
+             * behavior.
+             *
+             * @private
+             * @param {Event} event
+             */
+            _on_key_down: function(event) {
+                this.keysdown[event.keyCode] = true;
             }
         },
 
-- 
1.8.5.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to