1app.controller('adminShowInfoController', ['$scope', '$state', '$timeout', '$ngConfirm', '$q', 'localStorageService', 'permissionsService', 'authenticationService', 'showsService', 'lists', 'webApiSettings', 'adminCompanySettingsService', 'lookupService', 2 function ($scope, $state, $timeout, $ngConfirm, $q, localStorageService, permissionsService, authenticationService, showsService, lists, webApiSettings, adminCompanySettingsService, lookupService) { 3 4 $scope.initializePage = function() { 5 6 $scope.$parent.activeChildView = $state.current.name.replace('adminShow.', ''); 7 8 // Check to make sure they are logged in as a user 9 var requesteduserRightsRequested = { 10 roles: ['Super Admin', 'Admin'], 11 permissions: ['CanChangeAuctions'] 12 }; 13 14 permissionsService.isPermitted(requesteduserRightsRequested).then(function(results) { 15 if (!results.data) { 16 popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue."); 17 authenticationService.logout(); 18 $state.go('accountLogin'); 19 } else { 20 $scope.getCategoriesForFieldSelection(); 21 $scope.pageIsLoaded = true; 22 } 23 }, function(error) { 24 popApiErrorMessage(error); 25 }); 26 27 }; 28 29 $scope.isInRole = function (roleName) { 30 var roles = [] 31 32 if ($scope.user && $scope.user != null && $scope.user.roles && $scope.user.roles != null) { 33 roles = $scope.user.roles.split(','); 34 } 35 36 var foundRole = false; 37 38 $.each(roles, function (index, role) { 39 if ($.trim(roleName).toLowerCase() == $.trim(role).toLowerCase()) { 40 foundRole = true; 41 return false; 42 } 43 }); 44 45 return foundRole; 46 }; 47 48 $scope.hasPermission = function (permissionName) { 49 var permissions = [] 50 51 if ($scope.user && $scope.user != null && $scope.user.permissions && $scope.user.permissions != null) { 52 permissions = $scope.user.permissions; 53 } 54 55 var foundPermission = false; 56 57 $.each(permissions, function (index, permission) { 58 if ($.trim(permissionName).toLowerCase() == $.trim(permission).toLowerCase()) { 59 foundPermission = true; 60 return false; 61 } 62 }); 63 64 return foundPermission; 65 }; 66 67 68 $scope.formatDateAsUtc = function (dateToFormat) { 69 return formatDateOrDateStringAsUtcDate(dateToFormat); 70 }; 71 72 $scope.$parent.$watch('show.showId', function () { 73 $scope.isEditMode = $scope.$parent.show.showId < 0; 74 if ($scope.isEditMode) { 75 $scope.getTermsAndConditionsSetting(); 76 $scope.loadDropZone(); 77 } 78 if ($scope.$parent.show.selectedFieldsForEditing == null || $scope.$parent.show.selectedFieldsForEditing === '') { 79 $scope.$parent.show.selectedFieldsForEditing = []; 80 } else { 81 $scope.$parent.show.selectedFieldsForEditing = JSON.parse($scope.$parent.show.selectedFieldsForEditing); 82 } 83 }); 84 85 $scope.loadDropZone = function () { 86 var serviceBase = webApiSettings.serviceBaseUri; 87 88 if ($scope.user && $scope.user != null) { 89 try { 90 Dropzone.autoDiscover = false; 91 var fileUploadDropzone = new Dropzone( 92 "div#fileUploader", 93 { 94 url: serviceBase + "/api/v1/files/UploadImageJpeg", 95 acceptedFiles: "image/*", 96 dictDefaultMessage: "Click or drop image files here to upload.", 97 headers: { "Authorization": 'bearer ' + $scope.user.access_token } 98 }); 99 fileUploadDropzone.on("addedfile", function (file) { 100 if (this.files[1] != null) { 101 this.removeFile(this.files[0]); 102 } 103 }); 104 fileUploadDropzone.on("complete", function (data) { 105 $scope.$apply(function () { 106 $scope.$parent.show.bannerImageUrl = data.xhr.response; 107 }); 108 this.removeFile(this.files[0]); 109 }); 110 } catch (error) { 111 if (error.description != 'Dropzone already attached.' && error.message != 'Dropzone already attached.') { 112 popMessage("error", "Error", error.message); 113 } 114 } 115 } 116 117 $scope.pageIsLoaded = true; 118 }; 119 120 $scope.getTermsAndConditionsSetting = function () { 121 adminCompanySettingsService.getTermsAndConditions('AuctionDefaults').then(function (results) { 122 if (($scope.$parent.show.termsAndConditions == null || $scope.$parent.show.termsAndConditions.length == 0) 123 && (results.data.auctionCompanySettings != null && results.data.auctionCompanySettings.length > 0)) { 124 $scope.$parent.show.termsAndConditions = results.data.auctionCompanySettings[0].value; 125 } 126 $scope.pageIsLoaded = true; 127 }, function (error) { 128 popApiErrorMessage(error); 129 }); 130 }; 131 132 $scope.editShow = function () { 133 134 // Set temp variables that are used for editing 135 $scope.tempShow = angular.copy($scope.$parent.show); 136 137 $scope.$parent.show.startDateTime = $scope.formatDateAsUtc($scope.$parent.show.startDateTime); 138 $scope.$parent.show.endDateTime = $scope.formatDateAsUtc($scope.$parent.show.endDateTime); 139 $scope.$parent.show.onlineRegistrationCloseDateTime = $scope.formatDateAsUtc($scope.$parent.show.onlineRegistrationCloseDateTime); 140 $scope.$parent.show.editingOnSelectedFieldsCloseDateTime = $scope.formatDateAsUtc($scope.$parent.show.editingOnSelectedFieldsCloseDateTime); 141 142 // Set up the page for editing 143 $scope.isEditMode = true; 144 $scope.loadDropZone(); 145 }; 146
147 $scope.saveShow = function () { 148 149 // Set the deffered promise for the button to disable 150 var deferred = $q.defer(); 151 152 // Validate the form 153 if (!$scope.upsertForm.$valid) { 154 // Make sure that the form field highlight if nothing is filled out. 155 $scope.$broadcast('show-errors-check-validity'); 156 157 popMessage("error", "Error", 'All required fields must be filled.'); 158 159 // Resolve the promise 160 deferred.resolve(); 161 162 // Return the promise so the button will activate again 163 return deferred.promise; 164 } 165 166 showsService.upsertShow($scope.$parent.show).then(function (results) { 167 168 popMessage("success", "Show Saved Successfully", "The Show has been added successfully."); 169 170 $scope.isEditMode = false; 171 172 $state.go('adminShow.showInfo', { "showId": results.data.results[0].code }, { reload: true }); 173 174 // Resolve the promise 175 deferred.resolve(); 176 177 }, function (error) { 178 // Pop up an error 179 popApiErrorMessage(error); 180 // Resolve the promise 181 deferred.resolve(); 182 }); 183 184 // Return the promise so the button will activate again 185 return deferred.promise; 186 }; 187 188 $scope.cancelSaveShow = function () { 189 if ($scope.$parent.show.showId < 0) { 190 // Reset the edit mode 191 $scope.isEditMode = false; 192 // Go back to the show list since this was an add new 193 $scope.$back(); 194 } else { 195 // set the auction back to the temp auction 196 $scope.$parent.show = angular.copy($scope.tempShow); 197 // Reset the edit mode 198 $scope.isEditMode = false; 199 } 200 }; 201 202 $scope.uploadAnotherBanner = function () { 203 $scope.$parent.show.bannerImageUrl = ''; 204 }; 205 206 /******************************************************************************* 207 * Date Range Functions 208 * This is for the Date Time Pickers so the start date doesn't 209 * come after the end date and the end date doesn't come before 210 * the start date. 211 */ 212 213 $scope.startDateOnSetTime = function () { 214 // Broadcast that a change has been made so the end date time can re render the active dates 215 $scope.$broadcast('start-date-changed'); 216 // Make sure that the form field highlight if nothing is filled out. 217 $('[name="startDateTime"]').focus(); 218 $('[name="startDateTime"]').blur(); 219 }; 220 221 $scope.endDateOnSetTime = function () { 222 // Broadcast that a change has been made so the start date time can re render the active dates 223 $scope.$broadcast('end-date-changed'); 224 // Make sure that the form field highlight if nothing is filled out. 225 $('[name="endDateTime"]').focus(); 226 $('[name="endDateTime"]').blur(); 227 }; 228 229 $scope.startDateBeforeRender = function ($dates) { 230 // Check to see if there is an end date and the auction type is not live 231 if ($scope.$parent.show.endDateTime) { 232 // Set the active date as the end date time 233 var activeDate = moment($scope.$parent.show.endDateTime); 234 // Create a filter that doesn't allow dates after the active date to be selectable 235 $dates.filter(function (date) { 236 return date.localDateValue() >= activeDate.valueOf() 237 }
237).forEach(function (date) { 238 date.selectable = false; 239 }) 240 } 241 }; 242 243 $scope.endDateBeforeRender = function ($view, $dates) { 244 // Check to see if there is a start date 245 if ($scope.$parent.show.startDateTime) { 246 // Set the active date as the start date time 247 var activeDate = moment($scope.$parent.show.startDateTime).subtract(1, $view).add(1, 'minute'); 248 // Create a filter that doesn't allow dates before the active date to be selectable 249 $dates.filter(function (date) { 250 return date.localDateValue() <= activeDate.valueOf() 251 }).forEach(function (date) { 252 date.selectable = false; 253 }) 254 } 255 }; 256 257 $scope.registrationEndDateOnSetTime = function () { 258 // Broadcast that a change has been made 259 $scope.$broadcast('registration-end-date-changed'); 260 // Make sure that the form field highlight if nothing is filled out. 261 $('[name="onlineRegistrationCloseDateTime"]').focus(); 262 $('[name="onlineRegistrationCloseDateTime"]').blur(); 263 }; 264 265 $scope.registrationEndDateBeforeRender = function ($dates) { 266 // Check to see if there is a start date 267 if ($scope.$parent.show.startDateTime) { 268 // Set the active date as the start date time 269 var activeDate = moment($scope.$parent.show.startDateTime); 270 // Create a filter that doesn't allow dates after the active date to be selectable 271 $dates.filter(function (date) { 272 return date.localDateValue() >= activeDate.valueOf() 273 }
273).forEach(function (date) { 274 date.selectable = false; 275 }) 276 } 277 }; 278 279 $scope.editingOnSelectedFieldsCloseDateTimeOnSetTime = function () { 280 // Make sure that the form field highlight if nothing is filled out. 281 $('[name="editingOnSelectedFieldsCloseDateTime"]').focus(); 282 $('[name="editingOnSelectedFieldsCloseDateTime"]').blur(); 283 }; 284 285 $scope.editingOnSelectedFieldsCloseDateTimeBeforeRender = function ($dates) { 286 // Check to see if there is a start date 287 if ($scope.$parent.show.endDateTime) { 288 // Set the active date as the start date time 289 var activeDate = moment($scope.$parent.show.endDateTime); 290 var registrationEndDate = moment($scope.$parent.show.onlineRegistrationCloseDateTime); 291 // Create a filter that doesn't allow dates after the active date to be selectable 292 $dates.filter(function (date) { 293 return date.localDateValue() <= registrationEndDate.valueOf() || date.localDateValue() >= activeDate.valueOf(); 294 }
294).forEach(function (date) { 295 date.selectable = false; 296 }) 297 } 298 }; 299 300 /* 301 * End Date Range Functions 302 *******************************************************************************/ 303 304 $scope.allowOnlineRegistrationChanged = function () { 305 if ($scope.$parent.show.allowOnlineRegistration) { 306 $scope.$parent.show.onlineRegistrationCloseDateTime = $scope.$parent.show.startDateTime; 307 } else { 308 $scope.$parent.show.onlineRegistrationCloseDateTime = null; 309 } 310 }; 311 312 $scope.allowOnlineRegistrationOption = function (item) { 313 // if the allow users to register themselves option 314 if (item == true) { 315 // Check the setting to see if it needs to be disabled 316 if (!$scope.settings.environment.allowShowsSelfRegistration || $scope.settings.environment.allowShowsSelfRegistration == '' || $scope.settings.environment.allowShowsSelfRegistration == "False") { 317 return true; 318 } else { 319 return false; 320 } 321 } else { 322 // Always allow users to not register themselves option and don't disable it 323 return false; 324 } 325 }; 326 327 $scope.excludeSelectedCategories = function () { 328 // Mark all categories as excluded for starting 329 var temp = []; 330 $.each($scope.allCategoriesWithFields, function (categoryIndex, categoryItem) { 331 temp.push(angular.copy(categoryItem.categoryId)); 332 }); 333 334 $scope.$parent.show.showCategoryTags.filter(function (tag) { 335 return tag.isSelected === 1; 336 }).map(function (tag) { 337 var indexToRemove = -1; 338 $.each(temp, function (categoryIndex, categoryItem) { 339 if (categoryItem == tag.categoryId) { 340 indexToRemove = categoryIndex; 341 } 342 }); 343 if (indexToRemove >= 0) { 344 temp.splice(indexToRemove, 1); 345 } 346 }); 347 return temp; 348 }; 349 350 $scope.$watch('show.showCategoryTags', function () { 351 if ($scope.allCategoriesWithFields.length > 0) { 352 $scope.categoriesForFieldSelection = angular.copy($scope.allCategoriesWithFields); 353 $scope.categoryIdsToExclude = $scope.excludeSelectedCategories(); 354 } 355 }, true); 356 357 $scope.getCategoriesForFieldSelection = function () { 358 adminCompanySettingsService.getCategories($scope.showId).then(function (results) { 359 if (results.data.categories.length > 0) { 360 // Set the categories 361 $scope.allCategoriesWithFields = results.data.categories; 362 $scope.categoriesForFieldSelection = angular.copy($scope.allCategoriesWithFields); 363 $scope.categoryIdsToExclude = $scope.excludeSelectedCategories(); 364 365 } else { 366 // Show that no categories are found 367 popMessage("error", "Not Found", "No categories found."); 368 } 369 }, function (error) { 370 popApiErrorMessage(error); 371 }); 372 }; 373 374 //initialize variables 375 $scope.user = localStorageService.get('AuthData'); 376 $scope.pageIsLoaded = false; 377 $scope.isEditMode = false; 378 379 $scope.tempShow = {}; 380 $scope.setting = {}; 381 382 $scope.states = lists.states; 383 384 385 //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation 386 $scope.canShowPageLoading = false; 387 $timeout(function() { $scope.canShowPageLoading = true; }, 1000); 388 389 $scope.user = localStorageService.get('AuthData'); 390 $scope.settings = lookupService.settings; 391 392 393 $scope.allCategoriesWithFields = []; 394 $scope.categoriesForFieldSelection = []; 395 $scope.categoryIdsToExclude = []; 396 $scope.categoryFieldTypesToExclude = [0]; 397 $scope.selectCategoryFields = []; 398 399 400 //initialize Page 401 $scope.initializePage(); 402 } 403]);
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.