ac7d03
From 894fdd8c10552ef0b90363db985bb25e398d99e1 Mon Sep 17 00:00:00 2001
ac7d03
From: Pavel Vomacka <pvomacka@redhat.com>
ac7d03
Date: Wed, 22 Mar 2017 16:48:36 +0100
ac7d03
Subject: [PATCH] WebUI: add method for disabling item in user dropdown menu
ac7d03
ac7d03
AD user can do only several things. One of those which are not
ac7d03
allowed is to reset password to itself. Therefore we need to be
ac7d03
able to turn of a item in dropdown menu. In our case
ac7d03
'Password reset' item. Function which disable menu item and detach
ac7d03
the listener on click from the item specified by its name was added.
ac7d03
ac7d03
Part of: https://pagure.io/freeipa/issue/3242
ac7d03
ac7d03
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
ac7d03
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
ac7d03
---
ac7d03
 install/ui/src/freeipa/Application_controller.js | 42 ++++++++++++++++++++----
ac7d03
 install/ui/src/freeipa/widgets/App.js            |  4 +++
ac7d03
 2 files changed, 40 insertions(+), 6 deletions(-)
ac7d03
ac7d03
diff --git a/install/ui/src/freeipa/Application_controller.js b/install/ui/src/freeipa/Application_controller.js
ac7d03
index 32add5f8f3d6874c1c555bf28d2b70cd54af5956..d809c1f2662609e390609270ef3ddc42f0727936 100644
ac7d03
--- a/install/ui/src/freeipa/Application_controller.js
ac7d03
+++ b/install/ui/src/freeipa/Application_controller.js
ac7d03
@@ -69,6 +69,16 @@ define([
ac7d03
         facet_changing: false,
ac7d03
 
ac7d03
         /**
ac7d03
+         * Listeners for user menu items
ac7d03
+         */
ac7d03
+         on_profile_listener: null,
ac7d03
+         on_passwd_reset_listener: null,
ac7d03
+         on_logout_listener: null,
ac7d03
+         on_item_select_listener: null,
ac7d03
+         on_configuration_listerer: null,
ac7d03
+         on_about_listener: null,
ac7d03
+
ac7d03
+        /**
ac7d03
          * Currently displayed facet
ac7d03
          *
ac7d03
          */
ac7d03
@@ -109,12 +119,7 @@ define([
ac7d03
                 }
ac7d03
             };
ac7d03
 
ac7d03
-            on(this.app_widget.menu_widget, 'item-select', this.on_menu_click.bind(this));
ac7d03
-            on(this.app_widget, 'profile-click', this.on_profile.bind(this));
ac7d03
-            on(this.app_widget, 'logout-click', this.on_logout.bind(this));
ac7d03
-            on(this.app_widget, 'password-reset-click', this.on_password_reset.bind(this));
ac7d03
-            on(this.app_widget, 'configuration-click', this.on_configuration.bind(this));
ac7d03
-            on(this.app_widget, 'about-click', this.on_about.bind(this));
ac7d03
+            this.register_user_menu_listeners();
ac7d03
 
ac7d03
             on(this.router, 'facet-show', this.on_facet_show.bind(this));
ac7d03
             on(this.router, 'facet-change', this.on_facet_change.bind(this));
ac7d03
@@ -133,6 +138,31 @@ define([
ac7d03
             IPA.opened_dialogs.start_handling(this);
ac7d03
         },
ac7d03
 
ac7d03
+        register_user_menu_listeners: function() {
ac7d03
+            this.on_profile_listener = on(this.app_widget, 'profile-click',
ac7d03
+                    this.on_profile.bind(this));
ac7d03
+            this.on_passwd_reset_listener = on(this.app_widget,
ac7d03
+                    'password-reset-click', this.on_password_reset.bind(this));
ac7d03
+            this.on_logout_listener = on(this.app_widget, 'logout-click',
ac7d03
+                    this.on_logout.bind(this));
ac7d03
+            this.on_item_select_listener = on(this.app_widget.menu_widget,
ac7d03
+                    'item-select', this.on_menu_click.bind(this));
ac7d03
+            this.on_configuration_listerer = on(this.app_widget,
ac7d03
+                    'configuration-click', this.on_configuration.bind(this));
ac7d03
+            this.on_about_listener = on(this.app_widget,
ac7d03
+                    'about-click', this.on_about.bind(this));
ac7d03
+        },
ac7d03
+
ac7d03
+        /**
ac7d03
+         * Turns off one item in user dropdown menu and remove its listener.
ac7d03
+         * @param {string} name of the user menu item which should be disabled
ac7d03
+         * @param {Object} listener disable this listener
ac7d03
+         */
ac7d03
+        disable_user_menu_item: function(name, listener) {
ac7d03
+            this.app_widget.disable_user_menu_item(name);
ac7d03
+            listener.remove();
ac7d03
+        },
ac7d03
+
ac7d03
         /**
ac7d03
          * Gets:
ac7d03
          *  * metadata
ac7d03
diff --git a/install/ui/src/freeipa/widgets/App.js b/install/ui/src/freeipa/widgets/App.js
ac7d03
index 68b78c7c4be44f5a1f658fed6b6b75d1beda22c5..95bc9b2cf3bcf40cd3a4cab47e9043e05331e019 100644
ac7d03
--- a/install/ui/src/freeipa/widgets/App.js
ac7d03
+++ b/install/ui/src/freeipa/widgets/App.js
ac7d03
@@ -222,6 +222,10 @@ define(['dojo/_base/declare',
ac7d03
             }
ac7d03
         },
ac7d03
 
ac7d03
+        disable_user_menu_item: function(name) {
ac7d03
+            this.user_menu.disable_item(name);
ac7d03
+        },
ac7d03
+
ac7d03
         on_menu_item_click: function(item) {
ac7d03
             this.collapse_menu();
ac7d03
         },
ac7d03
-- 
ac7d03
2.12.1
ac7d03