1import CloudflareTurnstile from './cloudflareTurnstile.js'; 2import './assert-05fed46d.js'; 3 4// CAUTION: This file is used in several parts of the application. 5//watchlist image upload 6// @ts-ignore 7function readURL(input, targetobj) { 8 if (input.files && input.files[0]) { 9 var reader = new FileReader(); 10 reader.onload = function (e) { 11 // @ts-ignore 12 $('#' + targetobj).attr('src', e.target.result); 13 }; 14 reader.readAsDataURL(input.files[0]); 15 } 16} 17/** 18 * Shows a no entry sign on a link or button 19 * @param $element The jQuery link or button 20 * @param milliSeconds Time in milliseconds the sign should be visible 21 * @returns undefined 22 */ 23// @ts-ignore 24function showNoEntrySignForNSeconds($element, milliSeconds) { 25 // @ts-ignore 26 var $span = $element.find('span'); 27 // @ts-ignore 28 var oldText = $span.text(); 29 var oldWidth = $element.css('width'); 30 $element.toggleClass('changed'); 31 $element.css('width', oldWidth); 32 // @ts-ignore 33 $span.fadeOut('slow', function () { 34 // @ts-ignore 35 $span.empty().html('🚫'); // "no entry" sign 36 }); 37 // @ts-ignore 38 $span.fadeIn('fast', function () { 39 // @ts-ignore 40 $span.delay(milliSeconds).fadeOut('fast', function () { 41 // @ts-ignore 42 $span.empty().text(oldText); 43 // @ts-ignore 44 $span.fadeIn('slow', function () { 45 $element.toggleClass('changed'); 46 }); 47 }); 48 }); 49} 50/** 51 * call for adding articles to shoppingbaskes / watchlist 52 * @param $link The HTML element which triggered the action 53 * @param entries The artgroesse / amount combinations to add to the basket 54 * @param location The controller::action to call 55 * @returns Promise 56 */ 57// @ts-ignore 58function addArticlesToWatchlistOrBasket($link, entries, location) { 59 // make sure the button doesn't get smaller because of the shorter text we will add 60 var oldWidth = $link.css('width'); 61 $link.css('width', oldWidth); 62 /* make sure the arrow besides the "check-mark" is not visible when button clicked*/ 63 $link.removeClass('arrow'); 64 $link.addClass('active'); 65 //add artgroesseids to url 66 // @ts-ignore 67 $.each(entries, function (index, element) { 68 if (!index) { 69 location += '?artgroesseids[]=' + element['artgroesseid']; 70 } 71 else { 72 location += '&artgroesseids[]=' + element['artgroesseid']; 73 } 74 location += '&amountids[]=' + element['amount']; 75 }); 76 // @ts-ignore 77 var ajaxPromise = $.ajax({ 78 dataType: 'json', 79 url: location, 80 // @ts-ignore 81 success: function (data) { 82 if ('ok' == data.message) { 83 var type = ''; 84 if (location.search('shoppingbasket') != -1) { 85 type = 'shoppingbasket'; 86 } 87 else if (location.search('watchlist') != -1) { 88 type = 'watchlist'; 89 } 90 // @ts-ignore 91 updateNumberOfSkusInHeader(type); 92 } 93 else { 94 //TODO: wann koennen Artikel nicht in den Warenkorb / die Merkliste gelegt werden? 95 alert('Artikel konnte nicht in den Warenkorb gelegt werden'); 96 } 97 //TODO: clear all input fields? 98 }, 99 }); 100 // @ts-ignore 101 jQuery.when(ajaxPromise).done(function () { 102 setTimeout(function () { 103 /* show the arrow again */ 104 $link.addClass('arrow'); 105 $link.removeClass('active'); 106 }, 2000); 107 }); 108 return ajaxPromise; 109} 110// @ts-ignore 111$(document).ready(function () { 112 // @ts-ignore 113 $('.img_upload').on('change', function () { 114 // @ts-ignore 115 let targetobj = 'tgt-' + $(this).data('itemid'); 116 // @ts-ignore 117 readURL(this, targetobj); 118 }); 119 //Inplace editing of values in watchlist 120 // @ts-ignore 121 $('.watchlist_index form').on('focusout', '.input_holder input', function (event) { 122 // @ts-ignore 123 var watchlistitemsizeid = $(this) 124 .attr('name') 125 .match(/amount\[(\d+)\]/); 126 // No update if not amount field 127 if (watchlistitemsizeid == null) { 128 return; 129 } 130 // Don`t submit the complete form when pressing enter in an amount input field. 131 // Just update the current itemsize 132 if (event.keyCode == 13) { 133 event.preventDefault(); 134 } 135 // @ts-ignore 136 var amount = $(this).val().trim(); 137 //sanitize amount 138 // @ts-ignore 139 var error = validateNumber(amount); 140 // @ts-ignore 141 if (errorEnum.no_error !== error) { 142 return; 143 } 144 // @ts-ignore 145 var url = $(this).closest('form').prop('action'); 146 var location = url + 'edit/watchlistitemsizeid/' + watchlistitemsizeid[1] + '/amount/' + Number(amount) + '/'; 147 // @ts-ignore 148 $.ajax({ 149 dataType: 'json', 150 url: location, 151 // @ts-ignore 152 success: function (data) { 153 if ('ok' == data.message) { 154 // @ts-ignore 155 updateNumberOfSkusInHeader('watchlist'); 156 } 157 }, 158 }); 159 }); 160 //article detail - item to basket and neukundenanfrage (article detail) 161 // @ts-ignore 162 $('.details_main').on('click', 'form#art-detail-to-basket button.button', function (event) { 163 event.preventDefault(); 164 // @ts-ignore 165 var $button = $(this); 166 var $btn_disabled = $button.attr('disabled'); 167 // For some browsers, `attr` is undefined; for others, `attr` is false. Check for both. 168 if (typeof $btn_disabled !== typeof undefined && $btn_disabled !== false) { 169 return; 170 } 171 // @ts-ignore 172 var $form = $('form#art-detail-to-basket'); 173 var $mengeInput = $form.find('input#q_num').first(); 174 var menge = $mengeInput.val().trim(); 175 //sanitize menge 176 $mengeInput.unwrap('span.field_with_errors'); //remove previous set errors 177 // @ts-ignore 178 var error = validateNumber(menge); 179 // @ts-ignore 180 if (errorEnum.no_error !== error) { 181 // @ts-ignore 182 if (errorEnum.zero == error) { 183 //if 0, just clear field 184 $mengeInput.val(''); 185 } 186 else { 187 //else mark error field 188 $mengeInput.wrap('<span class="field_with_errors"></span>'); 189 showNoEntrySignForNSeconds($button, 3000); 190 } 191 return; 192 } 193 var colorSelect = document.querySelector('sl-select#colors'); 194 var sizeSelect = document.querySelector('sl-select#groesse_bestand'); 195 // @ts-ignore 196 var artfarbeId = colorSelect.value; 197 // @ts-ignore 198 var artgroesseId = sizeSelect.value; 199 // @ts-ignore 200 var farbenId = colorSelect.querySelector('sl-option[value="' + artfarbeId + '"]').dataset.colorid; 201 var entries = [];
202 entries.push({ artgroesseid: artgroesseId, artfarbeid: artfarbeId, amount: Number(menge) }); 203 var location = $button.data('url'); 204 location += 'farbenid/' + farbenId + '/artfarbeid/' + artfarbeId + '/'; 205 var promiseBasket = addArticlesToWatchlistOrBasket($button, entries, location); 206 promiseBasket.done(function () { 207 // @ts-ignore 208 articleDetailApi.reloadPriceDependents(); 209 }); 210 }); 211 let watchlistFormTurnstile; 212 let turnstileContainer = document.querySelector('.turnstile_container .turnstile'); 213 if (turnstileContainer !== null) { 214 watchlistFormTurnstile = new CloudflareTurnstile('.turnstile_container .turnstile', '.query_submit .button'); 215 watchlistFormTurnstile.renderWidget(); 216 } 217 //article detail - item to basket and neukundenanfrage ('related articles' slider, 'get-the-look' and 'alle farben und bestaende') 218 // @ts-ignore 219 $('section#content_part').on('click', 'a.animatebasket', function (event) { 220 event.preventDefault(); 221 // if CF is not ready, the user shouldn't be able to click the button 222 if (turnstileContainer !== null) { 223 if (!watchlistFormTurnstile) { 224 return false; 225 } 226 const token = watchlistFormTurnstile.getToken(); 227 if (!token) { 228 return false; 229 } 230 } 231 // @ts-ignore 232 let $link = $(this); 233 // @ts-ignore 234 if ($link.hasClass('changed')) { 235 //disable click when animation is running 236 return; 237 } 238 //get all mengen inputs from table 239 // @ts-ignore 240 var $table = $link.prev('table'); 241 // @ts-ignore 242 var entries = getEntries($table);
243 //if any of the values is invalid, show warnings and don't proceed 244 { 245 // @ts-ignore 246 let $messageContainer = $link.next('.error-messages'); 247 // @ts-ignore 248 if ($messageContainer.length) { 249 //there is only a message container in the related articles slider, colors list is missing it 250 //clear previous messages 251 // @ts-ignore 252 $messageContainer.find('p').css('display', 'none'); 253 } 254 if (entries.errors.length) { 255 var hasError = false; 256 // @ts-ignore 257 $.each(entries.errors, function (key, value) { 258 // @ts-ignore 259 if (errorEnum.zero == value['message']) { 260 //just clear field 261 value['element'].val(''); 262 } 263 else { 264 value['element'].wrap('<span class="field_with_errors"></span>'); 265 hasError = true; 266 } 267 }); 268 if (hasError) { 269 // @ts-ignore 270 if ($messageContainer.length) { 271 //there is only a message container in the related articles slider, colors list is missing it 272 // @ts-ignore 273 $messageContainer.find('p').css('display', 'block'); 274 } 275 // @ts-ignore 276 showNoEntrySignForNSeconds($link, 3000); 277 } 278 return; 279 } 280 } 281 //we need at least one valid entry, otherwise don't proceed 282 if (!entries.entries.length) { 283 return; 284 } 285 // @ts-ignore 286 var location = $link.attr('href'); 287 //only show popup if adding to shopping basket, not to watchlist 288 // @ts-ignore 289 var showPopup = $link.data('popup'); 290 if (showPopup) { 291 // @ts-ignore 292 popups.open('popup_recalculating_prices'); 293 } 294 // @ts-ignore 295 var promiseBasket = addArticlesToWatchlistOrBasket($link, entries.entries, location); 296 promiseBasket.fail(function () { 297 if (showPopup) { 298 // @ts-ignore 299 popups.close(); 300 } 301 }); 302 if (showPopup) { 303 promiseBasket.done(function () { 304 // @ts-ignore 305 if ($link.parents('.related').length) { 306 // @ts-ignore 307 articleDetailApi.reloadRelatedArticles(); 308 } 309 // @ts-ignore 310 articleDetailApi.reloadPriceDependents().then(function () { 311 // @ts-ignore 312 popups.close(); 313 }); 314 }); 315 } 316 }); 317 /** 318 * Get all the artgroesse/amount from the inputs in a table 319 * @TODO: remove error status for inputs here? 320 * @param $table 321 * @returns array 322 */ 323 // @ts-ignore 324 function getEntries($table) { 325 // @ts-ignore 326 var errors = []; 327 // @ts-ignore 328 var entries = []; 329 $table.find('input').each(function () { 330 //remove previous set error css 331 // @ts-ignore 332 $(this).unwrap('span.field_with_errors'); 333 // @ts-ignore 334 var value = $(this).val().trim(); 335 // @ts-ignore 336 var error = validateNumber(value); 337 switch (error) { 338 // @ts-ignore 339 case errorEnum.no_error: 340 //all seems ok, add artgroesse and number to basket 341 // @ts-ignore 342 var artgroesse = $(this).closest('tr').data('artgroesseid'); 343 // @ts-ignore 344 var artfarbeid = $(this).closest('tr').data('artfarbeid'); 345 entries.push({ artgroesseid: artgroesse, artfarbeid: artfarbeid, amount: Number(value) }); 346 break; 347 // @ts-ignore 348 case errorEnum.empty: 349 return true; //same as continue; 350 default: 351 // @ts-ignore 352 errors.push({ message: error, element: $(this) }); 353 break; 354 } 355 }); 356 // @ts-ignore
357 return { errors: errors, entries: entries }; 358 } 359}); 360 361//# sourceMappingURL=WatchlistPromo.entry.js.map
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.