1app.directive('bidding', function () { 2 return { 3 templateUrl: 'app/directives/bidding.html', 4 restrict: 'EA', 5 scope: { 6 auctionIsOpen: '=', 7 auctionItem: '=', 8 user: '=', 9 showMessage: '=', 10 hasBidOnAuction: '=', 11 auctionTermsAndConditions: '=', 12 auctionQuestions: '=', 13 liveAuctionAcceptingPreBidOffers: '=' 14 }, 15 controller: 'biddingController', 16 controllerAs: 'vm', 17 bindToController: true 18 } 19}); 20 21 22app.controller('biddingController', ['$scope', '$rootScope', '$timeout', '$state', '$q', '$ngConfirm', 'auctionsService', 'bidsService', 'lookupService', 23 function ($scope, $rootScope, $timeout, $state, $q, $ngConfirm, auctionsService, bidsService, lookupService) { 24 var vm = this; 25 26 $scope.$watch('vm.auctionItem', function (newValue, oldValue) { 27 if (vm.auctionItem.winningBidInformation != null) { 28 vm.bid.auctionId = vm.auctionItem.auctionId; 29 vm.bid.auctionItemId = vm.auctionItem.auctionItemId; 30 vm.bid.bidAmount = vm.auctionItem.winningBidInformation[0].nextBidAmount; 31
32 vm.auctionItem.bidMessage = getAuctionItemBidMessage(vm.user, vm.auctionItem, vm.settings); 33 34 $scope.$on('a-' + vm.auctionItem.auctionId + '-ai-' + vm.auctionItem.auctionItemId + '-winningbidinformation-changed', function (event, result) { 35 if (vm.auctionItem.auctionItemId == result.auctionItemId) { 36 vm.bid.bidAmount = vm.auctionItem.winningBidInformation[0].nextBidAmount; 37 38 if (vm.bidConfirmationModalOpen) { 39 $scope.bidPlacedWhileConfirmationModalIsOpen = true; 40 vm.bidConfirmationModal.buttons.confirm.setShow(false); 41 } 42 43 } 44 }); 45 46 } 47 }); 48 49 $scope.$watch('vm.hasBidOnAuction', function (newValue, oldValue) { 50 if (vm.hasBidOnAuction) { 51 vm.bid.agreeToTermsAndConditions = true; 52 } 53 }); 54 55 56 57 $scope.$watch('vm.user', function (newValue, oldValue) { 58 vm.isLoggedIn = vm.user != null; 59 60 if (vm.isLoggedIn) { 61 vm.bid.userId = vm.user.id; 62 vm.bid.phoneVerified = vm.user.phoneConfirmed == 'True' || vm.user.isAllowedToBidWithoutPhoneNumberVerification == 'True'; 63 } 64 65 }); 66 67 vm.placeBidWithConfirmation = function (isBuyItNow) { 68 69 // Set the deffered promise for the button to disable 70 var deferred = $q.defer(); 71 72 if (vm.bid.agreeToTermsAndConditions == null || vm.bid.agreeToTermsAndConditions == false) { 73 74 vm.popTermsAndConditions(isBuyItNow, true); 75 76 deferred.resolve(); 77 return deferred.promise; 78 79 } 80 81 // Validate the form 82 if (!$scope.bidForm.$valid) { 83 // Make sure that the form field highlight if nothing is filled out. 84 $scope.$broadcast('show-errors-check-validity'); 85 86 popMessage("error", "Error", 'All required fields must be filled.'); 87 88 // Resolve the promise 89 deferred.resolve(); 90 91 // Return the promise so the button will activate again 92 return deferred.promise; 93 } 94 95 vm.bidConfirmationModalOpen = true; 96 97 var confirmMessage = ""; 98 99 100 if (isBuyItNow && (vm.auctionItem.buyItNowQuantity != null && vm.auctionItem.buyItNowQuantity != 'undefined') && vm.auctionItem.buyItNowQuantity > 1 && vm.buyItNowBidQuantitySelected == null) { 101 102 //BUY IT NOW WITH MORE THAN 1 QUANTITY AVAILABLE FOR PURCHASE, AND THE QUANTITY HAS NOT YET BEEN SELECTED 103 104 vm.buyItNowBidQuantitySelected = 1; //Set the default of 1 105 106 confirmMessage = '<span class="text-danger" ng-show="bidPlacedWhileConfirmationModalIsOpen">This bid is no longer valid since an incoming bid has been placed on this lot. Press the cancel button to review the new information before placing another bid.<br /></span>' + 107 '<span ng-hide="bidPlacedWhileConfirmationModalIsOpen">' + vm.auctionItem.buyItNowQuantity + ' lots of ' + vm.auctionItem.name + 108 ' are available for ' + 109 formatCurrency(vm.bid.bidAmount) + 110 (vm.auctionItem.bidModifier > 1 ? ' (x ' + vm.auctionItem.bidModifier + ' = ' + formatCurrency(vm.auctionItem.winningBidInformation[0].amount * vm.auctionItem.bidModifier) + ' Total)' : '') 111 + ' each.<br />How many would you like to buy? <br />' + 112 '<input name="selectedBuyItNowQuantity" type="number" class="form-control" min="1" max="{{vm.auctionItem.buyItNowQuantity}}" placeholder="QTY" ng-model="vm.buyItNowBidQuantitySelected" />'; 113 114 vm.bidConfirmationModal = $ngConfirm({ 115 title: 'How Many?', 116 closeIcon: false, 117 icon: 'fa fa-gavel text-success', 118 content: confirmMessage, 119 scope: $scope, 120 buttons: { 121 confirm: { 122 text: 'Buy', 123 btnClass: 'btn-success', 124 action: function (buttonScope, button) { 125 126 $timeout(function () { vm.placeBidWithConfirmation(isBuyItNow); }, 250); 127 deferred.resolve(); 128 } // End Confirm Action 129 }, 130 cancel: { 131 text: 'Cancel', 132 btnClass: 'btn-warning',
133 action: function (buttonScope, button) { 134 // Set that the confirmaiton modal is now closed 135 vm.buyItNowBidQuantitySelected = null; 136 vm.bidConfirmationModalOpen = false; 137 $scope.bidPlacedWhileConfirmationModalIsOpen = false; 138 // Return the resolve 139 deferred.resolve(); 140 } 141 } 142 } 143 }); 144 145 return deferred.promise; 146 } 147 else { 148 if (isBuyItNow) { 149 //BUY IT NOW 150 151 if ((vm.buyItNowBidQuantitySelected != null && vm.buyItNowBidQuantitySelected != 'undefined') && vm.buyItNowBidQuantitySelected > 1) { 152 confirmMessage = '<span class="text-danger" ng-show="bidPlacedWhileConfirmationModalIsOpen">This bid is no longer valid since an incoming bid has been placed on this lot. Press the cancel button to review the new information before placing another bid.<br /></span>' + 153 '<span ng-hide="bidPlacedWhileConfirmationModalIsOpen">Are you sure you want to buy ' + vm.buyItNowBidQuantitySelected + ' lots of ' + vm.auctionItem.name + 154 ' for ' + 155 formatCurrency(vm.bid.bidAmount * vm.buyItNowBidQuantitySelected) + 156 (vm.auctionItem.bidModifier > 1 ? ' (x ' + vm.auctionItem.bidModifier + ' = ' + formatCurrency(vm.auctionItem.winningBidInformation[0].amount * vm.auctionItem.bidModifier * vm.buyItNowBidQuantitySelected) + ' Total)' : ''); 157 } else { 158 confirmMessage = '<span class="text-danger" ng-show="bidPlacedWhileConfirmationModalIsOpen">This bid is no longer valid since an incoming bid has been placed on this lot. Press the cancel button to review the new information before placing another bid.<br /></span>' + 159 '<span ng-hide="bidPlacedWhileConfirmationModalIsOpen">Are you sure you want to buy ' + vm.auctionItem.name + 160 ' for ' + 161 formatCurrency(vm.bid.bidAmount) + 162 (vm.auctionItem.bidModifier > 1 ? ' (x ' + vm.auctionItem.bidModifier + ' = ' + formatCurrency(vm.auctionItem.winningBidInformation[0].amount * vm.auctionItem.bidModifier) + ' Total)' : ''); 163 } 164 165 } else { 166 //REGULAR BID 167 confirmMessage = '<span class="text-danger" ng-show="bidPlacedWhileConfirmationModalIsOpen">This bid is no longer valid since an incoming bid has been placed on this lot. Press the cancel button to review the new information before placing another bid.<br /></span>' + 168 '<span ng-hide="bidPlacedWhileConfirmationModalIsOpen">Are you sure you want to place a ' + 169 (vm.auctionItem.bidMessage.isWinning ? 'max bid' : 'bid') + 170 ' of ' + 171 (vm.auctionItem.bidMessage.isWinning ? formatCurrency(vm.bid.maxBidAmount) : formatCurrency(vm.bid.bidAmount)) + 172 (vm.auctionItem.bidMessage.isWinning == false && vm.bid.maxBidAmount > 0 ? ' and a max bid of ' + formatCurrency(vm.bid.maxBidAmount) : '') + 173 //(vm.auctionItem.bidModifier > 1 ? ' (x ' + vm.auctionItem.bidModifier + ' = ' + formatCurrency(vm.auctionItem.winningBidInformation[0].amount * vm.auctionItem.bidModifier) + ' Total)' : '') + 174 (vm.auctionItem.bidModifier > 1 ? ' (x ' + vm.auctionItem.bidModifier + ' = ' + formatCurrency(vm.bid.bidAmount * vm.auctionItem.bidModifier) + ' Total)' : '') + 175 ' for ' + vm.auctionItem.name + '?</span>'; 176 } 177 178 vm.bidConfirmationModal = $ngConfirm({ 179 title: isBuyItNow ? 'Buy It Now' : vm.auctionItem.bidMessage.isWinning ? 'Place Max Bid' : 'Place Bid', 180 closeIcon: false, 181 icon: 'fa fa-gavel text-success', 182 content: confirmMessage, 183 scope: $scope, 184 buttons: { 185 confirm: { 186 text: isBuyItNow ? 'Buy' : 'Place Bid', 187 btnClass: 'btn-success', 188 action: function (buttonScope, button) { 189 190 if (isBuyItNow && vm.auctionItem.buyItNowQuantity > 1) { 191 //NEW BID SPROC FOR MANAGING BUYITNOW QUANTITY 192 193 bidsService.bidsBuyItNowQuantityInsert(vm.bid, vm.buyItNowBidQuantitySelected).then(function (results) { 194 195 var winningBidInfo = results.data.winningBidInformation[0]; 196 var isOutBid = false; 197 198 vm.auctionItem.isWatchlistAuctionItem = 1; 199 200 if (winningBidInfo.isBidInserted) { 201 //if (winningBidInfo.userId == vm.user.id) { 202 // popMessage("success", "Bid Entered", "Your bid was entered successfully!"); 203 //} else { 204 // popMessage("warning", 'Out Bid', 'You have been out bid.'); 205 // isOutBid = true; 206 //} 207 208 popMessage("success", "Bid Entered", "Your bid was entered successfully!"); 209 210 // Show that you have placed a bi
210d on this auction item 211 vm.auctionItem.hasBidOnItem = true; 212 213 // If the user entered a max bid, we need to update his max bid amount for the screen 214 //if (winningBidInfo.isMaxBidInserted) { 215 // vm.auctionItem.userMaxBidAmount = vm.bid.maxBidAmount; 216 // if (!isOutBid) { 217 // popMessage("success", "Max Bid Entered", "Your max bid was entered successfully!"); 218 // } 219 //} 220 221 //} else if (winningBidInfo.isMaxBidInserted) { 222 // // If the user entered a max bid, we need to update his max bid amount for the screen 223 // vm.auctionItem.userMaxBidAmount = vm.bid.maxBidAmount; 224 // popMessage("success", "Max Bid Entered", "Your max bid was entered successfully!"); 225 } else { 226 var resultInfo = results.data.results[0]; 227 if (resultInfo.success) { 228 popMessage("warning", resultInfo.title, resultInfo.message); 229 } else { 230 popMessage("error", resultInfo.title, resultInfo.message); 231 } 232 } 233 234 // Close the bidding area (if in the auction list) 235 vm.auctionItem.showBidding = false; 236 237 // Get the messages for the auction item per user 238 //vm.auctionItem.bidMessage = getAuctionItemBid
238Message(vm.user, vm.auctionItem); 239 vm.auctionItem.bidMessage = { 240 message: { 241 text: 'Placing bid...', 242 class: 'default' 243 }, 244 isAllowedToBid: false, 245 isWinning: false 246 }; 247 248 // Reset the max bid back to nothing. 249 vm.bid.maxBidAmount = null; 250 251 // Set that the confirmaiton modal is now closed 252 vm.bidConfirmationModalOpen = false; 253 254 $rootScope.$broadcast('bid-placed', winningBidInfo); 255 256 vm.buyItNowBidQuantitySelected = null; 257 258 // Resolve the promise 259 deferred.resolve(); 260 261 }, function (error) { 262 // Pop up an error 263 popApiErrorMessage(error); 264 265 // Set that the confirmaiton modal is now closed 266 vm.bidConfirmationModalOpen = false; 267 $scope.bidPlacedWhileConfirmationModalIsOpen = false; 268 269 vm.buyItNowBidQuantitySelected = null; 270 271 // Resolve the promise 272 deferred.resolve(); 273 }); 274 } 275 else { 276 //REGULAR BID 277 bidsService.insertBid(vm.bid).then(function (results) { 278 279 var winningBidInfo = results.data.winningBidInformation[0]; 280 var isOutBid = false; 281 282 vm.auctionItem.isWatchlistAuctionItem = 1; 283 284 if (winningBidInfo.isBidInserted) { 285 if (winningBidInfo.userId == vm.user.id) { 286 popMessage("success", "Bid Entered", "Your bid was entered successfully!"); 287 } else { 288 popMessage("warning", 'Out Bid', 'You have been out bid.'); 289 isOutBid = true; 290 } 291 292 // Show that you have placed a bid on this auction item 293 vm.auctionItem.hasBidOnItem = true; 294 295 // If the user entered a max bid, we need to update his max bid amount for the screen 296 if (winningBidInfo.isMaxBidInserted) { 297 vm.auctionItem.userMaxBidAmount = vm.bid.maxBidAmount; 298 if (!isOutBid) { 299 popMessage("success", "Max Bid Entered", "Your max bid was entered successfully!"); 300 } 301 } 302 303 } else if (winningBidInfo.isMaxBidInserted) { 304 // If the user entered a max bid, we need to update his max bid amount for the screen 305 vm.auctionItem.userMaxBidAmount = vm.bid.maxBidAmount; 306 popMessage("success", "Max Bid Entered", "Your max bid was entered successfully!"); 307 } else { 308 var resultInfo = results.data.results[0]; 309 if (resultInfo.success) { 310 popMessage("warning", resultInfo.title, resultInfo.message); 311 } else { 312 popMessage("error", resultInfo.title, resultInfo.message); 313 } 314 } 315 316 // Close the bidding area (if in the auction list) 317 vm.auctionItem.showBidding = false; 318 319 // Get the messages for the auction item per user 320 //vm.auctionItem.bidMessage = getAuctionItemBid
320Message(vm.user, vm.auctionItem); 321 vm.auctionItem.bidMessage = { 322 message: { 323 text: 'Placing bid...', 324 class: 'default' 325 }, 326 isAllowedToBid: false, 327 isWinning: false 328 }; 329 330 // Reset the max bid back to nothing. 331 vm.bid.maxBidAmount = null; 332 333 // Set that the confirmaiton modal is now closed 334 vm.bidConfirmationModalOpen = false; 335 336 $rootScope.$broadcast('bid-placed', winningBidInfo); 337 338 vm.buyItNowBidQuantitySelected = null; 339 340 // Resolve the promise 341 deferred.resolve(); 342 343 }, function (error) { 344 // Pop up an error 345 popApiErrorMessage(error); 346 347 // Set that the confirmaiton modal is now closed 348 vm.bidConfirmationModalOpen = false; 349 $scope.bidPlacedWhileConfirmationModalIsOpen = false; 350 351 vm.buyItNowBidQuantitySelected = null; 352 353 // Resolve the promise 354 deferred.resolve(); 355 }); 356 } 357 358 359 360 361 362 } // End Confirm Action 363 }, 364 cancel: { 365 text: 'Cancel', 366 btnClass: 'btn-warning', 367 action: function (buttonScope, button) { 368 // Set that the confirmaiton modal is now closed 369 vm.bidConfirmationModalOpen = false; 370 $scope.bidPlacedWhileConfirmationModalIsOpen = false; 371 372 vm.buyItNowBidQuantitySelected = null; 373 374 // Return the resolve 375 deferred.resolve(); 376 } 377 } 378 } 379 }); 380 381 return deferred.promise; 382 } 383 384 }; 385 386 vm.getBidsForAuctionItem = function (auctionItem) { 387 vm.loadingBidHistory = true; 388 auctionItem.bidHistory = []; 389 bidsService.getAuctionItemBidHistory(auctionItem.auctionItemId).then(function (results) { 390 auctionItem.bidHistory = results.data.bids; 391 vm.loadingBidHistory = false; 392 }, function (error) { 393 // Pop up an error 394 popApiErrorMessage(error); 395 }); 396 }; 397 398 vm.formatDateAsUtc = function (dateToFormat) { 399 return formatDateOrDateStringAsUtcDate(dateToFormat); 400 }; 401 402 vm.popTermsAndConditions = function (isBuyItNow, bidAfterAgree) { 403 404 $ngConfirm({ 405 columnClass: 'col-xs-12 col-xs-offset-0 col-sm-8 col-sm-offset-2', 406 closeIcon: false, 407 title: 'Auction Terms and Conditions', 408 icon: '', 409 //content: '<div class="text-left" style="max-height:400px;overflow-y:auto;overflow-x:hidden;"><div style="white-space: pre-wrap;margin-right: 10px;">' + vm.auctionTermsAndConditions + '</div></div>', 410 contentUrl: '/app/directives/biddingTermsAndConditions.html', 411 scope: $scope, 412 buttons: { 413 ok: { 414 text: 'I Agree', 415 btnClass: 'btn-success', 416 action: function (buttonScope, button) { 417 418 //validate 18 or older 419 var userIs18OrOlder = false; 420 if (vm.agreeTo18 != true) { 421 userIs18OrOlder = false; 422 $scope.$broadcast('show-errors-check-validity'); 423 popMessage('error', 'You Must Be 18 Years Old', 'You must be 18 years of age or older before you can bid.'); 424 } else { 425 userIs18OrOlder = true; 426 } 427 428 //validate the question form 429 var questionsAnswered = true; 430 if (vm.auctionQuestions != null && vm.auctionQuestions.questions != null && vm.auctionQuestions.questions.length > 0) { 431 $.each(vm.auctionQuestions.questions, function (index, question) { 432 if (question.answer == null || question.answer.trim().length == 0) { 433 $scope.$broadcast('show-errors-check-validity'); 434 popMessage('error', 'Pre-bidding Questions', 'You must answer all of the questions before you can bid.'); 435 questionsAnswered = false; 436 return false; 437 } 438 }); 439 } 440 441 if (!questionsAnswered || !userIs18OrOlder) { 442 return false; 443 } 444 445 446 auctionsService.upsertAuctionUserAnswers(vm.bid.auctionId, vm.auctionQuestions).then(function (results) { 447 //Nothing to do if successful 448 }, function (error) { 449 // Pop up an error 450 popApiErrorMessage(error); 451 }); 452 453 vm.bid.agreeToTermsAndConditions = true; 454 455 vm.hasBidOnAuction = true; 456 457 if (bidAfterAgree) { 458 vm.placeBidWithConfirmation(isBuyItNow); 459 } 460 461 } 462 }, 463 cancel: { 464 text: 'Cancel', 465 btnClass: 'btn-warning',
466 action: function (buttonScope, button) { 467 468 vm.bid.agreeToTermsAndConditions = false; 469 } 470 } 471 } 472 }); 473 }; 474 475 vm.goToLiveAuction = function (auctionId) { 476 $state.go('liveAuction', { "auctionId": auctionId }); 477 }; 478 479 vm.settings = lookupService.settings; 480 481 vm.isLoggedIn = false; 482 vm.isAllowedToBid = false; 483 484 $scope.bidPlacedWhileConfirmationModalIsOpen = false; 485 vm.bidConfirmationModalOpen = false; 486 vm.bidConfirmationModal = {}; 487 488 vm.buyItNowBidQuantitySelected = null; 489 490 vm.bid = { 491 auctionId: null, 492 auctionItemId: null, 493 userId: null, 494 bidAmount: null, 495 maxBidAmount: null, 496 phoneVerified: null 497 }; 498 499 vm.agreeTo18 = ""; 500 501 vm.loadingBidHistory = false; 502 503 }] 504);
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.