1var app = angular.module('bossApp'); 2app.controller('addNotificationPreferenceCtrl', ['$scope', '$http', '$state', '$stateParams', '$rootScope', '$cookies', 'NotificationPreferenceService', 'UserNewEditService', '$timeout', 3 function ($scope, $http, $state, $stateParams, $rootScope, $cookies, NotificationPreferenceService, UserNewEditService, $timeout) { 4 $scope.loadingPreference = true; 5 $scope.errorMessage = ""; 6 function clearErrorMessage() { 7 $scope.errorMessage = ""; 8 } 9 var preference = { 10 name: undefined, 11 phoneNumbers: [], 12 emailIds: [], 13 status: undefined, 14 notifications: [] 15 }; 16 $scope.preference = angular.copy(preference); 17 /** 18 * Edit Preference 19 */ 20 loadUserList(); 21 NotificationPreferenceService.getStaticData().then(function (data) { 22 var notificationTypes = data.responseObj.notificationPrefTypes; 23 var notifications = []; 24 var notificationTypeMap = new Map(); 25 for (var i = 0; i < notificationTypes.length; i++) { 26 var notification = { 27 email: false, 28 text: false, 29 notificationType: notificationTypes[i].id, 30 desc: notificationTypes[i].desc, 31 show: notificationTypes[i].desc ? true : false 32 }; 33 notifications.push(notification); 34 notificationTypeMap.set(notificationTypes[i].id, notificationTypes[i].desc); 35 } 36 $scope.preference.notifications = notifications; 37 if ($stateParams.preferenceId) { 38 NotificationPreferenceService.getNotificationPreference($stateParams.preferenceId).then(function (response) { 39 var _preference = angular.copy(response.responseObj); 40 _preference.emailIds = _preference.emailIds?_preference.emailIds.join(","):null; 41 _preference.phoneNumbers = _preference.phoneNumbers?_preference.phoneNumbers.join(","):null; 42 if (_preference.notificationPrefType === "LegalContact") { 43 _preference.notificationPrefType = "Legal Contact"; 44 } 45 if (_preference.notificationPrefType === "NotificationOnly") { 46 _preference.notificationPrefType = "Notification Only (For Unregistered Contacts)"; 47 } 48 if (_preference.notifications) { 49 for (var i = 0; i < _preference.notifications.length; i++) { 50 var notification = _preference.notifications[i]; 51 notification.desc = notificationTypeMap.get(notification.notificationType) || notification.desc; 52 notification.show = false; 53 if (notification.desc) { 54 notification.show = true; 55 } 56 } 57 } else { 58 _preference.notifications = notifications; 59 } 60 61 $scope.preference = _preference 62 }); 63 } 64 }); 65 66 /** 67 * Load All User to populate through typeahead. 68 */ 69 function loadUserList() { 70 UserNewEditService.getUserList().then(function (data) { 71 $scope.userList = data.responseObj.filter(user => user.status==="Active"); 72 $scope.loadingPreference = false; 73 }); 74 } 75 /** 76 * Fucntion to populate Name,Email,Phone on typeahead-on-select. 77 */ 78 $scope.populateContactDetails = function () { 79 let _userId = angular.copy($scope.preference.leContactId); 80 if (_userId) { 81 _index = $scope.indexOfObject($scope.userList, 'userId', _userId); 82 let _user = $scope.userList[_index]; 83 if (angular.isDefined(_user)) { 84 let fullName = _user.firstName + " " + _user.lastName; 85 $scope.preference.name = angular.copy(fullName); 86 $scope.preference.emailIds = angular.copy(_user.emailAddress); 87 $scope.preference.phoneNumbers = angular.copy(_user.textNumber); 88 } 89 } else { 90 $scope.preference.name = undefined; 91 $scope.preference.emailIds = ""; 92 $scope.preference.phoneNumbers = ""; 93 } 94 } 95 96 /** 97 * Fucntion to clear the Notification Details. 98 */ 99 $scope.clearDetails = function () { 100 $scope.preference.leContactId ="" 101 $scope.preference.name = ""; 102 $scope.preference.emailIds = ""; 103 $scope.preference.phoneNumbers = ""; 104 for (var i = 0; i < $scope.preference.notifications.length; i++) { 105 $scope.preference.notifications[i].email = false; 106 $scope.preference.notifications[i].text = false; 107 } 108 } 109 110 /*** 111 * Function to save/add Notification Preference. 112 */ 113 $scope.savePreference = function () { 114 $scope.exception = ""; 115 let _preference = angular.copy($scope.preference); 116 _preference.id = $stateParams.preferenceId;
117 if (_preference.notificationPrefType == "Legal Contact") { 118 _preference.notificationPrefType = "LegalContact"; 119 } else { 120 _preference.notificationPrefType = "NotificationOnly"; 121 } 122 // Adding [] to the Email and PhoneNumber 123 if ((_preference.emailIds && !Array.isArray(_preference.emailIds))|| _preference.emailIds == "") { 124 _preference.emailIds = _preference.emailIds.split(","); 125 } 126 if ((_preference.phoneNumbers && !Array.isArray(_preference.phoneNumbers)) || _preference.phoneNumbers == "") { 127 _preference.phoneNumbers = _preference.phoneNumbers.split(","); 128 } 129 130 var _userList = angular.copy($scope.userList); 131 var isValidUser = true; 132 if (_preference.notificationPrefType == "LegalContact") { 133 isValidUser = _userList.some(user => user.userId.toLowerCase() === _preference.leContactId.toLowerCase()); 134 if (!isValidUser) { 135 $scope.preference.leContactId = ""; 136 $scope.errorMessage = "The given User is not valid. Please provide valid User."; 137 $timeout(clearErrorMessage, 20000); 138 }else if($scope.preference.name === ''){ 139 $scope.preference.leContactId = ""; 140 $scope.errorMessage = "Please select the User in the search result."; 141 $timeout(clearErrorMessage, 20000); 142 } 143 144 } 145 //Checking for the Notification is enabled or not 146 var isNotificationsEnabled = false; 147 for (var i = 0; i < _preference.notifications.length; i++) { 148 if (_preference.notifications[i].email != false || _preference.notifications[i].text != false) { 149 isNotificationsEnabled = true; 150 } 151 } 152 if (!isNotificationsEnabled) { 153 $scope.errorMessage = "Notifications are not enabled. Please enable Email or Text Notifications."; 154 $timeout(clearErrorMessage, 20000); 155 } 156 //Checking Atleast one of the Additional EmailId's or Additional PhoneNumbers are entered or not. 157 var emailIds = $scope.preference.emailIds; 158 var phoneNumbers = $scope.preference.phoneNumbers; 159 var isAdditionalEmailIdsandPhoneNumbers = false; 160 if((!emailIds && emailIds.trim() === '') && (!phoneNumbers && phoneNumbers.trim() === '')){ 161 isAdditionalEmailIdsandPhoneNumbers = true; 162 } 163 if (isAdditionalEmailIdsandPhoneNumbers && _preference.notificationPrefType == "NotificationOnly") { 164 $scope.errorMessage = "The Additional EmailIds and PhoneNumbers are empty, please enter atleast one of them"; 165 $timeout(clearErrorMessage, 20000); 166 } 167 if (!$scope.preferenceForm.phoneNumber.$error.required && !$scope.preferenceForm.email.$error.required 168 && !$scope.preferenceForm.name.$error.required && isValidUser && isNotificationsEnabled && !isAdditionalEmailIdsandPhoneNumbers) { 169 notificationPref(_preference); 170 } 171 } 172 173 function showPhoneNumberWarning(_preference){ 174 bootbox.confirm({ 175 title: "Warning Message", 176 message: "Mobile numbers outside the US must be prefixed with +Country Code (e.g. +49 for Germany). For US numbers this is not mandatory. Do you want to proceed?", 177 swapButtonOrder: true, 178 closeButton: false, 179 buttons: { 180 confirm: { label: 'Yes', className: 'btn-primary' }, 181 cancel: { label: 'No', className: 'btn-danger' } 182 }, 183 callback: function (result) { 184 console.log("Result",result) 185 console.log(_preference) 186 if (result) { 187 notificationPref(_preference,true); 188 return result; 189 } 190 } 191 }); 192 } 193 194 function notificationPref(_preference, overRidePhoneNumber) { 195 _preference.overRidePhoneNumber = overRidePhoneNumber==true?true:false; 196 NotificationPreferenceService.saveNotificationPreference(_preference).then(function (response) { 197 if (response.success) { 198 $state.go("home.admin.manageNotificationPreferences"); 199 }else if(response.errorResponse == "OVERRIDE_PHONENUMBER"){ 200 showPhoneNumberWarning(_preference); 201 } 202 else { 203 $scope.exception = response.errorResponse; 204 } 205 }); 206 } 207 $scope.$watchCollection('[preference.phoneNumber,preference.email,preference.name]', function () { 208 $scope.exception = ""; 209 }); 210 $scope.indexOfObject = function indexOfObject(array, property, value) { 211 if (array) { 212 for (var i = 0; i < array.length; i++) { 213 if (array[i][property] === value) return i; 214 } 215 } 216 return -1; 217 }; 218 }]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.