1app.controller('adminConsignorSettingsAdminUsersController', ['$scope', '$state', '$stateParams', '$timeout', '$q', '$location', 'localStorageService', 'permissionsService', 'authenticationService', 'consignorsService', 'lists', 'usersService', 2 function ($scope, $state, $stateParams, $timeout, $q, $location, localStorageService, permissionsService, authenticationService, consignorsService, lists, usersService) { 3 4 $scope.initializePage = function () { 5 $scope.$parent.activeChildView = $state.current.name.replace('adminConsignorSettings.', ''); 6 // Check to make sure they are logged in as a user 7 var requesteduserRightsRequested = { 8 roles: ['Super Admin', 'Admin', 'Consignor'], 9 permissions: ['CanChangeConsignorSettings'] 10 }; 11 permissionsService.isPermitted(requesteduserRightsRequested).then(function (results) { 12 if (!results.data) { 13 popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue."); 14 authenticationService.logout(); 15 $state.go('accountLogin'); 16 } else { 17 $scope.getConsignorUsersByConsignorId(); 18 } 19 }, function (error) { 20 popApiErrorMessage(error); 21 }); 22 23 }; 24 25 $scope.getConsignorUsersByConsignorId = function () { 26 27 consignorsService.getConsignorUsersByConsignorId($stateParams.consignorId).then(function (results) { 28 29 $scope.consignorUsers = results.data.consignorUsers; 30 31 //Now get the users based on the consignorUsers userIds 32 $scope.getConsignorUsers(); 33 34 }, function (error) { 35 popApiErrorMessage(error); 36 $scope.isSearchInProgress = false; 37 }); 38 }; 39 40 $scope.getConsignorUsers = function () { 41 42 $scope.isSearchInProgress = true; 43 44 $scope.checkIfFilterChanged(); 45 46 var deferred = $q.defer(); 47 48 var userIds = []; 49 $.each($scope.consignorUsers, function (index, item) { 50 userIds.push(item.userId); 51 }); 52 53 var filter = ""; 54 if ($scope.filter.length > 0) { 55 filter = '%' + $scope.filter + '%'; 56 } 57 58 usersService.getUsersByUserIds(userIds, filter, $scope.sortField, $scope.sortDirection, $scope.pageNumber, $scope.pageSize).then(function (results) { 59 60 $scope.adminUsers = results.data.users; 61 62 $scope.totalItems = results.data.totalRows[0].totalRows; 63 $scope.pageIsLoaded = true; 64 $scope.isSearchInProgress = false; 65 66 deferred.resolve(); 67 68 }, function (error) { 69 popApiErrorMessage(error); 70 $scope.isSearchInProgress = false; 71 deferred.resolve(); 72 }); 73 74 return deferred.promise; 75 }; 76 77 $scope.insertConsignorUser = function () { 78 79 var deferred = $q.defer(); 80 81 var userIds = []; 82 83 //See if we can find the user for the email address that was typed in 84 usersService.getUsers(userIds, $scope.consignorUserEmailToInsert, "Email", "ASC", 1, 2).then(function (userResults) { 85 86 if (userResults.data && userResults.data.users && userResults.data.users.length == 1) { 87 88 var user = userResults.data.users[0]; 89 var userRoles = user.roles.split(','); 90 var canAddConsignorPermissions = true; 91 92 $.each(userRoles, function (index, role) { 93 if (role.trim() == 'Super Admin' || role.trim() == 'Admin') { 94 canAddConsignorPermissions = false; 95 return false; 96 } 97 }); 98 99 if (canAddConsignorPermissions) { 100 //Insert the consignor User 101 consignorsService.insertConsignorUser($stateParams.consignorId, userResults.data.users[0].id).then(function (results) { 102 103 deferred.resolve(); 104 popMessage('success', 'Success', 'The user has been successfully added as a consignor admin.'); 105 $scope.isAddingConsignorUser = false; 106 $scope.consignorUserEmailToInsert = ""; 107 $scope.getConsignorUsersByConsignorId(); 108 109 }, function (error) { 110 popApiErrorMessage(error); 111 //$scope.isSearchInProgress = false; 112 deferred.resolve(); 113 }); 114 } else { 115 popMessage('warning', 'User already has permission', 'The user already has consignor admin rights and cannot be added.'); 116 deferred.resolve(); 117 } 118 119 } 120 else { 121 popMessage('error', 'Error', 'Unable to identify a user in the system with that email address.'); 122 deferred.resolve(); 123 } 124 125 }, function (error) { 126 popApiErrorMessage(error); 127 $scope.isSearchInProgress = false; 128 deferred.resolve(); 129 }); 130 131 return deferred.promise; 132 }; 133 134 $scope.removeConsignorAdminRights = function (adminUser) { 135 136 var deferred = $q.defer(); 137 138 // Remove the consignor user 139 consignorsService.deleteConsignorUser($stateParams.consignorId, adminUser.id).then(function (results) { 140 141 popMessage('success', 'Consignor Admin Removed', 'The user was successfully removed as a Consignor Admin'); 142 $scope.getConsignorUsersByConsignorId(); 143 144 }, function (error) { 145 popApiErrorMessage(error); 146 deferred.resolve(); 147 }); 148 149 return deferred.promise; 150 }; 151 152 153 154 /*********************************************************************************************************************** 155 156 Table sorting and paging methods 157 158 */ 159 160 $scope.setSort = function (newSortField) { 161 // If the sort field is the same 162 if (newSortField == $scope.sortField) { 163 // set the sort direction to opposite of what it currently is 164 $scope.sortDirection == 'ASC' ? $scope.sortDirection = 'DESC' : $scope.sortDirection = 'ASC'; 165 } else { 166 // Set the sort field as the new field and set the sort direction 167 $scope.sortField = newSortField; 168 $scope.sortDirection = 'ASC'; 169 } 170 171 // Set the values in the query string 172 $scope.setQueryStringSearchParams(); 173 174 // Re-get the data 175 $scope.getConsignorUsers(); // CUSTOM PER CONTROLLER 176 }; 177 178 $scope.pageResults = function (pagination) { 179 $scope.pageNumber = pagination.page; 180 181 // Set the values in the query string 182 $scope.setQueryStringSearchParams(); 183 184 // Re-get the data 185 $scope.getConsignorUsers(); // CUSTOM PER CONTROLLER 186 }; 187 188 $scope.pageSizeChange = function (newpageSize) { 189 $scope.pageSize = newpageSize; 190 191 if ($scope.pageNumber * $scope.pageSize > $scope.totalItems && $scope.totalItems > 0) {
192 $scope.pageNumber = Math.ceil($scope.totalItems / $scope.pageSize); 193 } 194 195 // Set the values in the query string 196 $scope.setQueryStringSearchParams(); 197 198 // Re-get the data 199 $scope.getConsignorUsers(); // CUSTOM PER CONTROLLER 200 }; 201 202 $scope.setQueryStringSearchParams = function () { 203 204 $location.search($scope.queryStringPrefix + "f", $scope.filter); // CUSTOM PER CONTROLLER 205 206 $location.search($scope.queryStringPrefix + "p", $scope.pageNumber); 207 $location.search($scope.queryStringPrefix + "ps", $scope.pageSize); 208 $location.search($scope.queryStringPrefix + "s", $scope.sortField); 209 $location.search($scope.queryStringPrefix + "sd", $scope.sortDirection); 210 }; 211 212 $scope.getQueryStringSearchParams = function () { 213 214 if (getParameterByName($scope.queryStringPrefix + "f").length > 0) // CUSTOM PER CONTROLLER 215 $scope.filter = getParameterByName($scope.queryStringPrefix + "f"); 216 217 if (getParameterByName($scope.queryStringPrefix + "p").length > 0) 218 $scope.pageNumber = Number(getParameterByName($scope.queryStringPrefix + "p")); 219 if (getParameterByName($scope.queryStringPrefix + "ps").length > 0) 220 $scope.pageSize = Number(getParameterByName($scope.queryStringPrefix + "ps")); 221 if (getParameterByName($scope.queryStringPrefix + "s").length > 0) 222 $scope.sortField = getParameterByName($scope.queryStringPrefix + "s"); 223 if (getParameterByName($scope.queryStringPrefix + "sd").length > 0) 224 $scope.sortDirection = getParameterByName($scope.queryStringPrefix + "sd"); 225 }; 226 227 $scope.checkIfFilterChanged = function () { 228 if ($scope.filterChanged) { 229 $scope.pageNumber = 1; 230 $scope.filterChanged = false; 231 } 232 }; 233 234 // Set the default variables 235 $scope.availablePageSizes = lists.availablePageSizes; 236 237 $scope.queryStringPrefix = 'acsau-'; // CUSTOM PER CONTROLLER 238 239 $scope.sortField = '[LastName]'; // CUSTOM PER CONTROLLER 240 $scope.sortDirection = 'ASC'; 241 $scope.pageNumber = 1; 242 $scope.pageSize = 10; 243 $scope.totalItems = 0; 244 245 $scope.isSearchInProgress = false; 246 $scope.filterChanged = false; 247 248 // Check to see if any values got passed in the query string 249 $scope.getQueryStringSearchParams(); 250 251 /* 252 253 End table sorting and paging methods 254 255 ***********************************************************************************************************************/ 256 257 //initialize variables 258 $scope.user = localStorageService.get('AuthData'); 259 260 $scope.pageIsLoaded = false; 261 262 //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation 263 $scope.canShowPageLoading = false; 264 $timeout(function () { $scope.canShowPageLoading = true; }, 1000); 265 266 267 $scope.consignorUsers = []; 268 $scope.adminUsers = []; 269 270 $scope.isAddingConsignorUser = false; 271 $scope.consignorUserEmailToInsert = ""; 272 273 $scope.filter = ''; 274 275 //initialize Page 276 $scope.initializePage(); 277 } 278]);
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.