1angular.module('app') 2 .directive('addProductToWishlist', function (appService, $rootScope, $q, $http, translationService, shoppingCartModel) { 3 4 return { 5 restrict: 'E', 6 scope: { 7 addToWishlistComplete: '=', // Indicates if the product has been added to the wishlist 8 product: '=', 9 setGetWishlistsFn: '&' // Function to tell direct to get the current wishlists 10 }, 11 replace: true, 12 templateUrl: 'AddProductToWishlistDirective.html', 13 link: function (scope, element, attrs) { 14 if (scope.product != null) { 15 scope.product.newWishlistName = null; 16 } 17 18 scope.init = function () { 19 var promises = [appService.makeReady()]; 20 $q.all(promises).then(function () { 21 22 promises[translationService.getTranslations('wishlist-manager')]; 23 $q.all(promises).then(function (result) { 24 25 scope.dataReady = true; 26 }); 27 }); 28 } 29 30 scope.getWishlists = function () { 31 var customerCartID = idstc().getExpirableLocalStorageVar('CustomerCartID', idstc_setting_acutacartexpirationseconds); 32 33 var url = apiRoot + 'api/customerportal/GetPersonalWishlists'; 34 if (typeof customerCartID != 'undefined' && customerCartID != null) { 35 url = url + '?cartID=' + customerCartID; 36 } 37 38 return $http.get(url).then( 39 function (response) { 40 scope.wishlists = response.data; 41 42 if (scope.wishlists == null) { 43 scope.wishlists = []; 44 } 45 // add "Create A New List" as an option 46 scope.wishlists.push({ 47 WishlistID: '', 48 WishlistGuid: null, 49 Name: '+ ' + (translationService.translations['wishlist-manager']['create-a-new-list'] || 'Create A New List') 50 }); 51 if (scope.wishlists.length > 1) { 52 scope.product.selectedWishlistID = scope.wishlists[0].WishlistID; 53 } 54 }, 55 function (error) { 56 idstc().processError({ error: error, showNotifications: true }); 57 }); 58 } 59 60 scope.setGetWishlistsFn({ theSetDirFn: scope.getWishlists }); 61 62 scope.addToWishlist = function () { 63 var isValid = true; 64 65 if (typeof scope.product.selectedWishlistID == 'undefined' || scope.product.selectedWishlistID == null) { 66 isValid = false; 67 idstc().dialog({ 68 type: 'alert', 69 message: idstc().translate('wishlist-manager', 'wishlist-required', 'A wishlist is required.') 70 }, function () { 71 return; 72 }); 73 } 74 75 if (scope.product.selectedWishlistID == '') { 76 if (typeof scope.product.newWishlistName == 'undefined' || scope.product.newWishlistName == null || scope.product.newWishlistName == '') { 77 isValid = false; 78 79 idstc().dialog({ 80 type: 'alert', 81 message: idstc().translate('wishlist-manager', 'wishlist-name-required', 'New wishlist name is required.') 82 }, function () { 83 return; 84 }); 85 } 86 } 87 88 if (isValid) { 89 $(document).progressStart(); 90 91 var promises = []; 92 if (scope.product.selectedWishlistID == '') { 93 promises = [scope.createWishlist()]; 94 } 95 $q.all(promises).then(function (result) { 96 if (typeof result == 'undefined' || result == null || result.length == 0 || (result.length > 0 && result[0].status == 200)) { 97 var postVar = { 98 CartID: scope.product.CartID, 99 WishlistID: scope.product.selectedWishlistID, 100 SKU: scope.product.SKU, 101 BusinessUnitID: scope.product.BusinessUnitID, 102 CustomFields: scope.product.CustomFields, 103 BuildableComponents: scope.product.BuildableComponents 104 } 105 106 var url = apiRoot + 'api/customerportal/AddProductToPersonalWishlist'; 107 108 $http.post(url, postVar).then( 109 function (r) { 110 scope.addToWishlistComplete = true; 111 idstc().notifyServerResponse(r); 112 $(document).progressFinish(); 113 $rootScope.$broadcast('productAddedToWishlist.Complete', scope.product.SKU); 114 }, 115 function (error) { 116 idstc().processError({ error: error, showNotifications: true }); 117 $(document).progressFinish(); 118 } 119 ); 120 } 121 }); 122 } 123 } 124 125 scope.createWishlist = function () { 126 127 var url = apiRoot + 'api/customerportal/AddPersonalWishlist?name=' + scope.product.newWishlistName; 128 129 return $http.post(url, null).then( 130 function (r) { 131 scope.product.selectedWishlistID = r.data.data; 132 idstc().notifyServerResponse(r); 133 return r; 134 }, 135 function (error) { 136 idstc().processError({ error: error, showNotifications: true }); 137 $(document).progressFinish(); 138 return error; 139 } 140 ); 141 } 142 143 scope.continueShopping = function () { 144 scope.addToWishlistComplete = false;
145 $rootScope.$broadcast('productAddedToWishlist.ContinueShop'); 146 } 147 148 scope.viewWishlist = function () { 149 scope.addToWishlistComplete = false; 150 window.location = '/' + shoppingCartModel.translatedPageNames.wishlistManager; 151 } 152 153 scope.init(); 154 }, 155 }; 156 });
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.