"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"; var AgpHeaderCtrl = /*#__PURE__*/function () { function AgpHeaderCtrl($timeout, constant, HomeService, $mdMedia, backofficeConfigService, $location, EventStoreService, ProcessService, $mdDialog) { _classCallCheck(this, AgpHeaderCtrl); this.$timeout = $timeout; this.imgPath = constant.imgPath; this.processService = ProcessService; this.homeService = HomeService; this.$mdMedia = $mdMedia; this.$mdDialog = $mdDialog; this.eventStoreService = EventStoreService; this.backofficeConfigService = backofficeConfigService; this.$location = $location; this.notificationsopup = false; this.headerActive = false; this.emailsList = []; this.userName = ""; this.defaultInitialConfig = { configsList: { ContactUsWorkflow: null, headerBackgroundColor: '#0abeec', headerTextColor: '#ffffff', logoImage: this.imgPath + 'assets/img/default-picture.png', municipalityName: 'Agora', contactUsConfig: { "isVisible": 0, "processStatus": 4, "endDate": "12/04/2018", "idProcess": 12, "idWorkflow": 2, "workflowName": "Family creation test 1", "startDate": "12/04/2018" } } }; this.contactUsWorkflow = sessionHandler.sessionStorage.get("contactUsWorkflow"); this.showContactUs = 0; this.query = { order: 'SEND_DATE DESC', limit: 20, page: 1, filter: "%" }; } _createClass(AgpHeaderCtrl, [{ key: "$onInit", value: function $onInit() { var self = this; self.eventStoreService.setEventStore({ eventType: "emailsData", func: function func() { var isRequest = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var data = arguments.length > 1 ? arguments[1] : undefined; var changeReadStatusById = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (isRequest) { var resp = {}; self.processService.getEmailLogs(true, 0, self.query).then(function (response) { resp = response; })["finally"](function () { self.emailsList = resp.data; })["catch"](function (error) {}); } else if (changeReadStatusById) { for (var i = 0; i < self.emailsList.length; i++) { if (data.ID_LOG_NOTIF_READ === self.emailsList[i].ID_LOG_NOTIF_READ) { self.emailsList[i].IS_READ = data.IS_READ; break; } } } else { self.emailsList = data; } } }); var googleAnalyticsUsed = false, googleAnalyticsKey = null, googleAnalyticsUsage = {}; this.homeService.getGoogleAnalyticsUsage().then(function (response) { googleAnalyticsUsage = response; })["catch"](function (error) { console.error("GA usage: " + error); })["finally"](function () { var typeResult = 0; if (googleAnalyticsUsage.hasOwnProperty("data") && googleAnalyticsUsage.data.hasOwnProperty("TYPE_RESULT")) { typeResult = +googleAnalyticsUsage.data.TYPE_RESULT; } if (typeResult === 1) { googleAnalyticsUsed = googleAnalyticsUsage.data.DATA.google_analytics_used === 1; googleAnalyticsKey = googleAnalyticsUsage.data.DATA.google_analytics_key; if (googleAnalyticsUsed) { (function (i, s, o, g, r, a, m) { i["GoogleAnalyticsObject"] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments); }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, "script", "https://www.google-analytics.com/analytics.js", "ga"); ga("create", googleAnalyticsKey, "auto"); ga("send", "pageview"); } } }); // handling the cookies warning (function (i, s, o, g, r, c, a, m) { i["CookiesChoiceObject"] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments); }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); if (c) { a.addEventListener('load', function (e) { c(null, e); }, false); } })(window, document, "script", PCK_GLOBAL_VARIABLES.IMG_PATH + "assets/libs/cookiechoices.js", "cookiechoice", function (event) { cookieChoices.showCookieConsentBar('Ce site utilise des cookies pour vous offrir le meilleur service possible. En poursuivant votre navigation, vous acceptez l\'utilisation des cookies.', 'J\'accepte', null, null, null, null); }); // handling the detection of the browser // if we are loading the page saying that the browser is not up to date, we must not do the check var checkBrowser; try { var currentRoute = $route.current.loadedTemplateUrl; // this might not be defined, this is why we surround that with a try/catch var updateBrowserRoute = $route.routes["/update_your_browser"].templateUrl; checkBrowser = !(currentRoute == updateBrowserRoute); } catch (error) { checkBrowser = true; } if (checkBrowser) { (function (i, s, o, g, r, c, a, m) { i["BrowserDetectionObject"] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments); }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); if (c) { a.addEventListener('load', function (e) { c(null, e); }, false); } })(window, document, "script", PCK_GLOBAL_VARIABLES.js_browser_detection, "browserdetection", function (event) { if (!browserOk()) { window.location.replace(PCK_GLOBAL_VARIABLES.update_your_browser_url); } }); } } }, { key: "$onChanges", value: function $onChanges() { if (typeof this.initialConfig === "undefined" || !this.initialConfig) { this.initialConfig = {}; if (typeof this.initialConfig.configsList === "undefined" || !this.initialConfig.configsList) { this.initialConfig.configsList = {}; } } this.initBasicConfig(); if (this.isLoggedIn) { this.userInitials = ""; this.fullName = "PROFILE"; var userInfo = sessionHandler.sessionStorage.get("userInfo"); if (userInfo !== null) { userInfo = typeof userInfo === "string" ? JSON.parse(userInfo) : userInfo; if (userInfo.hasOwnProperty("FIRST_NAME") && userInfo.FIRST_NAME) { this.fullName = userInfo.FIRST_NAME; this.userInitials = userInfo.FIRST_NAME.substring(0, 1).toUpperCase(); if (userInfo.hasOwnProperty("LAST_NAME") && userInfo.LAST_NAME) { this.userInitials = this.userInitials + userInfo.LAST_NAME.substring(0, 1).toUpperCase(); this.fullName = this.fullName + " " + userInfo.LAST_NAME; } } } } } /** * initBasicConfig Initialize basic configuration * (in this iteration 0.0.1) it initializes the header with the background * color configured by the client. * @param {Object} initialConfig Retrieved initial configuration from a WS */ }, { key: "initBasicConfig", value: function initBasicConfig() { var _this = this; var self = this; this.$timeout(function () { if (_this.initialConfig.configsList.hasOwnProperty("headerBackgroundColor") && _this.initialConfig.configsList.headerBackgroundColor && sessionHandler.sessionStorage.get("showBridge") != null && sessionHandler.sessionStorage.get("showBridge") != true || _this.initialConfig.configsList.hasOwnProperty("headerBackgroundColor") && _this.initialConfig.configsList.headerBackgroundColor && sessionHandler.sessionStorage.get("showBridge") === null) { _this.headerBackgroundColor = _this.initialConfig.configsList.headerBackgroundColor + ";"; } else { _this.headerBackgroundColor = _this.defaultInitialConfig.configsList.headerBackgroundColor + ";"; } if (_this.initialConfig.configsList.hasOwnProperty("headerTextColor") && _this.initialConfig.configsList.headerTextColor && sessionHandler.sessionStorage.get("showBridge") != null && sessionHandler.sessionStorage.get("showBridge") != true || _this.initialConfig.configsList.hasOwnProperty("headerTextColor") && _this.initialConfig.configsList.headerTextColor && sessionHandler.sessionStorage.get("showBridge") === null) { _this.headerTextColor = _this.initialConfig.configsList.headerTextColor + ";"; } else { _this.headerTextColor = _this.defaultInitialConfig.configsList.headerTextColor + ";"; } _this.logoImage = _this.initialConfig.configsList.hasOwnProperty("logoImage") && _this.initialConfig.configsList.logoImage && _this.initialConfig.configsList.logoImage != " " ? _this.initialConfig.configsList.logoImage : _this.defaultInitialConfig.configsList.logoImage; _this.municipalityName = _this.initialConfig.configsList.hasOwnProperty("municipalityName") && _this.initialConfig.configsList.municipalityName ? _this.initialConfig.configsList.municipalityName : _this.defaultInitialConfig.configsList.municipalityName; _this.showContactUs = _this.initialConfig.configsList.hasOwnProperty("showContactUs") && _this.initialConfig.configsList.showContactUs ? _this.initialConfig.configsList.showContactUs : _this.defaultInitialConfig.configsList.showContactUs; _this.ContactUsWorkflowId = _this.initialConfig.configsList.hasOwnProperty("ContactUsWorkflow") && _this.initialConfig.configsList.ContactUsWorkflow ? _this.initialConfig.configsList.ContactUsWorkflow : _this.defaultInitialConfig.configsList.ContactUsWorkflow; // Get email data on eventstore if (self.contactUsWorkflow === null && self.ContactUsWorkflowId != null) self.getUrlWorkflowById(); if (_this.isLoggedIn && sessionHandler.sessionStorage.get("showBridge") != null && sessionHandler.sessionStorage.get("showBridge") === false) self.eventStoreService.getEventStore('emailsData').func(true); // Show Header component After render setTimeout(function () { angular.element('#agp-header-component').show(); }, 200); //Bind Notifications self.bindNotificationsPopUp(); }); } }, { key: "bindNotificationsPopUp", value: function bindNotificationsPopUp() { angular.element(document).on('click', function (e) { if (e.target.id != 'notifications-popup' && angular.element(e.target).parents('#notifications-popup').length == 0 && e.target.id != 'header-notification-container' && angular.element(e.target).parents('#header-notification-container').length == 0) { angular.element("#notifications-popup").hide(); angular.element("#header-notification-container").removeClass("clicked-notif"); } }); angular.element("#header-notification-container").off().on('click', function (e) { angular.element("#header-notification-container").toggleClass("clicked-notif"); angular.element("#notifications-popup").toggle(); }); } }, { key: "getUrlWorkflowById", value: function getUrlWorkflowById() { // Save Instance var self = this; var resp = null; self.homeService.getUrlWorkflowById(parseInt(self.ContactUsWorkflowId)).then(function (response) { resp = response; })["catch"](function (error) { console.error(error); })["finally"](function () { self.contactUsWorkflow = resp; // Set contactUsWorkflow in session storage sessionHandler.sessionStorage.set("contactUsWorkflow", self.contactUsWorkflow); }); } }, { key: "contactUs", value: function contactUs() { window.location = this.contactUsWorkflow; } /** * redirect Header logo click event listener */ }, { key: "redirect", value: function redirect() { moduleSelection(this, sessionHandler.sessionStorage.get("showBridge") != null && sessionHandler.sessionStorage.get("showBridge") === true); } /** * Go to viewAllProcess */ }, { key: "viewAllProcess", value: function viewAllProcess() { angular.element("#notifications-popup").hide(); angular.element("#header-notification-container").removeClass("clicked-notif"); window.location.href = PCK_GLOBAL_VARIABLES.pck_home_home_view + "#notifications-area"; } }, { key: "getTotalNewNotifications", value: function getTotalNewNotifications() { var self = this; var unread = 0; if (self.emailsList != null) { for (var i = 0; i < self.emailsList.length; i++) { if (self.emailsList[i].IS_READ === 0) unread++; } } return unread >= 20 ? 20 : unread; } }, { key: "showDialog", value: function showDialog(email) { angular.element("#notifications-popup").hide(); if (email.IS_READ === 0) this.changeStatus(email); this.popUpData = email; this.$mdDialog.show({ contentElement: '#inboxDialog', parent: angular.element(document.body) }); } }, { key: "close", value: function close() { this.$mdDialog.hide(); } }, { key: "changeStatus", value: function changeStatus(email) { var self = this; var payload = { "idNotifications": email.ID_NOTIFICATIONS, "idTypeNotifRead": email.ID_TYPE_NOTIF_READ, "idLogNotifRead": email.ID_LOG_NOTIF_READ, "markNotifRead": email.IS_READ === 1 ? 0 : 1 }; var resp = {}; this.processService.changeStatusOfNotifRead(payload).then(function (response) { resp = response; })["finally"](function () { if (resp.data.TYPE_RESULT > 0) { self.popUpData.IS_READ = email.IS_READ === 1 ? 0 : 1; self.eventStoreService.getEventStore('emailsData').func(false, self.emailsList); } })["catch"](function (error) {}); } /** * 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() { franceConnectKit.init(); return sessionHandler.sessionStorage.get("loginData") !== null ? sessionHandler.sessionStorage.get("loginData") : {}; } }]); return AgpHeaderCtrl; }(); /** * moduleSelection - check if the user is on home module and perform a redirect * @param {Object} self * @param {Boolean} fromV2 */ function moduleSelection(self, fromV2) { var isfromV2 = fromV2 || false; redirectTo(self, isfromV2, window.hasOwnProperty("home")); } /** * redirectTo - depending on a series of conditions, redirect the user to dashboard or to home page * @param {Object} self * @param {Boolean} isfromV2 * @param {Boolean} isHomeModule */ function redirectTo(self, isfromV2, isHomeModule) { if (self.isLoggedIn) { if (!isfromV2) { isHomeModule ? self.$location.path("/dashboard") : window.location = PCK_GLOBAL_VARIABLES.pck_home_home_view_logged_in; return; } } else { if (!isfromV2) { isHomeModule ? self.$location.path("/") : window.location = PCK_GLOBAL_VARIABLES.pck_home_home_view; return; } } window.location = PCK_GLOBAL_VARIABLES.dashboard_v2; } // Component definition var agpHeader = { bindings: { initialConfig: "<", isLoggedIn: "<" }, controller: AgpHeaderCtrl, templateUrl: "transversalModule/template/agp_header_comp_view.html" }; angular.module("agp.transversal.header", []).component("agpHeader", agpHeader); }).call();