"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"; /** * AgpSidenavCtrl Sidenav controller * Allows to control the sidenav toogle. When this component * initializes, and if the item 'sidenavSelectedItem' is not present in * session storage the selected item will 'home'. */ var AgpSidenavCtrl = /*#__PURE__*/function () { function AgpSidenavCtrl(EventStoreService, $http, $mdSidenav, constant, HomeService, $location, $timeout, $scope, $mdMedia) { _classCallCheck(this, AgpSidenavCtrl); this.$timeout = $timeout; this.$mdSidenav = $mdSidenav; this.eventStoreService = EventStoreService; this.imgPath = constant.imgPath; this.$http = $http; this.logoPath = ""; this.clientName = ""; this.selectedItem = ""; this.sidenavMenu = []; this.homeService = HomeService; this.$location = $location; this.$scope = $scope; this.$mdMedia = $mdMedia; } /** * $onInit Initialize the sidenav with the correct selected item */ _createClass(AgpSidenavCtrl, [{ key: "$onInit", value: function $onInit() { this.getSideNavMenus(true); this.toggle = buildToggler(this, this.componentId); var selectedItem = sessionHandler.sessionStorage.get("sidenavSelectedItem"); if (selectedItem) { this.selectedItem = selectedItem; } else { this.selectedItem = "home"; } sessionHandler.sessionStorage.set("sidenavSelectedItem", this.selectedItem); } /** * $onChanges Set up the correct logo and client name in the sidenav */ }, { key: "$onChanges", value: function $onChanges() { if (this.initialConfig) { if (this.initialConfig.hasOwnProperty("configsList")) { if (this.initialConfig.configsList.hasOwnProperty("logoImage")) { var logoPath = this.initialConfig.configsList.logoImage; this.logoPath = logoPath.trim(); } if (this.initialConfig.configsList.hasOwnProperty("municipalityName")) { this.clientName = this.initialConfig.configsList.municipalityName; } } } } /** * Get Dynamic menu config */ }, { key: "getSideNavMenus", value: function getSideNavMenus() { // Save Instance var self = this; // Set Event self.eventStoreService.setEventStore({ eventType: "sideNavReload", func: function func() { var reload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; self.reloadSidenavMenuData(reload); } }); self.eventStoreService.getEventStore('sideNavReload').func(true); } }, { key: "reloadSidenavMenuData", value: function reloadSidenavMenuData(reload) { var self = this; var sidenavMenuSessionStorage = sessionHandler.sessionStorage.get("sidenavMenu"); if (sidenavMenuSessionStorage === null || reload) { var resp = {}; self.homeService.getSideNavMenus().then(function (response) { resp = response; })["catch"](function (error) { console.error(error); })["finally"](function () { self.sidenavMenu = resp; sessionHandler.sessionStorage.set("sidenavMenu", self.sidenavMenu); }); } else { self.sidenavMenu = sidenavMenuSessionStorage; } } /** * isItemSelected Verify if the 'listItem' is the one that is selected * @param {String} listItem List item unique identifier * @return {Boolean} If true the 'listItem' is the one that is * selected. */ }, { key: "isItemSelected", value: function isItemSelected(listItem) { return listItem.path === this.$location.absUrl().split('?')[0]; } /** * setSelectedItem On mdListItem click set the clicked list item as the one * that was selected. * @param {String} selectedItem Unique list item identifier */ }, { key: "setSelectedItem", value: function setSelectedItem(selectedItem) { this.selectedItem = selectedItem; } }, { key: "bindSideNavClickOutSide", value: function bindSideNavClickOutSide() { angular.element(document).on('click', function (e) { if (e.target.id != 'side-nav-component' && angular.element(e.target).parents('#side-nav-component').length == 0) {} }); } }, { key: "redirectTo", value: function redirectTo() { this.$mdSidenav(this.componentId).close(); this.redirect(); } }]); return AgpSidenavCtrl; }(); /** * buildToggler Build the sidenav toggler. Also add the CSS class * 'agp-footer-custom', if it's not present, so that the sidenav stays above * the footer * @param {Object} self AgpSidenavCtrl instance * @param {String} id Sidenav unique identifier * @return {Function} Returns a function that is executed when the buttons * open/close are clicked */ function buildToggler(self, id) { return function () { var elem = angular.element(document.getElementById("agpFooter")); if (elem.hasClass("agp-footer-custom")) { elem.removeClass("agp-footer-custom"); } else { elem.addClass("agp-footer-custom"); } self.$mdSidenav(id).toggle(); // Bind close side nive when click outside angular.element(document).on('click', function (e) { if (e.target.id != 'side-nav-component' && angular.element(e.target).parents('#side-nav-component').length == 0 && e.target.id != 'sidenav-open-button-container-button' && angular.element(e.target).parents('#sidenav-open-button-container-button').length == 0) { self.$mdSidenav(id).close(); } }); }; } // Component definition var agpSidenav = { templateUrl: "transversalModule/template/agp_sidenav_view.html", controller: AgpSidenavCtrl, bindings: { componentId: "@", initialConfig: "<", redirect: "&?" } }; angular.module("agp.sidenav", []).component("agpSidenav", agpSidenav); }).call();