"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"; // Define functions to be executed and redirect path when the button is // clicked var BOOTSTRAP_COMPONENT = { "1": { /* "fn": hasPaymentNotifications, */ "redirectPath": PCK_GLOBAL_VARIABLES.pck_home_home_view + "#/invoices" }, "2": { "redirectPath": PCK_GLOBAL_VARIABLES.pck_calendar_comp_home_view + "#/reservations" }, "3": { "redirectPath": PCK_GLOBAL_VARIABLES.pck_home_home_view + "#/my-profile" } }; /** * DashboardButtonCtrl Create a dashboard button component and provide some * functionality to it, like the opssibility to redirect to another page * when clicked. * The component is also configurable in its background color, icon, label, * notification background color and notification border color. It also * receives a unique identifier as a property. */ var DashboardButtonCtrl = /*#__PURE__*/function () { function DashboardButtonCtrl(constant, $window) { _classCallCheck(this, DashboardButtonCtrl); this.imgPath = constant.imgPath; this.$window = $window; this.hasNotification = false; } /** * $onInit Initialize the component by bootstraping it and by initializing * the click handler */ _createClass(DashboardButtonCtrl, [{ key: "$onInit", value: function $onInit() { bootstrap(this); this.buttonHandler = buildButtonHandler(this); } }]); return DashboardButtonCtrl; }(); /****** Private functions ******/ /** * bootstrap Executes a function if the id of the current instance of the * component is a key in the object BOOTSTRAP_COMPONENT * @param {Object} self Current instance of the component */ function bootstrap(self) { if (Object.keys(BOOTSTRAP_COMPONENT).indexOf(self.identifier) >= 0 && BOOTSTRAP_COMPONENT[self.identifier].hasOwnProperty("fn")) { BOOTSTRAP_COMPONENT[self.identifier].fn(self); } } /** * hasPaymentNotifications Specific function to be executed for a specific id. * It allows to check if a notification should be displayed for the pay_invoices * button, by invoking a web service. * @param {Object} self Current instance of the component */ /* function hasPaymentNotifications(self) { // TODO - implement web service call to check if a payment notification icon should be displayed self.hasNotification = true; } */ /** * buildButtonHandler Builds a button handler for each instance of this * component. And returns a caalback function that is executed onclick event * of the component * @param {String} identifier Unique identifier for this component * @param {Object} self Current instance of the component * @return {Function} Returns a callback function */ function buildButtonHandler(self) { return function () { switch (self.identifier) { case "1": //console.log("redirect for button: ", self.identifier); //self.$window.location.href = BOOTSTRAP_COMPONENT[self.identifier].redirectPath; self.$window.location.href = BOOTSTRAP_COMPONENT[self.identifier].redirectPath; break; case "2": //console.log("redirect for button: ", self.identifier); self.$window.location.href = BOOTSTRAP_COMPONENT[self.identifier].redirectPath; break; case "3": //console.log("redirect for button: ", self.identifier); self.$window.location.href = BOOTSTRAP_COMPONENT[self.identifier].redirectPath; break; /* case "4": console.log("redirect for button: ", self.identifier); break; case "5": console.log("redirect for button: ", self.identifier); break; case "6": console.log("redirect for button: ", self.identifier); break; case "7": console.log("redirect for button: ", self.identifier); break; */ default: return; } }; } // Set up component definition var dashboardButton = { bindings: { bckColor: "@", icon: "@", label: "@", identifier: "@", notificationBckColor: "@?", notificationBorderColor: "@?" }, controller: DashboardButtonCtrl, templateUrl: PCK_GLOBAL_VARIABLES.dashboard_button_view }; angular.module("agp.dashboard.button").component("dashboardButton", dashboardButton); }).call();