1app.controller('adminAuctionItemsQuickSortController', ['$scope', '$state', '$stateParams', '$timeout', '$q', '$filter', '$location', '$ngConfirm', '$sce', 'localStorageService', 'permissionsService', 'authenticationService', 'adminCompanySettingsService', 'lists', 'auctionsService', 'webApiSettings', 2 function ($scope, $state, $stateParams, $timeout, $q, $filter, $location, $ngConfirm, $sce, localStorageService, permissionsService, authenticationService, adminCompanySettingsService, lists, auctionsService, webApiSettings) { 3 4 $scope.initializePage = function () { 5 if ($scope.isInRole('Consignor') && !$scope.isInRole('Admin')) { 6 auctionsService.getAuctionAdminAccessBySale($scope.auctionId).then(function (results) { 7 if (results.data.access[0].hasAccess) { 8 $scope.user.roles += ',Admin'; 9 } 10 $scope.initialize(); 11 }, function (error) { 12 popApiErrorMessage(error); 13 }); 14 } 15 else { 16 $scope.initialize(); 17 } 18 }; 19 20 $scope.initialize = function () { 21 $scope.$parent.activeChildView = $state.current.name.replace('adminAuction.', ''); 22 23 // Check to make sure they are logged in as a user 24 var requesteduserRightsRequested = { 25 roles: ['Super Admin', 'Admin', 'Consignor'], 26 permissions: ['CanChangeAuctions'] 27 }; 28 permissionsService.isPermitted(requesteduserRightsRequested).then(function (results) { 29 if (!results.data) { 30 popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue."); 31 authenticationService.logout(); 32 $state.go('accountLogin'); 33 } else { 34 35 if ($scope.auctionId == -1) { 36 $state.go('adminAuction.auctionInfo'); 37 } 38 39 $scope.prepareAuctionItems(); 40 } 41 }, function (error) { 42 popApiErrorMessage(error); 43 }); 44 } 45 46 $scope.prepareAuctionItems = function () { 47 //We need to make sure the parent has retrieved the auction before we can proceed 48 //We can tell by comparing the auctionId from the $stateParams against the one from the parent. 49 //Once the parent has hydrated the auction, the IDs will match. 50 if ($scope.auction.auctionId != $scope.auctionId) { 51 $timeout($scope.prepareAuctionItems, 500); 52 } else { 53 54 $.each($scope.auction.auctionItems.sort($scope.sortArrayBySequence), function (auctionItemIndex, auctionItem) { 55 $scope.auctionItemList.items.push({ label: truncateText(auctionItem.name, 25), fullName: auctionItem.name, id: auctionItem.auctionItemId, sequence: auctionItem.sequence }); 56 }); 57 58 $scope.pageIsLoaded = true; 59 } 60 61 }; 62 63 $scope.sortArrayBySequence = function (a, b) { 64 return ((a.sequence < b.sequence) ? -1 : ((a.sequence > b.sequence) ? 1 : 0)); 65 }; 66 67 68 69 //dnd-dragging determines what data gets serialized and send to the receiver 70 //of the drop. While we usually just send a single object, we send the array 71 //of all selected items here. 72 73 $scope.getSelectedItemsIncluding = function (list, item) { 74 item.selected = true; 75 return list.items.filter(function (item) { return item.selected; }); 76 }; 77 78 79 //We set the list into dragging state, meaning the items that are being 80 //dragged are hidden. We also use the HTML5 API directly to set a custom 81 //image, since otherwise only the one item that the user actually dragged 82 //would be shown as drag image. 83 84 $scope.onDragstart = function (list, event) { 85 list.dragging = true; 86 }; 87 88 89 //In the dnd-drop callback, we now have to handle the data array that we 90 //sent above. We handle the insertion into the list ourselves. By returning 91 //true, the dnd-list directive won't do the insertion itself. 92 93 $scope.onDrop = function (list, items, index) { 94 angular.forEach(items, function (item) 95 { 96 item.needsDropNotification = true; 97 item.selected = false; 98 } 99 ); 100 list.items = list.items.slice(0, index) 101 .concat(items) 102 .concat(list.items.slice(index)); 103 return true; 104 }; 105 106 107 //We have to remove the previously dragged items in the dnd-moved callback. 108 109 $scope.onMoved = function (list) { 110 list.items = list.items.filter(function (item) { return !item.selected; }); 111 112 // Save the resquencing 113 var auctionItemIdsAndSequencesKVP = []; 114 115 var counter = 0; 116 $.each(list.items, function (index, item) { 117 118 item.sequence = counter; 119 120 auctionItemIdsAndSequencesKVP.push({ key: item.id, value: counter }); 121 122 //Find the parent auction item and change its sequence so the other pages can react accordingly 123 $.each($scope.auction.auctionItems, function (auctionItemIndex, auctionItem) { 124 if (auctionItem.auctionItemId == item.id) { 125 auctionItem.sequence = counter; 126 } 127 }); 128 129 counter += 1; 130 }); 131 132 //Update Sequences 133 auctionsService.updateAuctionItemSequences($scope.auction.auctionId, auctionItemIdsAndSequencesKVP).then(function (results) { 134 popMessage("success", "Lot Resquencing Saved", "The lots have been resequenced successfully."); 135 136 $timeout(function () { 137 $.each(list.items, function (index, item) { 138 item.needsDropNotification = false; 139 }); 140 }, 2000); 141 142 }, function (error) { 143 popApiErrorMessage(error); 144 }); 145 }; 146 147 148 149 $scope.isInRole = function (roleName) { 150 var roles = [] 151 152 if ($scope.user && $scope.user != null && $scope.user.roles && $scope.user.roles != null) { 153 roles = $scope.user.roles.split(','); 154 } 155 156 var foundRole = false; 157 158 $.each(roles, function (index, role) { 159 if ($.trim(roleName).toLowerCase() == $.trim(role).toLowerCase()) { 160 foundRole = true; 161 return false; 162 } 163 }); 164 165 return foundRole; 166 }; 167 168 ////initialize variables 169 $scope.user = localStorageService.get('AuthData'); 170 $scope.pageIsLoaded = false; 171 172 $scope.auctionId = $stateParams.auctionId; 173 174 $scope.auctionItemList = { items: [], dragging: false}; 175 176 //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation 177 $scope.canShowPageLoading = false; 178 $timeout(function () { $scope.canShowPageLoading = true; }, 1000); 179 180 //initialize Page 181 $scope.initializePage(); 182 } 183]);
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.