PageSourceSearch

https://wlivestock.com/app/views/admin/auctions/adminAuctionInfoController.js?v=buster20250808

js wlivestock.com collected 2026-10-04 06:05:52 UTC 27,554 bytes, 590 lines download raw bytes

1app.controller('adminAuctionInfoController', ['$scope', '$state', '$timeout', '$ngConfirm', '$q', 'localStorageService', 'permissionsService', 'authenticationService', 'auctionsService', 'lists', 'webApiSettings', 'adminCompanySettingsService', 'lookupService',
2    function ($scope, $state, $timeout, $ngConfirm, $q, localStorageService, permissionsService, authenticationService, auctionsService, lists, webApiSettings, adminCompanySettingsService, lookupService) {
3
4        $scope.initializePage = function() {
5
6            if ($scope.isInRole('Consignor') && !$scope.isInRole('Admin')) {
7                auctionsService.getAuctionAdminAccessBySale($scope.auctionId).then(function (results) {
8                    if (results.data.access[0].hasAccess) {
9                        $scope.user.roles += ',Admin';
10                    }
11                    $scope.initialize();
12                }, function (error) {                    
13                    popApiErrorMessage(error);
14                });
15            }
16            else {
17                $scope.initialize();
18            }
19        };
20
21        $scope.initialize = function () {
22            $scope.$parent.activeChildView = $state.current.name.replace('adminAuction.', '');
23
24            // Check to make sure they are logged in as a user
25            var requesteduserRightsRequested = {
26                roles: ['Super Admin', 'Admin', 'Consignor'],
27                permissions: ['CanChangeAuctions']
28            };
29
30            permissionsService.isPermitted(requesteduserRightsRequested).then(function (results) {
31                if (!results.data) {
32                    popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue.");
33                    authenticationService.logout();
34                    $state.go('accountLogin');
35                } else {                    
36                    $scope.pageIsLoaded = true;
37                }
38            }, function (error) {
39                popApiErrorMessage(error);
40            });
41
42            $scope.checkAuctionTypes();
43        }
44
45        var checkAuctionTypesCounter = 0;
46
47        $scope.checkAuctionTypes = function () {
48            checkAuctionTypesCounter++;
49            if ($scope.settings.environment.tenantId != null) {
50                // Loop through the auction types and check the environment vars to make sure they have access to them
51                $.each($scope.auctionTypes, function (index, item) {
52                    if (item.environmentKey.length > 0) {
53                        item.active = $scope.settings.environment[item.environmentKey] == 'True';
54                    } else {
55                        item.active = true;
56                    }
57                });
58            } else {
59                if (checkAuctionTypesCounter < 5) {
60                    $timeout(function () { $scope.checkAuctionTypes(); }, 500);
61                } else {
62                    // Just add the ones that don't require an envirnoment key (fail safe)
63                    $.each($scope.auctionTypes, function (index, item) {
64                        if (item.environmentKey.length > 0) {
65                            item.active = false;
66                        } else {
67                            item.active = true;
68                        }
69                    });
70                }
71            }
72        };
73
74        $scope.editAuction = function () {
75
76            // Set temp variables that are used for editing
77            $scope.tempAuction = angular.copy($scope.$parent.auction);
78            $scope.$parent.auction.highWaterMarkExtensionInMinutes = $scope.$parent.auction.highWaterMarkExtensionInSeconds / 60;
79            $scope.$parent.auction.buyersPremiumPercentage = $scope.$parent.auction.buyersPremium * 100;
80            $scope.$parent.auction.liveAuctionFloorBuyersPremiumPercentage = $scope.$parent.auction.liveAuctionFloorBuyersPremium * 100;
81
82            if ($scope.$parent.auction.auctionCompanyQuestionsId == null || $scope.$parent.auction.auctionCompanyQuestionsId.length == 0) {
83                $scope.$parent.auction.auctionCompanyQuestionsId = -1;
84            }
85            
86
87            $scope.$parent.auction.startDateTime = $scope.formatDateAsUtc($scope.$parent.auction.startDateTime);
88            $scope.$parent.auction.endDateTime = $scope.formatDateAsUtc($scope.$parent.auction.endDateTime);
89
90            // Set up the page for editing
91            $scope.isEditMode = true;
92            $scope.loadDropZone();
93        };
94
95        $scope.formatDateAsUtc = function (dateToFormat) {
96            return formatDateOrDateStringAsUtcDate(dateToFormat);
97        };
98
99        $scope.saveAuction = function () {
100
101            // Set the deffered promise for the button to disable
102            var deferred = $q.defer();
103
104
105            if ($scope.$parent.auction.consignors.length == 0) {
106                // Pop a message that a consignor needs to be selected
107                popMessage("error", "Error", 'Please select a consignor.');
108                // Resolve the promise
109                deferred.resolve();
110                // Return the promise so the button will activate again
111                return deferred.promise;
112            }
113
114            if ($scope.settings.environment.auctionTagsEnabled == 'True') {
115                //Check to see if the tags are required and make sure there are not more than allowed
116                if ($scope.settings.environment.auctionTagsRequiredPerAuction == 'True' && $scope.$parent.auction.auctionTags.length == 0) {
117                    // Pop a message that a consignor needs to be selected
118                    popMessage("error", "Error", 'Please select an auction tag.');
119                    // Resolve the promise
120                    deferred.resolve();
121                    // Return the promise so the button will activate again
122                    return deferred.promise;
123                }
124
125                if ($scope.settings.environment.auctionTagsRequiredPerAuction == 'True' && $scope.$parent.auction.auctionTags.length > $scope.settings.environment.auctionTagsMaxPerAuction) {
126                    // Pop a message that a consignor needs to be selected
127                    popMessage("error", "Error", 'Only ' + $scope.settings.environment.auctionTagsMaxPerAuction + ' auctions tag(s) are allowed');
128                    // Resolve the promise
129                    deferred.resolve();
130                    // Return the promise so the button will activate again
131                    return deferred.promise;
132                }
133                
134            }
135
136            
137
138            //else {
139            //    // If the auction has auction items (it is an update)
140            //    if ($scope.$parent.auction.auctionItems.length > 0) {
141            //        // Get all the consignors with active auction items
142            //        $.each($scope.$parent.auction.auctionItems, function (index, item) {
143
144            //        });
145            //    }
146            //    $.each($scope.$parent.auction.consignors, function (index, selectedConsignor) {
147                    
148            //    });
149            //}
150
151            // Validate the form
152            if (!$scope.upsertForm.$valid) {
153                // Make sure that the form field highlight if nothing is filled out.
154                $scope.$broadcast('show-errors-check-validity');
155
156                popMessage("error", "Error", 'All required fields must be filled.');
157
158                // Resolve the promise
159                deferred.resolve();
160
161                // Return the promise so the button will activate again
162                return deferred.promise;
163            }
164
165            //PZ - If it's a live or timed auction, we'll just make the end date far out into the future.
166            //The timers won't count down for these auction types anyway, and we'll set the end date to "now" once
167            //the administrator ends the auction.
168            if ($scope.$parent.auction.auctionType == 'liveAuction' || $scope.$parent.auction.auctionType == 'timedAuction') {
169                $scope.$parent.auction.endDateTime = moment($scope.$parent.auction.startDateTime).add(365 * 5, 'days');
170            }
171
172            if ($scope.$parent.auction.auctionCompanyQuestionsId == -1) {
173                $scope.$parent.auction.auctionCompanyQuestionsId = null;
174            }
175
176            auctionsService.upsertAuction($scope.$parent.auction).then(function (results) {
177
178                var auctionId = results.data.results[0].code;
179
180                //save any selected auction tags
181                auctionsService.upsertAuctionTagsAuctions({ auctionId: auctionId, auctionTags: $scope.$parent.auction.auctionTags }).then(function (results) {
182                    //saved
183                    popMessage("success", "Auction Saved Successfully", "The auction has been added successfully.");
184
185                    $scope.isEditMode = false;
186
187                    $state.go('adminAuction.auctionInfo', { "auctionId": results.data.results[0].c
187ode }, { reload: true });
188
189                    // Resolve the promise
190                    deferred.resolve();
191                }, function (error) {
192                    popApiErrorMessage(error);
193                    deferred.resolve();
194                });
195
196                
197
198            }, function (error) {
199                // Pop up an error
200                popApiErrorMessage(error);
201                // Resolve the promise
202                deferred.resolve();
203            });
204
205            // Return the promise so the button will activate again
206            return deferred.promise;
207        };
208
209        $scope.cancelSaveAuction = function () {
210            if ($scope.$parent.auction.auctionId < 0) {
211                // Reset the edit mode
212                $scope.isEditMode = false;
213                // Go back to the auction list since this was an add new
214                $scope.$back();
215            } else {
216                // set the auction back to the temp auction
217                $scope.$parent.auction = angular.copy($scope.tempAuction);
218                // Reset the edit mode
219                $scope.isEditMode = false;
220            }
221        };
222
223        $scope.uploadAnotherBanner = function () {
224            $scope.$parent.auction.bannerImageUrl = '';
225        };
226
227        $scope.loadDropZone = function () {
228            var serviceBase = webApiSettings.serviceBaseUri;
229
230            if ($scope.user && $scope.user != null) {
231                try {
232                    Dropzone.autoDiscover = false;
233                    var fileUploadDropzone = new Dropzone(
234                        "div#fileUploader",
235                        {
236                            url: serviceBase + "/api/v1/files/UploadImageJpeg",
237                            acceptedFiles: "image/*",
238                            dictDefaultMessage: "Click or drop image files here to upload.",
239                            headers: { "Authorization": 'bearer ' + $scope.user.access_token }
240                        });
241                    fileUploadDropzone.on("addedfile", function (file) {
242                        if (this.files[1] != null) {
243                            this.removeFile(this.files[0]);
244                        }
245                    });
246                    fileUploadDropzone.on("complete", function (data) {
247                        $scope.$apply(function () {
248                            $scope.$parent.auction.bannerImageUrl = data.xhr.response;
249                            //$scope.$parent.auction.bannerImageUrl = $scope.$parent.auction.bannerImageUrl.replace(/_lg_/i, '_sm_');
250                        });
251                        this.removeFile(this.files[0]);
252                    });
253                } catch (error) {
254                    if (error.description != 'Dropzone already attached.' && error.message != 'Dropzone already attached.') {
255                        popMessage("error", "Error", error.message);
256                    }
257                }
258            }
259
260            $scope.pageIsLoaded = true;
261        };
262
263        $scope.populateHighWaterMarkExtensionInSeconds = function () {
264            // Check to see if there is a high water mark in minutes (field added to the auction that is used for display purposes)
265            if ($scope.$parent.auction.highWaterMarkExtensionInMinutes != null) {
266                // Set the high water mark in seconds to the high water mark in minutes * 60
267                $scope.$parent.auction.highWaterMarkExtensionInSeconds = $scope.$parent.auction.highWaterMarkExtensionInMinutes * 60;
268            } else {
269                // Since it doesn't exist, just set it to zero
270                $scope.$parent.auction.highWaterMarkExtensionInSeconds = 0;
271                $scope.$parent.auction.highWaterMarkExtensionInMinutes = 0;
272            }
273        };
274
275        $scope.populateBuyersPremiumDecimal = function () {
276            // Check to see if there is a buyers premium percentage (field added to the auction that is used for display purposes)
277            if ($scope.$parent.auction.buyersPremiumPercentage != null) {
278                // Check to see if it is 0
279                if ($scope.$parent.auction.buyersPremiumPercentage == 0) {
280                    // Set the auctions buyers premium to 0
281                    $scope.$parent.auction.buyersPremium = 0;
282                } else {
283                    // Set the buyers premium to the percentage / 100
284                    $scope.$parent.auction.buyersPremium = $scope.$parent.auction.buyersPremiumPercentage / 100;
285                }
286            } else {
287                // Since it doesn't exist, just set it to zero
288                $scope.$parent.auction.buyersPremium = 0;
289                $scope.$parent.auction.buyersPremiumPercentage = 0;
290            }
291        };
292
293        $scope.populateFloorBuyersPremiumDecimal = function () {
294            // Check to see if there is a floor buyers premium percentage (field added to the auction that is used for display purposes)
295            if ($scope.$parent.auction.liveAuctionFloorBuyersPremiumPercentage != null) {
296                // Check to see if it is 0
297                if ($scope.$parent.auction.liveAuctionFloorBuyersPremiumPercentage == 0) {
298                    // Set the auctions buyers premium to 0
299                    $scope.$parent.auction.liveAuctionFloorBuyersPremium = 0;
300                } else {
301                    // Set the buyers premium to the percentage / 100
302                    $scope.$parent.auction.liveAuctionFloorBuyersPremium = $scope.$parent.auction.liveAuctionFloorBuyersPremiumPercentage / 100;
303                }
304            } else {
305                // Since it doesn't exist, just set it to zero
306                $scope.$parent.auction.liveAuctionFloorBuyersPremium = 0;
307                $scope.$parent.auction.liveAuctionFloorBuyersPremiumPercentage = 0;
308            }
309
310        };
311
312        //YouTube Streaming Video
313        $scope.editAuctionStreamYouTube = function () {
314            $scope.youTubeVideoId = null;
315            //Popup and prompt for YouTube Video
316            $ngConfirm({
317                closeIcon: false,
318                title: 'Enter YouTube Video Id',
319                icon: 'fa fa-camera text-primary',
320                content:  'What is the YouTube Video Id?<br />' +
321                '<input type="text" class="form-control" name="youTubeVideoId" ng-model="youTubeVideoId" placeholder="ID" />'  ,
322                scope: $scope,
323                buttons: {
324                    confirm: {
325                        text: 'Save YouTube Video Id',
326                        btnClass: 'btn-primary',
327                        action: function (buttonScope, button) {
328
329                            // Validate the form
330                            if ($scope.youTubeVideoId == null || $scope.youTubeVideoId.length < 1) {
331                                // Make sure that the form field highlight if nothing is filled out.
332                               // $scope.$broadcast('show-errors-check-validity');
333
334                                popMessage("error", "Error", 'All required fields must be filled.');
335
336                                // Resolve the promise
337                                return false;
338                            }
339
340                      
341                         
342                            $scope.$apply(function () {
343                                //Set the output from the YouTube Capture
344                                $scope.$parent.auction.liveAuctionBroadcastServer = 'rtmp://a.rtmp.youtube.com/live2'; //Default server for YouTube
345                                $scope.$parent.auction.liveAuctionStreamingType = 'YouTube';
346                                $scope.$parent.auction.liveAuctionStreamingId = $scope.youTubeVideoId;
347                            });
348                        }
349                    },
350                    cancel: {
351                        text: 'Cancel',
352                        btnClass: 'btn-warning',
353                        action: function (buttonScope, button) {
354                            // Reset the variable back to the orginal
355                            $scope.youTubeVideoId = null;
356                        }
357                    }
358                }
359            });
360
361        };
362
363        //Phenix Streaming Video
364        $scope.editAuctionStreamPhenix = function () {
365            $scope.phenixVideoId = null;
366            //Popup and prompt for Phenix Video
367            $ngConfirm({
368                closeIcon: false,
369                title: 'Enter Phenix Video Id',
370                icon: 'fa fa-camera text-primary',
371                content: 'What is the Phenix Stream Key?<br />' +
372                    '<input type="text" class="form-control" name="phenixStreamKey" ng-model="phenixStreamKey" placeholder="ID" />',
373                scope: $scope,
374                buttons: {
375                    confirm: {
376                        text: 'Save Phenix Stream Key',
377                        btnClass: 'btn-primary',
378                        action: function (buttonScope, button) {
379
380                            // Validate the form
381                            if ($scope.phenixStreamKey == null || $scope.phenixStreamKey.length < 1) {
382                                // Make sure that the form field highlight if nothing is filled out.
383                                // $scope.$broadcast('show-errors-check-validity');
384
385                                popMessage("error", "Error", 'All required fields must be filled.');
386
387                                // Resolve the promise
388                                return false;
389                            }
390
391
392
393                            $scope.$apply(function () {
394                                //Set the output from the Phenix Capture
395                                $scope.$parent.auction.liveAuctionBroadcastServer = 'https://phenixrts.com/docs/api/?http#rtmp-ingest'; //Default server for Phenix
396                                $scope.$parent.auction.liveAuctionStreamingType = 'Phenix';
397                                $scope.$parent.auction.liveAuctionStreamingId = $scope.phenixStreamKey;
398                            });
399                        }
400                    },
401                    cancel: {
402                        text: 'Cancel',
403                        btnClass: 'btn-warning',
404                        action: function (buttonScope, button) {
405                            // Reset the variable back to the orginal
406                            $scope.phenixStreamKey = null;
407                        }
408                    }
409                }
410            });
411
412        };
413
414        $scope.editAuctionStreamW2 = function () {
415            //Set the output from the YouTube Capture
416            $scope.$parent.auction.liveAuctionBroadcastServer = '[Pending Setup]';
417            $scope.$parent.auction.LiveAuctionStreamingType = 'W2';
418            $scope.$parent.auction.liveAuctionStreamingId = '[Pending Setup]';
419        };
420
421        //initialize variables
422        $scope.user = localStorageService.get('AuthData');
423        $scope.pageIsLoaded = false;
424
425        $scope.$parent.$watch('auction.auctionId', function() {
426            $scope.isEditMode = $scope.$parent.auction.auctionId < 0;
427            if ($scope.isEditMode) {
428                $scope.getTermsAndConditionsSetting();
429                $scope.getAuctionCompanyQuestions();
430                $scope.loadDropZone();
431            }
432        });
433
434        $scope.getTermsAndConditionsSetting = function () {
435            adminCompanySettingsService.getTermsAndConditions('AuctionDefaults').then(function (results) {
436                if (($scope.$parent.auction.termsAndConditions == null || $scope.$parent.auction.termsAndConditions.length == 0)
437                    && (results.data.auctionCompanySettings != null && results.data.auctionCompanySettings.length > 0)) {
438                    $scope.$parent.auction.termsAndConditions = results.data.auctionCompanySettings[0].value;
439                }
440                $scope.pageIsLoaded = true;
441            }, function (error) {
442                popApiErrorMessage(error);
443            });
444        };
445
446        $scope.getAuctionCompanyQuestions = function () {
447            adminCompanySettingsService.getAuctionCompanyQuestions().then(function (results) {
448                if (results.data.auctionCompanyQuestions && results.data.auctionCompanyQuestions.length > 0) {
449                    $scope.auctionCompanyQuestions = results.data.auctionCompanyQuestions;
450                }
451                var noQuestions = { auctionCompanyQuestionsId: -1, name: 'No Questions'};
452                $scope.auctionCompanyQuestions.unshift(noQuestions);
453                $scope.pageIsLoaded = true;
454            }, function (error) {
455                popApiErrorMessage(error);
456            });
457        };
458
459        $scope.isInRole = function (roleName) {
460            var roles = []
461
462            if ($scope.user && $scope.user != null && $scope.user.roles && $scope.user.roles != null) {
463                roles = $scope.user.roles.split(',');
464            }
465
466            var foundRole = false;
467
468            $.each(roles, function (index, role) {
469                if ($.trim(roleName).toLowerCase() == $.trim(role).toLowerCase()) {
470                    foundRole = true;
471                    return false;
472                }
473            });
474
475            return foundRole;
476        };
477
478        $scope.hasPermission = function (permissionName) {
479            var permissions = []
480
481            if ($scope.user && $scope.user != null && $scope.user.permissions && $scope.user.permissions != null) {
482                permissions = $scope.user.permissions;
483            }
484
485            var foundPermission = false;
486
487            $.each(permissions, function (index, permission) {
488                if ($.trim(permissionName).toLowerCase() == $.trim(permission).toLowerCase()) {
489                    foundPermission = true;
490                    return false;
491                }
492            });
493
494            return foundPermission;
495        };
496
497        $scope.getAuctionTypeText = function (auctionTypeId) {
498            return getConstantsListTextById(lists.auctionTypes, auctionTypeId);
499        };
500
501        /*******************************************************************************
502        *     Date Range Functions
503        *     This is for the Date Time Pickers so the start date doesn't
504        *     come after the end date and the end date doesn't come before
505        *     the start date.
506        */
507
508        $scope.startDateOnSetTime = function () {
509            // Broadcast that a change has been made so the end date time can re render the active dates
510            $scope.$broadcast('start-date-changed');
511            // Make sure that the form field highlight if nothing is filled out.
512            $('[name="startDateTime"]').focus();
513            $('[name="startDateTime"]').blur();
514        };
515
516        $scope.endDateOnSetTime = function () {
517            // Broadcast that a change has been made so the start date time can re render the active dates
518            $scope.$broadcast('end-date-changed');
519            // Make sure that the form field highlight if nothing is filled out.
520            $('[name="endDateTime"]').focus();
521            $('[name="endDateTime"]').blur();
522        };
523
524        $scope.startDateBeforeRender = function ($dates) {
525            // Check to see if there is an end date and the auction type is not live
526            if ($scope.$parent.auction.endDateTime && $scope.$parent.auction.auctionType != 'liveAuction') {
527                // Set the active date as the end date time
528                var activeDate = moment($scope.$parent.auction.endDateTime);
529                // Create a filter that doesn't allow dates after the active date to be selectable
530                $dates.filter(function (date) {
531                    return date.localDateValue() >= activeDate.valueOf()
532                }
532).forEach(function (date) {
533                    date.selectable = false;
534                })
535            }
536        };
537
538        $scope.endDateBeforeRender = function ($view, $dates) {
539            // Check to see if there is a start date
540            if ($scope.$parent.auction.startDateTime) {
541                // Set the active date as the start date time
542                var activeDate = moment($scope.$parent.auction.startDateTime).subtract(1, $view).add(1, 'minute');
543                // Create a filter that doesn't allow dates before the active date to be selectable
544                $dates.filter(function (date) {
545                    return date.localDateValue() <= activeDate.valueOf()
546                }).forEach(function (date) {
547                    date.selectable = false;
548                })
549            }
550        };
551
552        /*
553        *    End Date Range Functions
554        *******************************************************************************/
555
556        $scope.populateAuctionContactInformationFromConsignor = function (consignor) {
557            $scope.$parent.auction.phoneNumber = consignor.phoneNumber;
558            $scope.$parent.auction.address1 = consignor.address1;
559            $scope.$parent.auction.address2 = consignor.address2;
560            $scope.$parent.auction.city = consignor.city;
561            $scope.$parent.auction.state = consignor.state;
562            $scope.$parent.auction.postalCode = consignor.postalCode;
563        };
564
565        $scope.tempAuction = {};
566        $scope.setting = {};
567
568     
569        
570
571        $scope.states = lists.states;
572
573        $scope.auctionTypes = lists.auctionTypes;
574
575        $scope.auctionCompanyQuestions = [];
576
577        //$scope.consignors = [];
578
579        //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation
580        $scope.canShowPageLoading = false;
581        $timeout(function() { $scope.canShowPageLoading = true; }, 1000);
582
583        $scope.user = localStorageService.get('AuthData');
584
585        //$scope.settings = lookupService.settings;
586
587        //initialize Page
588        $scope.initializePage();
589    }
590]);

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.