"use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } (function () { "use strict"; /** * UserMenuCtrl Functionality for the component user menu */ var UserMenuCtrl = /*#__PURE__*/function () { function UserMenuCtrl(HomeLoginService, $timeout, constant, $window, $location, $mdMenu) { _classCallCheck(this, UserMenuCtrl); this.loginService = HomeLoginService; this.$timeout = $timeout; this.imgPath = constant.imgPath; this.$window = $window; this.$mdMenu = $mdMenu; this.$location = $location; this.params = {}; this.name = ""; this.fullName = ""; this.menuProfileHandlers = { "myaccount": myAccountHandler, "logout": logoutHandler, "logoutgoogleconnect": logoutGoogleConnect }; } /** * $onChanges Executed when the binding "userName" is changed. */ _createClass(UserMenuCtrl, [{ key: "$onChanges", value: function $onChanges() { this.fullName = this.userFullName; this.name = this.userName; if (this.isLoggedIn) { this.$timeout(function () { franceConnectKit.init(); }); } } /** * actionClicked Listener for menu click events * * @param {Object} ev AngularJS $event */ }, { key: "actionClicked", value: function actionClicked(ev) { var currentTargetId = ev.currentTarget.id; this.params = { "loginService": this.loginService, "window": this.$window, "location": this.$location }; executeHandler(this, currentTargetId); } /** * getLoginData get login data. Usefull in the view because by using this method * we create a watcher for changes in the session item loginData * */ }, { key: "getLoginData", value: function getLoginData() { return sessionHandler.sessionStorage.get("loginData") !== null ? sessionHandler.sessionStorage.get("loginData") : {}; } }, { key: "openUserMenu", value: function openUserMenu() { angular.element("#notifications-popup").hide(); angular.element("#header-notification-container").removeClass("clicked-notif"); } }]); return UserMenuCtrl; }(); /********** Private Functions **********/ /** * executeHandler Execute an handler, that is identified by a unique * attribute id from the element that was clicked. * * @param {Object} self UserMenuCtrl instance * @param {String} id Unique attribute id from the clicked element */ function executeHandler(self, id) { if (self.menuProfileHandlers.hasOwnProperty(id)) { self.menuProfileHandlers[id](self.params); } } /** * myAccountHandler Handler for the event that was triggered with the * id "myaccount". * * @param {Object} params Helper object with necessary data */ function myAccountHandler(params) { if (params.window.hasOwnProperty("home") && params.window.home.name === "home") { params.location.path("/my-profile"); } else { params.window.location.href = PCK_GLOBAL_VARIABLES.pck_home_home_view + "#/my-profile"; } } /** * logoutHandler Handler for the event that was triggered with the * id "logout". * * @param {Object} params Helper object with necessary data */ function logoutHandler(params) { if (params.hasOwnProperty("loginService")) { params.loginService.logout(); } } /** * logoutGoogleConnect Set the type and action clicked by the user and * redirect to the route 'google-connect' to logout the user from Agora Plus * and from google * @param {Object} params Object with dependencies to be used by this method */ function logoutGoogleConnect(params) { var loginData = { "loginType": "googleconnect", "action": "googleLogout", "urlLogout": "", "createAccountTempResult": -1 }; sessionHandler.sessionStorage.set("loginData", loginData); params.window.location.href = PCK_GLOBAL_VARIABLES.pck_home_home_view + "#/google-connect"; } // Component definition object var userMenu = { templateUrl: "transversalModule/template/agp_user_menu_comp_view.html", bindings: { userFullName: "@", userName: "@", isLoggedIn: "<" }, controller: UserMenuCtrl }; angular.module("agp.usermenu", []).component("userMenu", userMenu); }).call();