-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-'use strict';\r
-\r
-(function () {\r
-\r
- class userNotificationsModalCtrl {\r
- constructor($scope, $log, functionalMenuService, confirmBoxService, notificationService, $modal, ngDialog, $state, $filter) {\r
-\r
- let newNotifModel = {\r
- 'isOnlineUsersOnly': null,\r
- 'isForAllRolesOptions': null,\r
- 'selectedPriority': null,\r
- 'isActive': null,\r
- 'startTime': null,\r
- 'endTime': null,\r
- 'msgHeader': null,\r
- 'msgDescription': null,\r
- 'roleIds': null,\r
- 'roleObj': {notificationRoleIds:null}\r
- };\r
- \r
- $scope.notificationId = null;\r
- $scope.selectedCat = null;\r
- $scope.selectedEcompFunc = null;\r
- this.YN_index_mapping = {\r
- "Y": 0,\r
- "N": 1\r
- }\r
- \r
- $scope.onlineAllUsersOptions = [\r
- { "index": 0, "value": "Y", "title": "Online Users Only" },\r
- { "index": 1, "value": "N", "title": "Online & Offline Users" }\r
- \r
- ];\r
-\r
- $scope.isForAllRolesOptions = [\r
- { "index": 0, "value": "Y", "title": "Yes" },\r
- { "index": 1, "value": "N", "title": "No" }\r
- ];\r
-\r
- $scope.priorityOptions = [\r
- { "index": 0, "value": 1, "title": "Normal" },\r
- { "index": 1, "value": 2, "title": "Important" }\r
- ];\r
-\r
- $scope.isActiveOptions = [\r
- { "index": 0, "value": "Y", "title": "Yes" },\r
- { "index": 1, "value": "N", "title": "No" }\r
- ];\r
- $scope.isActive = $scope.isActiveOptions[0];\r
- $scope.selectPriority = $scope.priorityOptions[0];\r
- $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[1];\r
- $scope.isForAllRoles=$scope.isForAllRolesOptions[0].value;\r
- $scope.isFunctionalMenu ="Y";\r
-\r
- $scope.selectedPriority=$scope.priorityOptions[0].value;\r
-\r
- // $scope.notificationRoleIds = [];\r
- $scope.msgHeader = '';\r
- $scope.msgDescription = '';\r
- $scope.treeTitle="Functional Menu";\r
- $scope.notifObj= {isCategoriesFunctionalMenu:true};\r
-\r
- let init = () => {\r
- // $log.info('userNotificationsModalCtrl::init');\r
- this.isSaving = false;\r
- var today = new Date();\r
- $scope.minDate = today.toISOString().substring(0, 10);\r
- var threeMonthsFromNow = new Date();\r
- threeMonthsFromNow.setMonth(threeMonthsFromNow.getMonth() + 3);\r
- $scope.maxDate = threeMonthsFromNow.toISOString().substring(0, 10);\r
- if ($scope.ngDialogData && $scope.ngDialogData.notif) {\r
- // $log.debug('userNotificationsModalCtrl:init:: Edit\r
- // notification mode for', $scope.ngDialogData.notif);\r
- $scope.isEditMode = true;\r
- $scope.editModeObj = {isEditMode: true};\r
- this.notif = _.clone($scope.ngDialogData.notif);\r
- $scope.modalPgTitle = 'View Notification'\r
- $scope.isOnlineUsersOnly = $scope.onlineAllUsersOptions[this.YN_index_mapping[this.notif.isForOnlineUsers]];\r
- $scope.isForAllRoles = $scope.isForAllRolesOptions[this.YN_index_mapping[this.notif.isForAllRoles]].value;\r
- $scope.isActive = $scope.isActiveOptions[this.YN_index_mapping[this.notif.activeYn]];\r
- $scope.selectedPriority = $scope.priorityOptions[this.notif.priority - 1].value;\r
- $scope.startTime = new Date(this.notif.startTime);\r
- $scope.endTime = new Date(this.notif.endTime);\r
- $scope.msgHeader = this.notif.msgHeader;\r
- $scope.msgDescription = this.notif.msgDescription;\r
- $scope.notificationId = this.notif.notificationId;\r
- $scope.notificationRoleIds = this.notif.roleIds;\r
- $scope.roleObj = {notificationRoleIds:this.notif.roleIds};\r
- } else {\r
- // $log.debug('AppDetailsModalCtrl:init:: New app mode');\r
- $scope.isEditMode = false;\r
- $scope.editModeObj = {isEditMode: false};\r
- $scope.modalPgTitle = 'Add a New Notification'\r
- this.notif = _.clone(newNotifModel);\r
- $scope.roleObj = {notificationRoleIds:null};\r
- }\r
- };\r
- this.conflictMessages = {};\r
- this.scrollApi = {};\r
- let handleConflictErrors = err => {\r
- if(!err.data){\r
- return;\r
- }\r
- if(!err.data.length){ // support objects\r
- err.data = [err.data]\r
- }\r
- _.forEach(err.data, item => {\r
- _.forEach(item.fields, field => {\r
- // set conflict message\r
- this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];\r
- // set field as invalid\r
- $scope.appForm[field.name].$setValidity('conflict', false);\r
- // set watch once to clear error after user correction\r
- watchOnce[field.name]();\r
- });\r
- });\r
- this.scrollApi.scrollTop();\r
- };\r
-\r
- let resetConflict = fieldName => {\r
- delete this.conflictMessages[fieldName];\r
- if($scope.appForm[fieldName]){\r
- $scope.appForm[fieldName].$setValidity('conflict', true);\r
- }\r
- };\r
- $scope.addUserNotificationValidation = function () {\r
- // // pre-processing\r
- if (!($scope.isEditMode)) { \r
- var validation=false;\r
-\r
- if($scope.startTime && $scope.endTime && $scope.msgHeader != '' && $scope.msgDescription != '' && ($scope.startTime<$scope.endTime)){\r
- validation=true;\r
- if( $scope.isForAllRoles=='N'){\r
- validation = $scope.checkBoxObj.isAnyRoleSelected;\r
- }\r
- }\r
- else{\r
- validation=false;\r
- }\r
- \r
- \r
- return !validation; \r
- }\r
- }\r
- \r
- /* format the value for viewing a notification */\r
- $scope.formatStartDate = function () {\r
- if ($scope.startTime) {\r
- $scope.startTime = $filter('date')($scope.startTime, 'medium'); \r
- } \r
- }\r
- \r
- /* format the value for viewing a notification */\r
- $scope.formatEndDate = function () {\r
- if($scope.endTime){\r
- $scope.endTime = $filter('date')($scope.endTime, 'medium');\r
- }\r
- }\r
- \r
- $scope.addUserNotification = function () {\r
- $scope.notificationRoleIds = [];\r
- // pre-processing\r
- for (var key in $scope.checkboxIdDict) {\r
- if ($scope.checkboxIdDict[key].is_box_checked && ($scope.checkboxIdDict[key].role_id != null)) {\r
- var role_ids = $scope.checkboxIdDict[key].role_id;\r
- for (var i in role_ids) {\r
- if (!($scope.notificationRoleIds.indexOf(role_ids[i]) > -1)) {\r
- $scope.notificationRoleIds.push(role_ids[i]);\r
- }\r
- }\r
- }\r
- }\r
-\r
- $scope.notificationRoleIds.sort();\r
- if (($scope.isOnlineUsersOnly) && ($scope.isForAllRoles) && ($scope.selectedPriority) && ($scope.isActive)\r
- && ($scope.startTime) && ($scope.endTime) && ($scope.msgHeader != '') && ($scope.msgDescription != '')) {\r
- this.newUserNotification =\r
- {\r
- 'notificationId':$scope.notificationId,\r
- 'isForOnlineUsers': $scope.isOnlineUsersOnly.value,\r
- 'isForAllRoles': $scope.isForAllRoles,\r
- 'priority': $scope.selectedPriority,\r
- 'activeYn': $scope.isActive.value,\r
- 'startTime': $scope.startTime,\r
- 'endTime': $scope.endTime,\r
- 'msgHeader': $scope.msgHeader,\r
- 'msgDescription': $scope.msgDescription,\r
- 'roleIds': $scope.notificationRoleIds,\r
- 'createdDate': new Date()\r
- };\r
-\r
- // POST ajax call here;\r
- if ($scope.isEditMode) {\r
- notificationService.updateAdminNotification(this.newUserNotification)\r
- .then(() => {\r
- //$log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');\r
- $scope.closeThisDialog(true);\r
- // emptyCookies();\r
- }).catch(err => {\r
- $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));\r
- switch (err.status) {\r
- case '409': // Conflict\r
- // handleConflictErrors(err);\r
- break;\r
- case '500': // Internal Server Error\r
- confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
- 'Please try again later. Error: ' + err.status).then(isConfirmed => { });\r
- break;\r
- case '403': // Forbidden... possible\r
- // webjunction error to\r
- // try again\r
- confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
- 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });\r
- break;\r
- default:\r
- confirmBoxService.showInformation('There was a problem updating the notification. ' +\r
- 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });\r
- }\r
- }).finally(() => {\r
- // for bug in IE 11\r
- var objOffsetVersion = objAgent.indexOf("MSIE");\r
- if (objOffsetVersion != -1) {\r
- $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');\r
- $window.location.reload(); \r
- }\r
- // for bug in IE 11\r
- });\r
-\r
- } else {\r
- notificationService.addAdminNotification(this.newUserNotification)\r
- .then((res) => {\r
- $log.debug('notificationService:addAdminNotification:: Admin notification creation succeeded!,',res);\r
- if(res.status=='ERROR'){\r
- confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
- ' Error: ' + res.response).then(isConfirmed => { });\r
-\r
- \r
- }\r
- else{\r
- $scope.closeThisDialog(true);\r
- }\r
- \r
- // emptyCookies();\r
- }).catch(err => {\r
- switch (err.status) {\r
- case '409': // Conflict\r
- // handleConflictErrors(err);\r
- break;\r
- case '500': // Internal Server Error\r
- confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
- 'Please try again later. Error: ' + err.status).then(isConfirmed => { });\r
- break;\r
- default:\r
- confirmBoxService.showInformation('There was a problem adding the notification. ' +\r
- 'Please try again. If the problem persists, then try again later. Error: ' +\r
- err.status).then(isConfirmed => { });\r
- }\r
- $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));\r
- })\r
- }\r
-\r
- \r
- } else {\r
- $log.warn('please fill in all required fields');\r
- confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });\r
- }\r
- }\r
- // Populate the category list for category dropdown list\r
- let getFunctionalMenu = () => {\r
- this.isLoadingTable = true;\r
- $scope.notifObj= {isCategoriesFunctionalMenu:true};\r
- functionalMenuService.getFunctionalMenuRole().then(role_res => {\r
- var menu_role_dict = {};\r
- for (var i in role_res) {\r
- // if first time appear in menu_role_dict\r
- if (!(role_res[i].menuId in menu_role_dict)) {\r
- menu_role_dict[role_res[i].menuId] = [role_res[i].roleId];\r
- } else {\r
- menu_role_dict[role_res[i].menuId].push(role_res[i].roleId);\r
- }\r
- }\r
- functionalMenuService.getManagedFunctionalMenuForNotificationTree().then(res => {\r
- let actualData = [];\r
- var exclude_list = ['Favorites']\r
- // Adding children and label attribute to all objects in\r
- $scope.checkboxIdDict = {};\r
- $scope.checkBoxObj = {isAnyRoleSelected:false};\r
- for (let i = 0; i < res.length; i++) {\r
- res[i].children = [];\r
- res[i].label = res[i].text;\r
- res[i].id = res[i].text;\r
- // res[i].is_box_checked = false;\r
- res[i].can_check = true;\r
- res[i].roleId = menu_role_dict[res[i].menuId];\r
- $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId };\r
- }\r
-\r
- // Adding actual child items to children array in res\r
- // objects\r
- $scope.parentChildDict ={};\r
- $scope.parentChildRoleIdDict ={};\r
- for (let i = 0; i < res.length; i++) {\r
- let parentId = res[i].menuId;\r
- $scope.parentChildDict[parentId] = [];\r
- $scope.parentChildRoleIdDict[parentId]=[];\r
- for (let j = 0; j < res.length; j++) {\r
- let childId = res[j].parentMenuId;\r
- if (parentId === childId) {\r
- res[i].children.push(res[j]);\r
- $scope.parentChildDict[parentId].push(res[j].menuId);\r
- //if res[j].roleId is defined\r
- if (res[j].roleId) {\r
- for (let k in res[j].roleId) {\r
- $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);\r
- }\r
- \r
- }\r
- }\r
- }\r
- }\r
- \r
- //check if grand children exist\r
- for (var key in $scope.parentChildDict){\r
- var children = $scope.parentChildDict[key];\r
- var isGrandParent = false;\r
- if (children.length>0) {\r
- for (var i in children) {\r
- if ($scope.parentChildDict[children[i]].length>0){\r
- isGrandParent = true;\r
- break;\r
- }\r
- }\r
- }\r
- if (isGrandParent) {\r
- for (var i in children) {\r
- // if the child has children\r
- if ($scope.parentChildDict[children[i]].length>0) {\r
- for (var j in $scope.parentChildRoleIdDict[children[i]]) {\r
- \r
- if ($scope.parentChildRoleIdDict[key].indexOf($scope.parentChildRoleIdDict[children[i]][j]) === -1) {\r
- $scope.parentChildRoleIdDict[key].push($scope.parentChildRoleIdDict[children[i]][j]);\r
- }\r
- }\r
- } else {\r
- \r
- }\r
- }\r
- }\r
-\r
- }; \r
- \r
-\r
- var ListMenuIdToRemove = [];\r
- //$scope.parentObj = {ListMenuIdToRemove : []};\r
- //get the list of menuId that needs to be removed \r
- for (let i = 0; i < res.length; i++) {\r
- if ((res[i].children.length==0)&&(!res[i].roleId)) {\r
- var menuIdToRemove = res[i].menuId;\r
- if (ListMenuIdToRemove.indexOf(menuIdToRemove) === -1){\r
- ListMenuIdToRemove.push(menuIdToRemove);\r
- }\r
- }\r
- }\r
-\r
- // a scope variable that marks whether each functional menu item should be displayed.\r
- $scope.toShowItemDict = {}; \r
- for (let i = 0; i < res.length; i++) {\r
- if (res[i].roleId==null) {\r
- if (res[i].children.length==0) {\r
- $scope.toShowItemDict[res[i].menuId]=false; \r
- } else if(res[i].children.length>0){\r
- if($scope.parentChildDict[res[i].menuId].length === _.intersection($scope.parentChildDict[res[i].menuId], ListMenuIdToRemove).length){\r
- $scope.toShowItemDict[res[i].menuId]=false; \r
- } else {\r
- $scope.toShowItemDict[res[i].menuId]=true; \r
- }\r
- }\r
- } else {\r
- $scope.toShowItemDict[res[i].menuId]=true;\r
- }\r
- }\r
- \r
- // Sort the top-level menu items in order based on the\r
- // column\r
- res.sort(function (a, b) {\r
- return a.column - b.column;\r
- });\r
-\r
- // Sort all the children in order based on the column\r
- for (let i = 0; i < res.length; i++) {\r
- res[i].children.sort(function (a, b) {\r
- return a.column - b.column;\r
- });\r
- }\r
-\r
- // Forming actual parent items\r
- for (let i = 0; i < res.length; i++) {\r
- let parentId = res[i].parentMenuId;\r
- if (parentId === null) {\r
- actualData.push(res[i]);\r
- }\r
- }\r
-\r
- // $scope.treedata = actualData;\r
- var treedata = actualData[0].children;\r
- $scope.treedata = [];\r
- for (var i in treedata) {\r
- if (!(treedata[i].label.indexOf(exclude_list) > -1)) {\r
- $scope.treedata.push(treedata[i])\r
- }\r
- }\r
-\r
- }).catch(err => {\r
- $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
- }).finally(() => {\r
- this.isLoadingTable = false;\r
- })\r
-\r
- }).catch(err => {\r
- $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
- })\r
- ;\r
- }\r
- \r
- \r
- let getAppRoleIds = () => {\r
- $scope.notifObj= {isCategoriesFunctionalMenu:false};\r
- notificationService.getAppRoleIds().then(res => {\r
- \r
- res = res.data;\r
- let actualData = [];\r
- // var exclude_list = ['Favorites']\r
- var app_id_name_list = {};\r
- $scope.checkboxIdDict = {};\r
- $scope.checkBoxObj = {isAnyRoleSelected:false};\r
-\r
- for (let i = 0; i < res.length; i++) {\r
- if (!(res[i].appId in app_id_name_list)) {\r
- app_id_name_list[res[i].appId] = res[i].appName;\r
- }\r
-\r
- res[i].children = [];\r
- res[i].label = res[i].roleName;\r
- res[i].id = res[i].roleId;\r
- res[i].menuId = res[i].roleId;\r
- res[i].parentMenuId = res[i].appId;\r
- res[i].can_check = true;\r
- res[i].roleId = [res[i].roleId];\r
- $scope.checkboxIdDict[res[i].id] = { 'is_box_checked': false, 'role_id': res[i].roleId}; \r
- }\r
- \r
- for (var app_id in app_id_name_list) {\r
- var new_res = {};\r
- new_res.children = [];\r
- new_res.label = app_id_name_list[app_id];\r
- new_res.id = app_id;\r
- new_res.menuId = app_id;\r
- new_res.parentMenuId = null;\r
- new_res.appId = null;\r
- new_res.can_check = true;\r
- new_res.roleId = null;\r
- $scope.checkboxIdDict[new_res.id]= { 'is_box_checked': false, 'role_id': new_res.roleId };\r
- res.push(new_res);\r
- }\r
- $scope.parentChildRoleIdDict ={};\r
- //Adding actual child items to children array in res objects\r
- for (let i = 0; i < res.length; i++) {\r
- let parentId = res[i].menuId;\r
- $scope.parentChildRoleIdDict[parentId]=[];\r
- for (let j = 0; j < res.length; j++) {\r
- let childId = res[j].parentMenuId;\r
- if (parentId == childId) {\r
- res[i].children.push(res[j]);\r
- if (res[j].roleId) {\r
- for (let k in res[j].roleId) {\r
- $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);\r
- }\r
- \r
- }\r
- }\r
- }\r
- }\r
- //Forming actual parent items\r
- for (let i = 0; i < res.length; i++) {\r
- let parentId = res[i].parentMenuId;\r
- if (parentId === null) {\r
- actualData.push(res[i]);\r
- }\r
- }\r
-\r
- $scope.treedata = actualData;\r
- }).catch(err => {\r
- $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);\r
- }).finally(() => {\r
- this.isLoadingTable = false;\r
- })\r
- }\r
- $scope.getFunctionalMenu= function() {\r
- $scope.treeTitle="Functional Menu";\r
- getFunctionalMenu();\r
- }\r
- $scope.getAppRoleIds = function() {\r
- $scope.treeTitle="Applications/Roles";\r
- getAppRoleIds();\r
- }\r
- \r
- init();\r
- getFunctionalMenu();\r
-\r
- }\r
- \r
- }\r
- \r
- userNotificationsModalCtrl.$inject = ['$scope', '$log', 'functionalMenuService', 'confirmBoxService', 'notificationService', '$modal', 'ngDialog', '$state', '$filter'];\r
- angular.module('ecompApp').controller('userNotificationsModalCtrl', userNotificationsModalCtrl);\r
- \r
- angular.module('ecompApp').directive('attDatepickerCustom', ['$log', function($log) {\r
- return {\r
- restrict: 'A',\r
- require: 'ngModel',\r
- scope: {},\r
- \r
- controller: ['$scope', '$element', '$attrs', '$compile', 'datepickerConfig', 'datepickerService', function($scope, $element, $attrs, $compile, datepickerConfig, datepickerService) {\r
- var dateFormatString = angular.isDefined($attrs.dateFormat) ? $scope.$parent.$eval($attrs.dateFormat) : datepickerConfig.dateFormat;\r
- var selectedDateMessage = '<div class="sr-focus hidden-spoken" tabindex="-1">the date you selected is {{$parent.current | date : \'' + dateFormatString + '\'}}</div>';\r
- $element.removeAttr('att-datepicker-custom');\r
- $element.removeAttr('ng-model');\r
- $element.attr('ng-value', '$parent.current | date:"EEEE, MMMM d, y"');\r
- $element.attr('aria-describedby', 'datepicker');\r
- \r
- $element.attr('maxlength', 10);\r
-\r
- var wrapperElement = angular.element('<div></div>');\r
- wrapperElement.attr('datepicker-popup', '');\r
- wrapperElement.attr('current', 'current');\r
-\r
- datepickerService.setAttributes($attrs, wrapperElement);\r
- datepickerService.bindScope($attrs, $scope);\r
-\r
- wrapperElement.html('');\r
- wrapperElement.append($element.prop('outerHTML'));\r
- if (navigator.userAgent.match(/MSIE 8/) === null) {\r
- wrapperElement.append(selectedDateMessage);\r
- }\r
- var elm = wrapperElement.prop('outerHTML');\r
- elm = $compile(elm)($scope);\r
- $element.replaceWith(elm);\r
- }],\r
- link: function(scope, elem, attr, ctrl) {\r
- if (!ctrl) {\r
- // do nothing if no ng-model\r
- $log.error("ng-model is required.");\r
- return;\r
- }\r
-\r
- scope.$watch('current', function(value) {\r
- ctrl.$setViewValue(value);\r
- });\r
- ctrl.$render = function() {\r
- scope.current = ctrl.$viewValue;\r
- };\r
- \r
- }\r
- };\r
- }]);\r
-\r
- angular.module('ecompApp').directive('jqTreeUserNotif', ['functionalMenuService', '$log', 'confirmBoxService', '$compile', function (functionalMenuService, $log, confirmBoxService, $compile) {\r
- return {\r
- scope: true,\r
- templateUrl: 'jq-tree-tmpl-user-notif.html',\r
- link: function (scope, el, attrs) {\r
-\r
- var $jqTree = el.find('#jqTreeUserNotif').tree({\r
- data: scope.treedata,\r
- autoOpen: scope.editModeObj.isEditMode,\r
- dragAndDrop: false,\r
- onCreateLi: function (node, $li) {\r
- node.is_checked = false;\r
- if (node.roleId&&scope.roleObj.notificationRoleIds) {\r
- node.is_checked = (node.roleId.length === _.intersection(node.roleId, scope.roleObj.notificationRoleIds).length);\r
- } \r
- if (typeof node.id =="string"){\r
- $li.attr('id', node.id.replace(/\s+/g, '_'));\r
- }\r
- var isChecked = '';\r
- if (node.is_checked) {\r
- isChecked = 'checked="checked"';\r
- }\r
- if (node.can_check) {\r
- var toShow = true;\r
- if (scope.notifObj.isCategoriesFunctionalMenu) {\r
- toShow = scope.toShowItemDict[node.menuId];\r
- }\r
- var isDisabled = "";\r
- if (scope.editModeObj.isEditMode) {\r
- isDisabled = " disabled"\r
- \r
- //if node is a parent/grandparent node\r
- if (node.children.length>0){\r
- //whether to show node first\r
- if (_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {\r
- toShow=true;\r
- if (scope.parentChildRoleIdDict[node.menuId].length==_.intersection(scope.parentChildRoleIdDict[node.menuId], scope.roleObj.notificationRoleIds).length) {\r
- isChecked = 'checked="checked"'; \r
- }\r
- } else {\r
- toShow=false;\r
- }\r
- } \r
- //if node is a child node\r
- else {\r
- if (node.is_checked) {\r
- toShow=true; \r
- } else {\r
- toShow=false;\r
- }\r
- }\r
-\r
- }\r
-\r
- \r
-\r
- var template = '<input ng-click="thisCheckboxClicked($event)" type="checkbox" class="edit js-node-check" data-node-menu-id="' + node.menuId + '" data-node-id="' + node.id + '" ' + isChecked + ' ng-show="' + toShow + '"' + isDisabled+ '/>'\r
-\r
- var templateEl = angular.element(template);\r
- var $jqCheckbox = $compile(templateEl)(scope);\r
- if (toShow){\r
- $li.find('.jqtree-element').prepend($jqCheckbox);\r
- } else {\r
- $li.find('.jqtree-element').remove();\r
- }\r
- }\r
- }\r
- });\r
-\r
- scope.thisCheckboxClicked = function (e) {\r
- \r
- var nodeId = e.target.attributes[4].value;\r
- \r
- \r
- \r
- var sBrowser, sUsrAg = window.navigator.userAgent;\r
- //if (sUsrAg.indexOf("Firefox") > -1) {\r
- \r
- if (sUsrAg.indexOf("Trident") > -1) {\r
- nodeId = e.target.attributes[5].value;\r
- }\r
- \r
-// if (sUsrAg.indexOf("MSIE") > 1) {\r
-// alert("hELLO tHIS IS IE10");\r
-// nodeId = e.target.attributes[3].value;\r
-// alert('nodeId 26 of IE 45 : '+nodeId);\r
-// }\r
-// \r
- var version = navigator.userAgent.match(/Firefox\/(.*)$/);\r
- \r
- if(version && version.length > 1){\r
- if(parseInt(version[1]) >= 50){\r
- nodeId = e.target.attributes[3].value;\r
- } else if(parseInt(version[1]) >= 45){\r
- \r
- nodeId = e.target.attributes[2].value;\r
- }\r
- }\r
- var thisNode = el.find('#jqTreeUserNotif').tree('getNodeById', nodeId);\r
- var isChecked = e.target.checked;\r
- scope.checkboxIdDict[nodeId]['is_box_checked'] = isChecked;\r
-\r
- thisNode = angular.element(thisNode);\r
- if (thisNode[0].hasOwnProperty('children') && thisNode[0].children.length > 0) {\r
- var jsNodeCheckList = angular.element(e.target).parent().next().find('.js-node-check')\r
- // check/uncheck children items\r
- jsNodeCheckList.prop('checked', isChecked);\r
-\r
- for (var i in jsNodeCheckList) {\r
- var singlediv = jsNodeCheckList[i];\r
- if (typeof singlediv == 'object' & (!singlediv.length)) {\r
- \r
- var tempNodeId = angular.element(singlediv)[0].attributes[4].value;\r
- \r
- \r
- \r
- if (sUsrAg.indexOf("Trident") > -1) {\r
- \r
- var tempNodeId = angular.element(singlediv)[0].attributes[5].value;\r
- \r
- \r
- }\r
- \r
-// if (sUsrAg.indexOf("MSIE") > 0) {\r
-// var tempNodeId = angular.element(singlediv)[0].attributes[3].value;\r
-// alert('tempNodeId 2 FF 45 : '+tempNodeId);\r
-// }\r
- if(version && version.length > 1){\r
- if(parseInt(version[1]) >= 50){\r
- tempNodeId = angular.element(singlediv)[0].attributes[3].value;\r
- } \r
- else if(parseInt(version[1]) >= 45){\r
- tempNodeId = angular.element(singlediv)[0].attributes[2].value;\r
- }\r
- }\r
- scope.checkboxIdDict[tempNodeId]['is_box_checked'] = isChecked;\r
- }\r
- }\r
- }\r
-\r
- scope.checkBoxObj.isAnyRoleSelected = false;\r
- for (var key in scope.checkboxIdDict) {\r
- if (scope.checkboxIdDict[key]['is_box_checked']&&scope.checkboxIdDict[key]['role_id']) {\r
- scope.checkBoxObj.isAnyRoleSelected = true;\r
- break;\r
- }\r
- }\r
- }\r
-\r
-\r
-\r
- scope.$watch('treedata', function (oldValue, newValue) {\r
- if (oldValue !== newValue) {\r
- $jqTree.tree('loadData', scope.treedata);\r
- $jqTree.tree('reload', function () {\r
- });\r
- }\r
- });\r
- }\r
- };\r
- }]);\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+'use strict';
+
+(function () {
+
+ class userNotificationsModalCtrl {
+ constructor($scope, $log, functionalMenuService, confirmBoxService, notificationService, $modal, ngDialog, $state, $filter,items) {
+ this.debug = false;
+ $scope.newNotifModel = {
+ 'isOnlineUsersOnly': null,
+ 'isForAllRolesOptions': null,
+ 'selectedPriority': null,
+ 'isActive': null,
+ 'startTime': '',
+ 'endTime': '',
+ 'msgHeader': null,
+ 'msgDescription': null,
+ 'roleIds': null,
+ 'anyTreeItemSelected':false,
+ 'roleObj': {notificationRoleIds:null}
+ };
+
+ $scope.notificationId = null;
+ $scope.selectedCat = null;
+ $scope.selectedEcompFunc = null;
+ this.YN_index_mapping = {
+ "Y": 0,
+ "N": 1
+ }
+
+ $scope.onlineAllUsersOptions = [
+ { "index": 0, "value": "Y", "title": "Online Users Only" },
+ { "index": 1, "value": "N", "title": "Online & Offline Users" }
+
+ ];
+
+ $scope.isForAllRolesOptions = [
+ { "index": 0, "value": "Y", "title": "Yes" },
+ { "index": 1, "value": "N", "title": "No" }
+ ];
+
+ $scope.priorityOptions = [
+ { "index": 0, "value": 1, "title": "Normal" },
+ { "index": 1, "value": 2, "title": "Important" }
+ ];
+
+ $scope.isActiveOptions = [
+ { "index": 0, "value": "Y", "title": "Yes" },
+ { "index": 1, "value": "N", "title": "No" }
+ ];
+ $scope.newNotifModel.isActive = $scope.isActiveOptions[0];
+ $scope.newNotifModel.selectPriority = $scope.priorityOptions[0];
+ $scope.newNotifModel.isOnlineUsersOnly = $scope.onlineAllUsersOptions[1];
+ $scope.newNotifModel.isForAllRoles=$scope.isForAllRolesOptions[0].value;
+ $scope.newNotifModel.isFunctionalMenu ="Y";
+
+ $scope.newNotifModel.selectedPriority=$scope.priorityOptions[0].value;
+ $scope.newNotifModel.msgHeader = '';
+ $scope.newNotifModel.msgDescription = '';
+ $scope.newNotifModel.treeTitle="Functional Menu";
+ $scope.newNotifModel.notifObj= {isCategoriesFunctionalMenu:true};
+
+ let init = () => {
+ if(this.debug)
+ $log.debug('userNotificationsModalCtrl::init');
+ this.isSaving = false;
+ var today = new Date();
+ $scope.minDate = today.toISOString().substring(0, 10);
+ var threeMonthsFromNow = new Date();
+ threeMonthsFromNow.setMonth(threeMonthsFromNow.getMonth() + 3);
+ $scope.maxDate = threeMonthsFromNow.toISOString().substring(0, 10);
+ if (items && items.notif) {
+ if(this.debug)
+ $log.debug('userNotificationsModalCtrl:init:: Edit notification mode for', items.notif);
+ $scope.isEditMode = true;
+ $scope.editModeObj = {isEditMode: true};
+ this.notif = _.clone(items.notif);
+ $scope.modalPgTitle = 'View Notification'
+ $scope.newNotifModel.isOnlineUsersOnly = $scope.onlineAllUsersOptions[this.YN_index_mapping[this.notif.isForOnlineUsers]];
+ $scope.newNotifModel.isForAllRoles = $scope.isForAllRolesOptions[this.YN_index_mapping[this.notif.isForAllRoles]].value;
+ $scope.newNotifModel.isActive = $scope.isActiveOptions[this.YN_index_mapping[this.notif.activeYn]];
+ $scope.newNotifModel.selectedPriority = $scope.priorityOptions[this.notif.priority - 1].value;
+ $scope.newNotifModel.startTime = new Date(this.notif.startTime);
+ $scope.newNotifModel.endTime = new Date(this.notif.endTime);
+ $scope.newNotifModel.msgHeader = this.notif.msgHeader;
+ $scope.newNotifModel.msgDescription = this.notif.msgDescription;
+ $scope.notificationId = this.notif.notificationId;
+ $scope.newNotifModel.notificationRoleIds = this.notif.roleIds;
+ $scope.roleObj = {notificationRoleIds:this.notif.roleIds};
+ } else {
+ if(this.debug)
+ $log.debug('AppDetailsModalCtrl:init:: New app mode');
+ $scope.isEditMode = false;
+ $scope.editModeObj = {isEditMode: false};
+ $scope.modalPgTitle = 'Add a New Notification'
+ this.notif = _.clone($scope.newNotifModel);
+ $scope.roleObj = {notificationRoleIds:null};
+ }
+ };
+ this.conflictMessages = {};
+ this.scrollApi = {};
+ let handleConflictErrors = err => {
+ if(!err.data){
+ return;
+ }
+ if(!err.data.length){ // support objects
+ err.data = [err.data]
+ }
+ _.forEach(err.data, item => {
+ _.forEach(item.fields, field => {
+ // set conflict message
+ this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];
+ // set field as invalid
+ $scope.appForm[field.name].$setValidity('conflict', false);
+ // set watch once to clear error after user correction
+ watchOnce[field.name]();
+ });
+ });
+ this.scrollApi.scrollTop();
+ };
+
+ let resetConflict = fieldName => {
+ delete this.conflictMessages[fieldName];
+ if($scope.appForm[fieldName]){
+ $scope.appForm[fieldName].$setValidity('conflict', true);
+ }
+ };
+ $scope.addUserNotificationValidation = function () {
+ // // pre-processing
+ if (!($scope.isEditMode)) {
+ var validation=false;
+ if($scope.isDateValid($scope.newNotifModel.startTime) && $scope.isDateValid($scope.newNotifModel.endTime) && $scope.newNotifModel.msgHeader != '' && $scope.newNotifModel.msgDescription != '' && ($scope.newNotifModel.startTime<$scope.newNotifModel.endTime)){
+ validation=true;
+ if( $scope.newNotifModel.isForAllRoles=='N'){
+ validation = $scope.checkTreeSelect();
+ }
+ }
+ else{
+ validation=false;
+ }
+ return !validation;
+ }
+ }
+
+ /* format the value for viewing a notification */
+ $scope.formatStartDate = function () {
+ if ($scope.newNotifModel.startTime) {
+ $scope.newNotifModel.startTime = $filter('date')($scope.startTime, 'medium');
+ }
+ }
+
+ /* format the value for viewing a notification */
+ $scope.formatEndDate = function () {
+ if($scope.newNotifModel.endTime){
+ $scope.newNotifModel.endTime = $filter('date')($scope.endTime, 'medium');
+ }
+ }
+
+ $scope.isDateValid = function (time) {
+ if(time == undefined){
+ return false;
+ }
+ if(typeof time == 'object'){
+ return true;
+ }
+ var startDateformat =time.split('/');
+ if (startDateformat.length != 3) return false;
+ var day = startDateformat[1];
+ var month = startDateformat[0];
+ month= parseInt(month)-1;
+ var year = startDateformat[2];
+ if(year.length!=4) return false;
+ var composedDate = new Date(year, month, day);
+ return composedDate.getDate() == day &&
+ composedDate.getMonth() == month &&
+ composedDate.getFullYear() == year;
+
+ };
+
+
+ $scope.addUserNotification = function () {
+ $scope.notificationRoleIds = [];
+ // pre-processing
+
+ for(var fi=0;fi<$scope.treedata.length;fi++){
+ var fLevel = $scope.treedata[fi];
+ if(fLevel){
+ var fLevelChild = fLevel.child;
+ for(var si=0;si<fLevelChild.length;si++){
+ var sLevel = fLevelChild[si];
+ if(sLevel){
+ var sLevelChild = sLevel.child;
+ if(sLevelChild){
+ for(var ti=0;ti< sLevelChild.length;ti++){
+ var tLevel = sLevelChild[ti];
+ if(tLevel.isSelected && tLevel.roleId){
+ $scope.newNotifModel.anyTreeItemSelected=true;
+ for(var i in tLevel.roleId)
+ $scope.notificationRoleIds.push(tLevel.roleId[i]);
+ }
+ }
+ }
+ }
+ if(sLevel.isSelected && sLevel.roleId){
+ for(var i in sLevel.roleId)
+ $scope.notificationRoleIds.push(sLevel.roleId[i]);
+ }
+ }
+ }
+ }
+
+ $scope.notificationRoleIds.sort();
+ if (($scope.newNotifModel.isOnlineUsersOnly) && ($scope.newNotifModel.isForAllRoles) && ($scope.newNotifModel.selectedPriority) && ($scope.newNotifModel.isActive)
+ && ($scope.newNotifModel.startTime) && ($scope.newNotifModel.endTime) && ($scope.newNotifModel.msgHeader != '') && ($scope.newNotifModel.msgDescription != '')) {
+ this.newUserNotification =
+ {
+ 'notificationId':$scope.notificationId,
+ 'isForOnlineUsers': $scope.newNotifModel.isOnlineUsersOnly.value,
+ 'isForAllRoles': $scope.newNotifModel.isForAllRoles,
+ 'priority': $scope.newNotifModel.selectedPriority,
+ 'activeYn': $scope.newNotifModel.isActive.value,
+ 'startTime': $scope.newNotifModel.startTime,
+ 'endTime': $scope.newNotifModel.endTime,
+ 'msgHeader': $scope.newNotifModel.msgHeader,
+ 'msgDescription': $scope.newNotifModel.msgDescription,
+ 'roleIds': $scope.notificationRoleIds,
+ 'createdDate': new Date()
+ };
+
+ // POST ajax call here;
+ if ($scope.isEditMode) {
+ notificationService.updateAdminNotification(this.newUserNotification)
+ .then(() => {
+ if(this.debug)
+ $log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');
+ $scope.closeThisDialog(true);
+ }).catch(err => {
+ $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));
+ switch (err.status) {
+ case '409': // Conflict
+ // handleConflictErrors(err);
+ break;
+ case '500': // Internal Server Error
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ case '403': // Forbidden... possible
+ // webjunction error to
+ // try again
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ default:
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
+ }
+ }).finally(() => {
+ // for bug in IE 11
+ var objOffsetVersion = objAgent.indexOf("MSIE");
+ if (objOffsetVersion != -1) {
+ if(this.debug)
+ $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
+ $window.location.reload();
+ }
+ // for bug in IE 11
+ });
+
+ } else {
+ notificationService.addAdminNotification(this.newUserNotification)
+ .then((res) => {
+ if(this.debug)
+ $log.debug('notificationService:addAdminNotification:: Admin notification creation succeeded!,',res);
+ if(res.status=='ERROR'){
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ ' Error: ' + res.response).then(isConfirmed => { });
+
+
+ }
+ else{
+ //$scope.closeThisDialog(true);
+ $scope.$dismiss('cancel');
+ }
+
+ // emptyCookies();
+ }).catch(err => {
+ switch (err.status) {
+ case '409': // Conflict
+ // handleConflictErrors(err);
+ break;
+ case '500': // Internal Server Error
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ default:
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' +
+ err.status).then(isConfirmed => { });
+ }
+ $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));
+ })
+ }
+
+
+ } else {
+ $log.warn('please fill in all required fields');
+ confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });
+ }
+ }
+ $scope.functionalMenuRes={};
+ $scope.checkTreeSelect = function(){
+ if($scope.treedata){
+ for(var fi=0; fi<$scope.treedata.length;fi++){
+ var fLevel = $scope.treedata[fi];
+ if(fLevel.isSelected){
+ return true;
+ }
+ var sLevel = fLevel.child;
+ if(sLevel){
+ for(var si=0;si<sLevel.length;si++){
+ if(sLevel[si].isSelected){
+ return true;
+ }
+ var tLevel = sLevel[si].child;
+ if(tLevel){
+ for(var ti=0;ti<tLevel.length;ti++){
+ if(tLevel[ti].isSelected){
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+ // Populate the category list for category dropdown list
+ let getFunctionalMenu = () => {
+ this.isLoadingTable = true;
+ if(this.debug)
+ $log.debug('getFunctionalMenu:init');
+
+ functionalMenuService.getFunctionalMenuRole().then(role_res => {
+ var menu_role_dict = {};
+ if(this.debug)
+ $log.debug('functionalMenuService:getFunctionalMenuRole:: getting result', role_res);
+
+ for (var i in role_res) {
+ // if first time appear in menu_role_dict
+ if (!(role_res[i].menuId in menu_role_dict)) {
+ menu_role_dict[role_res[i].menuId] = [role_res[i].roleId];
+ } else {
+ menu_role_dict[role_res[i].menuId].push(role_res[i].roleId);
+ }
+ }
+
+ functionalMenuService.getManagedFunctionalMenuForNotificationTree().then(res => {
+ if(this.debug)
+ $log.debug('functionalMenuService:getManagedFunctionalMenuForNotificationTree:: getting result', res);
+ var exclude_list = ['Favorites'];
+ let actualData=[];
+ $scope.functionalMenuRes=res;
+
+ //Adding children and label attribute to all objects in res
+ for(let i = 0; i < res.length; i++){
+ res[i].child=[];
+ res[i].name=res[i].text;
+ res[i].id=res[i].text;
+ res[i].displayCheckbox= true;
+ $scope.checkBoxObj = {isAnyRoleSelected:false};
+ res[i].roleId = menu_role_dict[res[i].menuId];
+ res[i].onSelect = function () {
+ $scope.$apply(function () {
+ $scope.newNotifModel.anyTreeItemSelected=$scope.checkTreeSelect();
+ })
+ };
+
+ if (res[i].roleId && res[i].roleId.length==_.intersection(res[i].roleId, $scope.roleObj.notificationRoleIds).length){
+ res[i].isSelected= true;
+ res[i].selected= true;
+ res[i].indeterminate= false;
+ }else{
+ /*default*/
+ res[i].isSelected= false;
+ res[i].selected= false;
+ res[i].indeterminate= false;
+ }
+ }
+
+ // Adding actual child items to children array in res
+ // objects
+ $scope.parentChildDict ={};
+ $scope.parentChildRoleIdDict ={};
+ for (let i = 0; i < res.length; i++) {
+ let parentId = res[i].menuId;
+ $scope.parentChildDict[parentId] = [];
+ $scope.parentChildRoleIdDict[parentId]=[];
+ for (let j = 0; j < res.length; j++) {
+ let childId = res[j].parentMenuId;
+ if (parentId === childId) {
+ res[i].child.push(res[j]);
+ $scope.parentChildDict[parentId].push(res[j].menuId);
+ //if res[j].roleId is defined
+ if (res[j].roleId) {
+ for (let k in res[j].roleId) {
+ $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
+ }
+
+ }
+ }
+ }
+ }
+ //check if grand children exist
+ for (var key in $scope.parentChildDict){
+ var child = $scope.parentChildDict[key];
+ var isGrandParent = false;
+ if (child.length>0) {
+ for (var i in child) {
+ if ($scope.parentChildDict[child[i]].length>0){
+ isGrandParent = true;
+ break;
+ }
+ }
+ }
+ if (isGrandParent) {
+ for (var i in child) {
+ // if the child has children
+ if ($scope.parentChildDict[child[i]].length>0) {
+ for (var j in $scope.parentChildRoleIdDict[child[i]]) {
+ if ($scope.parentChildRoleIdDict[key].indexOf($scope.parentChildRoleIdDict[child[i]][j]) === -1) {
+ $scope.parentChildRoleIdDict[key].push($scope.parentChildRoleIdDict[child[i]][j]);
+ }
+ }
+ }
+ }
+ }
+
+ };
+
+ // Sort the top-level menu items in order based on the column
+ res.sort(function(a, b) {
+ return a.column-b.column;
+ });
+
+ // Sort all the child in order based on the column
+ for(let i = 0; i < res.length; i++){
+ res[i].child.sort(function(a, b){
+ return a.column-b.column;
+ });
+ }
+
+ //Forming actual parent items
+ for(let i = 0; i < res.length; i++){
+ let parentId=res[i].parentMenuId;
+ if(parentId===null){
+ actualData.push(res[i]);
+ }
+ }
+ var treedata = actualData[0].child;
+ $scope.treedata = [];
+
+ /*Remove favorite from the list */
+ for (var i in treedata) {
+ if (!(treedata[i].name.indexOf(exclude_list) > -1)) {
+ $scope.treedata.push(treedata[i])
+ }
+ }
+ //setting b2b tree parameter
+ $scope.settingTreeParam();
+
+ }).catch(err => {
+ $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
+ }).finally(() => {
+ this.isLoadingTable = false;
+ })
+
+ }).catch(err => {
+ $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
+ })
+ ;
+ }
+
+
+ let getAppRoleIds = () => {
+ $scope.notifObj= {isCategoriesFunctionalMenu:false};
+ notificationService.getAppRoleIds().then(res => {
+ if(this.debug)
+ $log.debug('notificationService:getAppRoleIds:: getting result', res);
+ res = res.data;
+ let actualData = [];
+ var app_id_name_list = {};
+ $scope.checkBoxObj = {isAnyRoleSelected:false};
+ for (let i = 0; i < res.length; i++) {
+ if (!(res[i].appId in app_id_name_list)) {
+ app_id_name_list[res[i].appId] = res[i].appName;
+ }
+ res[i].child=[];
+ res[i].name=res[i].roleName;
+ res[i].displayCheckbox= true;
+ res[i].id = res[i].roleId;
+ res[i].menuId = res[i].roleId;
+ res[i].parentMenuId = res[i].appId;
+ res[i].can_check = true;
+ res[i].roleId = [res[i].roleId];
+ res[i].onSelect = function () {
+ $scope.$apply(function () {
+ $scope.newNotifModel.anyTreeItemSelected=$scope.checkTreeSelect();
+ })
+ };
+ /*assigning selected value*/
+ if (res[i].roleId && res[i].roleId.length==_.intersection(res[i].roleId, $scope.roleObj.notificationRoleIds).length){
+ res[i].isSelected= true;
+ res[i].selected= true;
+ res[i].indeterminate= false;
+ }else{
+ /*default*/
+ res[i].isSelected= false;
+ res[i].selected= false;
+ res[i].indeterminate= false;
+ }
+ }
+
+ for (var app_id in app_id_name_list) {
+ var new_res = {};
+ new_res.child = [];
+ new_res.name = app_id_name_list[app_id];
+ new_res.id = app_id;
+ new_res.displayCheckbox= true;
+ new_res.menuId = app_id;
+ new_res.parentMenuId = null;
+ new_res.appId = null;
+ new_res.can_check = true;
+ new_res.roleId = null;
+ new_res.onSelect = function () {
+ $scope.$apply(function () {
+ $scope.newNotifModel.anyTreeItemSelected=$scope.checkTreeSelect();
+ })
+ };
+ res.push(new_res);
+ }
+ $scope.parentChildRoleIdDict ={};
+ //Adding actual child items to child array in res objects
+ for (let i = 0; i < res.length; i++) {
+ let parentId = res[i].menuId;
+ $scope.parentChildRoleIdDict[parentId]=[];
+ for (let j = 0; j < res.length; j++) {
+ let childId = res[j].parentMenuId;
+ if (parentId == childId) {
+ res[i].child.push(res[j]);
+ if (res[j].roleId) {
+ for (let k in res[j].roleId) {
+ $scope.parentChildRoleIdDict[parentId].push(res[j].roleId[k]);
+ }
+
+ }
+ }
+ }
+ }
+ //Forming actual parent items
+ for (let i = 0; i < res.length; i++) {
+ let parentId = res[i].parentMenuId;
+ if (parentId === null) {
+ actualData.push(res[i]);
+ }
+ }
+
+ $scope.treedata = actualData;
+ //setting correct parameters for b2b tree
+ $scope.settingTreeParam();
+ }).catch(err => {
+ $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ', err);
+ }).finally(() => {
+ this.isLoadingTable = false;
+ })
+ }
+ $scope.getFunctionalMenu= function() {
+ $scope.treeTitle="Functional Menu";
+ getFunctionalMenu();
+ }
+ $scope.getAppRoleIds = function() {
+ $scope.treeTitle="Applications/Roles";
+ getAppRoleIds();
+ }
+
+
+
+ $scope.settingTreeParam = function(){
+ /**************first level****************/
+ for(var fi=0; fi<$scope.treedata.length;fi++){
+ var fLevel = $scope.treedata[fi];
+ var sLevel = $scope.treedata[fi].child;
+ var sLevelSelectedCount =0;
+ var sLevelChildNumber =0
+ if(fLevel.child.length==0 && fLevel.roleId==null){
+ delete fLevel.child;
+ }else if(sLevel){
+ /**************Second level****************/
+ var sLevelDelArray=[];
+ for(var si=0;si<sLevel.length;si++){
+ var deletThisSLev= false;
+ if(sLevel[si].child.length==0 && sLevel[si].roleId==null){
+ sLevel[si].displayCheckbox=false;
+ sLevelDelArray.push(sLevel[si].name);
+ sLevel[si].name = '';
+ sLevel[si].active=false;
+ delete sLevel[si].child;
+ } else if(sLevel[si].child.length==0){
+ delete sLevel[si].child;
+ }else{
+ /**************Third level****************/
+ var tLevel = sLevel[si].child;
+ var tLevelSelectedCount =0;
+ var tLevelChildNumber =0;
+ if(tLevel){
+ var tLevelDelArray=[];
+ var tLevelLen = tLevel.length;
+ var tLevelRoleIdUndefined =0;
+ for(var ti=0;ti<tLevel.length;ti++){
+ delete tLevel[ti].child;
+ if(tLevel[ti].roleId==null){
+ tLevel[ti].displayCheckbox=false;
+ tLevelDelArray.push(tLevel[ti].name);
+ tLevel[ti].name = '';
+ tLevel[ti].active=false;
+ tLevelRoleIdUndefined++
+ }else{
+ if(tLevel[ti].isSelected)
+ tLevelSelectedCount++;
+
+ if(tLevel[ti].displayCheckbox)
+ tLevelChildNumber++;
+ }
+ }
+ if(tLevelRoleIdUndefined==tLevelLen)
+ deletThisSLev=true;
+ if(tLevelSelectedCount==tLevelChildNumber){
+ sLevel[si].isSelected=true;
+ sLevel[si].indeterminate=false;
+ sLevel[si].active=true;
+ }else if(tLevelSelectedCount>0){
+ sLevel[si].indeterminate=true;
+ sLevel[si].active=true;
+ }
+
+ /*Cleanup unused third level items*/
+ for(var i=0;i<tLevelDelArray.length;i++){
+ var name = tLevelDelArray[i];
+ for(var ti=0;ti<tLevel.length;ti++){
+ if(name==tLevel[ti].text){
+ tLevel.splice(ti,1);
+ break;
+ }
+ }
+ }
+ }
+ }
+ if(deletThisSLev){ //remove the whole second level item if all it's child has no roleId
+ sLevel[si].displayCheckbox=false;
+ sLevelDelArray.push(sLevel[si].name);
+ sLevel[si].name = '';
+ sLevel[si].active=false;
+ }else{
+ if(sLevel[si].isSelected)
+ sLevelSelectedCount++;
+ if(sLevel[si].displayCheckbox)
+ sLevelChildNumber++;
+ }
+ }
+ if(sLevelSelectedCount==sLevelChildNumber && sLevelChildNumber!=0){
+ fLevel.isSelected=true;
+ fLevel.indeterminate=false;
+ fLevel.active=true;
+ }else if(sLevelSelectedCount>0){
+ fLevel.indeterminate=true;
+ fLevel.active=true;
+ }else{
+ //fLevel.active=false;
+ fLevel.indeterminate=false;
+ }
+ /*Cleanup unused second level items*/
+ for(var i=0;i<sLevelDelArray.length;i++){
+ var name = sLevelDelArray[i];
+ for(var si=0;si<sLevel.length;si++){
+ if(name==sLevel[si].text){
+ sLevel.splice(si,1);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ init();
+ getFunctionalMenu();
+
+ }
+
+ }
+
+ userNotificationsModalCtrl.$inject = ['$scope', '$log', 'functionalMenuService', 'confirmBoxService', 'notificationService', '$modal', 'ngDialog', '$state', '$filter','items'];
+ angular.module('ecompApp').controller('userNotificationsModalCtrl', userNotificationsModalCtrl);
+
+ angular.module('ecompApp').directive('attDatepickerCustom', ['$log', function($log) {
+ return {
+ restrict: 'A',
+ require: 'ngModel',
+ scope: {},
+
+ controller: ['$scope', '$element', '$attrs', '$compile', 'datepickerConfig', 'datepickerService', function($scope, $element, $attrs, $compile, datepickerConfig, datepickerService) {
+ var dateFormatString = angular.isDefined($attrs.dateFormat) ? $scope.$parent.$eval($attrs.dateFormat) : datepickerConfig.dateFormat;
+ var selectedDateMessage = '<div class="sr-focus hidden-spoken" tabindex="-1">the date you selected is {{$parent.current | date : \'' + dateFormatString + '\'}}</div>';
+ $element.removeAttr('att-datepicker-custom');
+ $element.removeAttr('ng-model');
+ $element.attr('ng-value', '$parent.current | date:"EEEE, MMMM d, y"');
+ $element.attr('aria-describedby', 'datepicker');
+
+ $element.attr('maxlength', 10);
+
+ var wrapperElement = angular.element('<div></div>');
+ wrapperElement.attr('datepicker-popup', '');
+ wrapperElement.attr('current', 'current');
+
+ datepickerService.setAttributes($attrs, wrapperElement);
+ datepickerService.bindScope($attrs, $scope);
+
+ wrapperElement.html('');
+ wrapperElement.append($element.prop('outerHTML'));
+ if (navigator.userAgent.match(/MSIE 8/) === null) {
+ wrapperElement.append(selectedDateMessage);
+ }
+ var elm = wrapperElement.prop('outerHTML');
+ elm = $compile(elm)($scope);
+ $element.replaceWith(elm);
+ }],
+ link: function(scope, elem, attr, ctrl) {
+ if (!ctrl) {
+ // do nothing if no ng-model
+ $log.error("ng-model is required.");
+ return;
+ }
+
+ scope.$watch('current', function(value) {
+ ctrl.$setViewValue(value);
+ });
+ ctrl.$render = function() {
+ scope.current = ctrl.$viewValue;
+ };
+
+ }
+ };
+ }]);
+
+
+})();