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