1if (prestashop.page.page_name == 'module-brico_bonus_rep-home') { 2 3 $(document).ready(function () { 4 5 let customer_name = prestashop.customer.lastname.toUpperCase() + ' ' + prestashop.customer.firstname[0].toUpperCase() + prestashop.customer.firstname.slice(1).toLowerCase(); 6 let customer_email = prestashop.customer.email; 7 let customer_phone = $('.bonus input[name=customer_phone]').val(); 8 let id_bonus = $('.bonus input[name=id_bonus]').val(); 9 let reference = $('.bonus input[name=reference]').val(); 10 let ref_order = $('input[name=ref_order]').val(); 11 let id_tech = $('input[name=id_tech]').val(); 12 let current_state = $('.bonus input[name=current_state]').val(); 13 let id_step = $('.bonus .steps .step.active').attr('id'); 14 let step_text = getStepText(id_step); 15 $('.bonus .step_text').html(step_text.responseText); 16 let messages = getMessages(id_bonus); 17 $('.bonus .messages .messages_list').html(messages.responseText); 18 let history_lines = getHistory(id_bonus); 19 $('.bonus .history .history_lines').html(history_lines.responseText); 20 21 22 /* DEVICE */ 23 24 // Sélection du canvas et initialisation de SignaturePad 25 if ($('#signature_pad').length) { 26 27 var canvas = document.getElementById('signature_pad'); 28 var signaturePad = new SignaturePad(canvas); 29 30 // Ajuster la taille du canvas 31 function resizeCanvas() { 32 let ratio = Math.max(window.devicePixelRatio || 1, 1); 33 canvas.width = canvas.offsetWidth * ratio; 34 canvas.height = canvas.offsetHeight * ratio; 35 canvas.getContext("2d").scale(ratio, ratio); 36 signaturePad.clear(); // Efface le canvas après redimensionnement 37 } 38 39 // Redimensionner le canvas au chargement 40 resizeCanvas(); 41 42 // Bouton pour effacer la signature 43 $('#signature_clear').click(function () { 44 signaturePad.clear(); 45 }); 46 47 } 48 49 $(document).on('change', '.bonus .device select[name=type]', function () { 50 51 if ($(this).val() == 'Smartphone') { 52 $('.bonus .device .input_imei').removeClass('hidden'); 53 $('.bonus .device .input_serial').addClass('hidden'); 54 } 55 if ($(this).val() == 'Ordinateur' || $(this).val() == 'Console de jeu' || $(this).val() == 'Tablette') { 56 $('.bonus .device .input_imei').addClass('hidden'); 57 $('.bonus .device .input_serial').removeClass('hidden'); 58 } 59 60 }); 61 62 $(document).on('click', '.find_imei', function() { 63 $('#bonus_modal_background, #bonus_imei_modal').fadeIn(500); 64 $('body').css({'overflow':'hidden'}); 65 }); 66 $(document).on('click', '#bonus_modal_background, .bonus_modal_close_btn', function() { 67 $('#bonus_modal_background, #bonus_imei_modal').fadeOut(500); 68 $('body').css({'overflow':'auto'}); 69 }); 70 71 $(document).on('change', '.bonus .device select[name=id_product]', function() { 72 let bonus_amount = $(this).find('option:selected').data('bonus_amount'); 73 let visio_amount = $(this).find('option:selected').data('visio_amount'); 74 let refund_amount = $(this).find('option:selected').data('refund_amount'); 75 let id_product = $(this).val(); 76 $('.bonus .infos .bonus_amount').html(bonus_amount + '<small>â¬</small>'); 77 $('.bonus .infos .visio_amount').html(visio_amount + '<small>â¬</small>'); 78 $('.bonus .infos .refund_amount').html(refund_amount + '<small>â¬</small>'); 79 $('.bonus .advice .links').addClass('hidden'); 80 $('.bonus .advice .links_' + id_product).removeClass('hidden'); 81 }); 82 83 $(document).on('click', '.bonus .device #w1, .bonus .device #i1', function() { 84 $('.bonus .device .alert_warranty').removeClass('hidden'); 85 }); 86 87 $(document).on('click', '.bonus .device #save', function () { 88 89 if (checkFields()) { 90 91 if (signaturePad.isEmpty()) { 92 $('#signature_pad').addClass('invalid'); 93 return; 94 } 95 96 $('#loading_frame').css({'display': 'flex'}); 97 98 let reference = $('input[name=reference]').val(); 99 let warranty = $('input[name=warranty]:checked').val(); 100 let insurance = $('input[name=insurance]:checked').val(); 101 let signature = signaturePad.toDataURL("image/png"); 102 103 let type = $('select[name=type]').val(); 104 let data = { 105 'id_bonus': id_bonus, 106 'id_order': $('select[name=id_product] option:selected').data('id_order'), 107 'reference': reference, 108 'type': type, 109 'brand': $('select[name=brand]').val(), 110 'model': $('input[name=model]').val(), 111 //'bonus_amount': bonus_amount, 112 //'visio_amount': visio_amount, 113 'warranty': (warranty !== undefined ? warranty : 0), 114 'insurance': (insurance !== undefined ? insurance : 0), 115 'description': $('textarea[name=description]').val(), 116 //'id_product': product.data('id_product'), 117 'id_product': $('select[name=id_product]').val(), 118 'signature': signature 119 }; 120 121 if (type == 'Smartphone') { 122 data['imei'] = $('input[name=imei]').val(); 123 } 124 if (type != 'Smartphone') { 125 data['serial'] = $('input[name=serial]').val(); 126 } 127 128 $.ajax({ 129 type: "POST", 130 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=device', 131 data: {data}, 132 success: function (result) { 133 //location.reload(true); 134 $('.bonus .device #save, #signature_pad, #signature_clear').remove(); 135 $('.bonus .device .input.signature').append('<img id="signature_png" src="img/cms/BONUS/signatures/signature_' + reference + '.png">'); 136 refreshHistory(data['id_bonus']); 137 updateSteps(2); 138 refreshStepText('step_2'); 139 $('.appointment_infos .open_calendar').removeAttr('disabled'); 140 $('.bonus .device .device_saved').removeClass('hidden'); 141 $('#loading_frame').fadeOut(1600); 142 $('.modal_certificate').removeClass('hidden'); 143 } 144 }); 145 146 } 147 148 }); 149 150 /* 151 $(document).on('click', '#submit_certificate', function() { 152 if (!signaturePad.isEmpty()) { 153 $('#loading_frame').css({'display': 'flex'}); 154 const { jsPDF } = window.jspdf; 155 const pdf = new jsPDF({ format: 'a4' }); 156 const imgData = signaturePad.toDataURL('image/png'); 157 158 // Ajouter les logos en haut du document 159 const logo1 = baseDir + 'img/cms/BONUS/qualirepar.png'; 160 const logo2 = baseDir + 'img/cms/BONUS/ecologic.png'; 161 pdf.addImage(logo1, 'PNG', 20, 20, 50, 20); 162 pdf.addImage(logo2, 'PNG', 140, 20, 50, 16); 163 164 pdf.setFontSize(10); // Réduction de la taille de police 165 166 // Ajouter le texte au centre du document 167 pdf.text("Je, soussigné(e) :", 20, 70); 168 pdf.text("Nom et prénom : " + customer_name, 20, 76); 169 pdf.text("Téléphone : " + customer_phone, 20, 82); 170 pdf.text("Atteste avoir effectué une demande de réparation avec bonus réparation :", 20, 100); 171 pdf.text("Numéro de dossier : " + reference, 20, 110); 172 pdf.text($('#cert_date').text(), 20, 116); 173 pdf.text("Nom de lâentreprise de réparation : SYALEO en visio", 20, 122); 174 pdf.text("Equipement concerné : ", 20, 140); 175 pdf.text("Equipement : " + $('.input_type select option:selected').val() + " " + $('input[name=model]').val(), 20, 146); 176 pdf.text("Marque : " + $('select[name=brand]').val(), 20, 152); 177 pdf.text("Numéro de série : " + ($('.input_type select option:selected').val() == 'Smartphone' ? $('input[name=imei]').val() : $('input[name=serial]').val()), 20, 160); 178 pdf.text("Type de panne : " + $('textarea[name=description]').val(), 20, 166); 179 pdf.text("Le montant du bonus réparation sâélève à :", 20, 190); 180 pdf.text("Montant du bonus : " + $('#cert_bonus_amount').text(), 20, 196); 181 pdf.text("Fait pour servir et valoir ce que de droit.", 20, 210); 182 let d = new Date(prestashop.time * 1000); 183 let options = { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }; 184 let dateStr = d.toLocaleDateString('fr-FR', options); 185 dateStr = dateStr.charAt(0).toUpperCase() + dateStr.slice(1); 186 pdf.text("Date : le " + dateStr, 20, 220); 187 188 // Ajouter la signature en bas 189 pdf.text("Signature:", 20, 250); 190 pdf.addImage(imgData, 'PNG', 20, 230, 150, 40); 191
192 // Convertir le PDF en blob et envoyer au serveur 193 const pdfBlob = pdf.output('blob'); 194 195 //fetch(baseDir + 'modules/brico_bonus_rep/ajax.php?type=certificate', { 196 fetch('modules/brico_bonus_rep/ajax.php?type=certificate&id_bonus=' + id_bonus + '&reference=' + reference, { 197 method: 'POST', 198 body: pdfBlob, 199 headers: { 'Content-Type': 'application/pdf' } 200 }) 201 .then(response => response.json()) 202 .then(data => alert(data.message)) 203 .catch(error => console.error('Erreur:', error)); 204 $('.modal_certificate, .device #save').addClass('hidden'); 205 $('.bonus .appointment .open_calendar').removeAttr('disabled'); 206 $('#loading_frame').fadeOut(1600); 207 refreshHistory(id_bonus); 208 } else { 209 alert("Veuillez dessiner une signature avant d'enregistrer."); 210 } 211 }); 212 */ 213 214 /* ORDER PRODUCTS */ 215 216 /* 217 let nb_products = $('.order_products .op_line').length; 218 if (nb_products == 1) { 219 $('.order_products .op_line').addClass('selected'); 220 } 221 222 $(document).on('click', '.bonus .order .op_line', function() { 223 //if (!$(this).hasClass('locked')) { 224 $('.bonus .order .op_line').removeClass('selected'); 225 $(this).addClass('selected'); 226 let bonus_amount = $(this).data('bonus_amount'); 227 let visio_amount = $(this).data('visio_amount'); 228 let id_product = $(this).data('id_product'); 229 $('.bonus .infos .bonus_amount').html(bonus_amount + '<small>â¬</small>'); 230 $('.bonus .infos .visio_amount').html(visio_amount + '<small>â¬</small>'); 231 $('.bonus .infos .refund_amount').html((bonus_amount - visio_amount).toFixed(2) + '<small>â¬</small>'); 232 $('.bonus .advice .links').addClass('hidden'); 233 $('.bonus .advice .links_' + id_product).removeClass('hidden'); 234 //} 235 }); 236 */ 237 238 /* CALENDAR */ 239 240 $(document).on('click', '.bonus .appointment .open_calendar', function () { 241 242 $('.bonus .appointment .appointment_infos').addClass('hidden'); 243 $('.bonus .appointment #close_calendar, .bonus .appointment .is_order_delivered').removeClass('hidden'); 244 245 }); 246 247 $(document).on('click', '.is_order_delivered .deliv_yes', function() { 248 let device_type = $('.input_type select[name=type]').val(); 249 let order_state = $('.label_state').text(); 250 if (order_state === 'Visio instantanée') { current_state = 100; } 251 $('.bonus .appointment .is_order_delivered').addClass('hidden'); 252 $.ajax({ 253 type: "POST", 254 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=show_calendar', 255 data: {'id_bonus': id_bonus, 'current_state': current_state, 'device_type': device_type}, 256 success: function (calendar) { 257 $('.bonus .appointment .content').append(calendar); 258 } 259 }); 260 }); 261 $(document).on('click', '.is_order_delivered .deliv_no', function() { 262 $('.is_order_delivered .question, .is_order_delivered .deliv_btn').addClass('hidden'); 263 $('.is_order_delivered .response').removeClass('hidden'); 264 }); 265 266 $(document).on('click', '.bonus .appointment #close_calendar', function () { 267 268 $('.bonus .calendar_container').remove(); 269 $('.bonus .appointment #close_calendar, .bonus .appointment .is_order_delivered, .is_order_delivered .response').addClass('hidden'); 270 $('.bonus .appointment .appointment_infos, .is_order_delivered .deliv_btn, .is_order_delivered .question').removeClass('hidden'); 271 272 }); 273 274 $(document).on('click', '.calendar .date', function () { 275 276 let date = $(this).data('date'); 277 $('.calendar .slots_' + date).slideToggle(300); 278 279 }); 280 281 $(document).on('click', '.calendar .slots .slot:not(.taken)', function () { 282 283 let display = $(this).data('display'); 284 let id_tech = $(this).data('id_tech'); 285 let id_slot = $(this).data('id_slot'); 286 let date = $(this).data('date'); 287 let time = $(this).data('time'); 288 let id_product = $('select[name=id_product]').val(); 289 $('.calendar .slots .slot').removeClass('active'); 290 $(this).addClass('active'); 291 $('.calendar_container .confirm').removeClass('hidden'); 292 $('.calendar_container .confirm .selected_date').text(display + ' ' + timeStr
292ing(time.toString())); 293 let data = { 294 'id_bonus': id_bonus, 295 'reference': reference, 296 'id_tech': id_tech, 297 'id_slot': id_slot, 298 'date': date, 299 'time': time, 300 'id_product': id_product, 301 'customer_name': customer_name, 302 'customer_email': customer_email 303 }; 304 305 $(document).on('click', '.calendar_container #confirm_date', function() { 306 307 $('#loading_frame').css({'display': 'flex'}); 308 309 if (data['id_bonus']) { 310 $.ajax({ 311 type: "POST", 312 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=add_visio', 313 data: {data}, 314 dataType: "JSON", 315 success: function (results) { 316 //$('.bonus .order .op_line').addClass('locked'); 317 $('.calendar_container .confirm').addClass('hidden'); 318 $('.calendar_container .slots_container').slideUp(); 319 $('.calendar .slots .slot').removeClass('active'); 320 updateSteps(3); 321 $('.bonus .appointment #tech_name').text(results['tech_name']); 322 $('.bonus .appointment #visio_url').attr('href', 'https://' + results['visio_url']).text(results.visio_url); 323 $('.bonus .photos, .bonus .messages').removeClass('disable'); 324 refreshHistory(data['id_bonus']); 325 refreshStepText('step_3'); 326 data = ''; 327 $('#loading_frame').fadeOut(1600); 328 } 329 }); 330 } 331 332 $('.bonus .calendar_container').remove(); 333 $('.bonus .appointment .no_visio_infos, #close_calendar').addClass('hidden'); 334 $('.bonus .appointment .appointment_infos, .bonus .appointment .visio_infos').removeClass('hidden'); 335 $('.bonus .appointment #visio_dt').text(display[0].toUpperCase() + display.slice(1) + ' ' + timeString(time.toString())); 336 337 }); 338 339 $(document).on('click', '.calendar_container #cancel_date', function() { 340 341 data = ''; 342 $('.calendar .slots .slot').removeClass('active'); 343 $('.calendar_container .confirm').addClass('hidden'); 344 }); 345 346 }); 347 348 /* VALIDATION */ 349 350 $(document).on('click', '#submit_photo_imei', function() { 351 $('.modal_photo_imei').addClass('hidden'); 352 $('.bonus .photos').addClass('upload_imei_photo'); 353 $('.bonus .photos .content').show(); 354 }); 355 $(document).on('click', '#go_to_validation', function() { 356 $('.modal_photo_imei').addClass('hidden'); 357 $('.modal_validation, #back_to_photo_imei').removeClass('hidden'); 358 $('#back_to_photo_imei').on('click', function() { 359 $('.modal_photo_imei').removeClass('hidden'); 360 $('.modal_validation').addClass('hidden'); 361 }); 362 }); 363 $(document).on('click', '#device_unrepaired', function() { 364 $('.modal_photo_imei').addClass('hidden'); 365 $('.modal_validation, #back_to_photo_imei').removeClass('hidden'); 366 $('.modal_validation .choice:first-child()').addClass('disable'); 367 $('#back_to_photo_imei').on('click', function() { 368 $('.modal_photo_imei').removeClass('hidden'); 369 $('.modal_validation').addClass('hidden'); 370 }); 371 }); 372 373 $(document).on('click', '.bonus_modal .vd_ranges .vd_range', function() { 374 $('.bonus_modal .vd_ranges .vd_range .checkbox').removeClass('checked'); 375 $(this).find('.checkbox').addClass('checked'); 376 }); 377 378 $(document).on('click', '.bonus_modal .vr_rates i', function() { 379 let rate = $(this).text(); 380 for (i = 1; i <= rate; i++) { $('.bonus_modal .vr_rates .' + i).addClass('selected'); } 381 for (i = 10; i > rate; i--) { $('.bonus_modal .vr_rates .' + i).removeClass('selected'); } 382 }); 383 384 $(document).on('click', '.bonus_modal', function() { 385 if ( 386 ($('.bonus_modal #repaired').is(':checked') || $('.bonus_modal #unrepaired').is(':checked')) 387 && $('.bonus_modal .vd_range .checkbox').hasClass('checked') 388 && $('.bonus_modal .vr_rates i').hasClass('selected') 389 ) { 390 $('.bonus_modal #submit_validation').attr('disabled', false); 391 } 392 }); 393 394 $(document).on('click', '#submit_validation', function() { 395 396 $('#loading_frame').css({'display': 'flex'}); 397 398 let version = $('input[name=version]').val(); 399 let choice = $('.validation .choice.selected').data('choice'); 400 let visio_duration = $('.bonus_modal .vd_ranges .vd_range .checkbox.checked').data('range'); 401 let visio_rate = $('.bonus_modal .vr_rates i.selected').length; 402 let id_visio = $('input[name=id_visio]').val(); 403 404 $('.bonus .blocks').removeClass('disable') 405 406 $.ajax({ 407 type: "POST", 408 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=validation', 409 data: { 410 'version': version, 411 'id_bonus': id_bonus, 412 'choice': choice, 413 'id_visio': id_visio, 414 'visio_duration': visio_duration, 415 'visio_rate': visio_rate 416 } 417 }); 418 419 if (choice == 'repaired') { 420 /* 421 updateSteps(5); 422 setTimeout(function() { 423 refreshHistory(id_bonus); 424 }, 1500); 425 refreshStepText('step_5'); 426 */ 427 location.reload(true); 428 } 429 if (choice == 'unrepaired') { 430 updateSteps(2); 431 refreshHistory(id_bonus); 432 refreshStepText('step_2'); 433 $('.bonus .appointment .visio_infos').addClass('hidden'); 434 $('.bonus .appointment .no_visio_infos').removeClass('hidden'); 435 } 436 437 $('.modal_validation').addClass('hidden'); 438 $('#loading_frame').fadeOut(1600); 439 440 }); 441 442 /* PHOTOS */ 443 444 $(document).on('change', '.bonus .photos .input_file_photo', function () { 445 446 $('#loading_frame').css({'display': 'flex'}); 447 let id_photo = $(this).data('id_photo'); 448 let photo = document.getElementById('input_photo_' + id_photo).files[0];
449 let name = photo.name; 450 let form_data = new FormData(); 451 let ext = name.split('.').pop().toLowerCase(); 452 let size = photo.size || photo.fileSize; 453 454 if (jQuery.inArray(ext, ['gif', 'png', 'jpg', 'jpeg']) == -1) { 455 $('#loading_frame').fadeOut(1600); 456 $('.bonus .photos .error_message').text('Votre photo doit être au format JPG, PNG ou GIF'); 457 } else if (size > 5000000) { 458 $('#loading_frame').fadeOut(1600); 459 $('.bonus .photos .error_message').text('Votre photo est trop volumineuse (max 5Mo)'); 460 } else { 461 let photo_x = $('#input_photo').data('photo_x'); 462 form_data.append('photo', photo); 463 form_data.append('id_photo', id_photo); 464 form_data.append('id_bonus', id_bonus); 465 form_data.append('reference', reference); 466 form_data.append('ref_order', ref_order); 467 form_data.append('origin', 'client'); 468 form_data.append('customer_name', customer_name); 469 form_data.append('id_tech', id_tech); 470 form_data.append('id_employee', 0); 471 $.ajax({ 472 type: 'POST', 473 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=upload_photo', 474 data: form_data, 475 contentType: false, 476 processData: false, 477 success: function (photo_url) { 478 $('.bonus .photo_' + id_photo + ' label').addClass('hidden'); 479 let thumb = $('.bonus .photos .thumb_' + id_photo); 480 thumb.attr('href', photo_url).html('<img src="' + prestashop.urls.base_url + photo_url + '">'); 481 refreshHistory(id_bonus); 482 if ($('.bonus .photos').hasClass('upload_imei_photo')) { 483 let nb_photos = $(".photos .thumb[href!='']").length; 484 if (nb_photos >= 1) { 485 location.reload(true); 486 } else { 487 $('#loading_frame').fadeOut(1600); 488 } 489 } else { 490 $('#loading_frame').fadeOut(1600); 491 } 492 } 493 }); 494 } 495 496 }); 497 498 $(document).on('mouseenter mouseleave', '.bonus .photos .thumb, .delete_photo_btn', function() { 499 500 let id_photo = $(this).data('id_photo'); 501 $('.delete_photo_btn_' + id_photo).toggleClass('hidden'); 502 503 }); 504 505 $(document).on('click', '.bonus .photos .delete_photo_btn', function () { 506 507 $('#loading_frame').css({'display': 'flex'}); 508 let id_photo = $(this).data('id_photo'); 509 $.ajax({ 510 type: 'POST', 511 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=delete_photo', 512 data: {'id_photo': id_photo, 'id_bonus': id_bonus}, 513 success: function () { 514 $('.bonus .photos .thumb_' + id_photo + ' img').fadeOut(300); 515 $('.bonus .photo_' + id_photo + ' label').removeClass('hidden'); 516 $('.bonus .photos .delete_photo_btn_' + id_photo).addClass('hidden'); 517 $('#loading_frame').fadeOut(1600); 518 } 519 }); 520 521 }); 522 523 /* MESSAGES */ 524 525 $(document).on('click', '.bonus .messages #messages_submit_btn', function () { 526 527 $('#loading_frame').css({'display': 'flex'}); 528 let message = $('#messages_input').val(); 529 let id_tech = $('input[name=id_tech]').val(); 530 531 $.ajax({ 532 type: 'POST', 533 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=add_message', 534 data: { 535 'message': message, 536 'id_bonus': id_bonus, 537 'ref_order': ref_order, 538 'origin': 'client', 539 'customer_name': customer_name, 540 'id_tech': id_tech, 541 'id_employee': 0, 542 'internal': 0, 543 'new': 1 544 }, 545 success: function () { 546 let messages = getMessages(id_bonus); 547 $('.bonus .messages .messages_list').html(messages.responseText); 548 $('.bonus .messages #messages_input').val(''); 549 $('#loading_frame').fadeOut(1600); 550 } 551 }); 552 }); 553 554 $(document).on('click', '.bonus .messages .delete_message', function () { 555 556 $('#loading_frame').css({'display': 'flex'}); 557 let id_message = $(this).data('id_message'); 558 $.ajax({ 559 type: 'POST', 560 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=delete_message', 561 data: {'id_message': id_message}, 562 success: function () { 563 let messages = getMessages(id_bonus); 564 $('.bonus .messages .messages_list').html(messages.responseText); 565 $('#loading_frame').fadeOut(1600); 566 } 567 }); 568 569 }); 570 571 572 /* MOBILE */ 573 574 if ($(window).width() <= 560) { 575 $('.bonus .block .title').on('click', function (e) { 576 if (e.target == this) { 577 $(this).closest('.bonus .block').find('.content').slideToggle(300); 578 } 579 }); 580 } 581 582 583
584 function timeString(time) { 585 if (time.length == 3) { 586 return '0' + time.slice(0, 1) + 'h' + time.slice(1, 3); 587 } else if (time.length == 4) { 588 return time.slice(0, 2) + 'h' + time.slice(2, 4); 589 } 590 } 591 function updateSteps(id) { 592 $('.bonus .steps .step').removeClass('active'); 593 $('.bonus .steps .step#step_' + id).addClass('active'); 594 $('.bonus .infos .state').addClass('hidden'); 595 $('.bonus .infos .state#state_' + id).removeClass('hidden'); 596 } 597 function getStepText(id_step) { 598 return $.ajax({ 599 type: 'POST', 600 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=get_step_text', 601 data: {'id_step': id_step}, 602 async: !1 603 }); 604 } 605 function refreshStepText(id_step) { 606 let step_text = getStepText(id_step); 607 $('.bonus .step_text').html(step_text.responseText); 608 } 609 function getHistory(id_bonus) { 610 return $.ajax({ 611 type: 'POST', 612 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=get_history', 613 data: {'id_bonus': id_bonus}, 614 async: !1 615 }); 616 } 617 function refreshHistory(id_bonus) { 618 setTimeout(function() { 619 let history_lines = getHistory(id_bonus); 620 $('.bonus .history .history_lines').html(history_lines.responseText); 621 }, 2000); 622 } 623 function getMessages(id_bonus) { 624 return $.ajax({ 625 type: 'POST', 626 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=get_messages', 627 data: {'id_bonus': id_bonus, 'internal': false}, 628 async: !1 629 }); 630 } 631 function checkFields() { 632 $('.bonus .invalid').removeClass('invalid'); 633 let empties = []; 634 let brand = $('input[name=brand]').val(); 635 if (brand == '') { empties.push('.input_brand input'); } 636 let model = $('input[name=model]').val(); 637 if (model == '') { empties.push('.input_model input'); } 638 if ($('select[name=type]').val() == 'Smartphone') { 639 let imei = $('input[name=imei]').val(); 640 if (imei == '' || imei.length < 15) { 641 //empties.push('.input_imei'); 642 } 643 } 644 if ($('select[name=type]').val() != 'Smartphone') { 645 let serial = $('input[name=serial]').val(); 646 if (serial == '') { 647 empties.push('.input_serial'); 648 } 649 } 650 let description = $('textarea[name=description]').val(); 651 if (description == '') { empties.push('.input_description textarea'); } 652 let warranty = $('input[name=warranty]:checked').val(); 653 if (!warranty) { 654 empties.push('.input_warranty .radios'); 655 } 656 let insurance = $('input[name=insurance]:checked').val(); 657 if (!insurance) { 658 empties.push('.input_insurance .radios'); 659 } 660 /* 661 let no_product = true; 662 $('.order_products .op_line').each(function() { 663 if ($(this).hasClass('selected')) { 664 no_product = false; 665 } 666 }); 667 if (no_product) { 668 empties.push('.order_products'); 669 } 670 */ 671 for (i = 0; i < empties.length; i++) { 672 $(empties[i]).addClass('invalid'); 673 } 674 if (empties.length == 0) { 675 return true; 676 } 677 } 678 }); 679 680} 681 682if (prestashop.page.page_name == 'product') { 683 684 $(document).on('click', '.custom_flag_bonus', function() { 685 $('#bonus_product_page_modal_background, #bonus_product_page_modal').fadeIn(500); 686 $('body').css({'overflow':'hidden'}); 687 }); 688 $(document).on('click', '#bonus_product_page_modal_background, .bonus_modal_close_btn', function() { 689 $('#bonus_product_page_modal_background, #bonus_product_page_modal').fadeOut(500); 690 $('body').css({'overflow':'auto'}); 691 }); 692 693 /* 694 var $btn = $('#product .add_to_cart_button button'); 695 696 if (window.innerWidth <= 768) { 697 698 var $btn = $('#product .add_to_cart_button button'); 699 var initialOffsetTop = $btn.offset().top; 700 701 $(window).on('scroll', function () { 702 var scrollTop = $(window).scrollTop(); 703 if (scrollTop >= initialOffsetTop - 50) { 704 $btn.addClass('fixed_mobile'); 705 } else { 706 $btn.removeClass('fixed_mobile'); 707 } 708 }); 709 710 } 711 */ 712} 713 714if (prestashop.page.page_name == 'cart') { 715 716 $(document).on('click', '.bonus_ask_quotation .link', function() { 717 $('.bonus_ask_quotation .how_to').slideToggle(500); 718 }); 719 720} 721 722jQuery(document).ready(function () { 723 724 $('input[type="checkbox"][role="select_product_bonus"]').change(function () { 725 console.log('change BONUS'); 726 }); 727 $('input[type="checkbox"][role="select_product_bonus"]').click(function () { 728 console.log('change click BONUS'); 729 }); 730 731 $("[id=brico_add_to_cart]").click(function () { 732 733 $('.add_to_cart_mobile_bottom').addClass('go_down'); 734 735 let $btn = $(this); 736 Swal.fire({ 737 /* title: trans('brico_bonus_rep.add_to_cart'),*/ 738 timerProgressBar: true, 739 didOpen: () => { 740 Swal.showLoading(); 741 } 742 }); 743 $.ajax({ 744 url: baseDir + "module/brico_bonus_rep/cart", 745 data: { 746 ajax: 1, 747 action: 'popup', 748 id_product: $btn.data("product-id") 749 }, 750 success: function (data) { 751 Swal.fire({ 752 width: 640, 753 /*title: "{trans('brico_bonus_rep.add_to_cart')}",*/ 754 html: data, 755 }).then((result) => { 756 $('.add_to_cart_mobile_bottom').removeClass('go_down'); 757 }); 758 $("#brico_add_to_cart_wb").click(function() { 759 $.ajax({ 760 url: baseDir + "module/brico_bonus_rep/cart", 761 data: { 762 ajax: 1, 763 bonus: 1, 764 action: 'addToCart', 765 id_product: $btn.data("product-id") 766 }, 767 success: function (data) { 768 Swal.close(); 769 //prestashop.emit('updateCart', {reason:'bonus'}); 770 prestashop.emit('updateCart', { 771 reason: { 772 idProduct: $btn.data("product-id"), 773 linkAction: 'add-to-cart' 774 } 775 }); 776 } 777 }); 778 }); 779 780 $("#brico_add_to_cart_wtb").click(function() { 781 $.ajax({ 782 url: baseDir + "module/brico_bonus_rep/cart", 783 data: { 784 ajax: 1, 785 bonus: 0, 786 action: 'addToCart', 787 id_product: $btn.data("product-id") 788 }, 789 success: function (data) { 790 Swal.close(); 791 //prestashop.emit('updateCart', {reason:'bonus'}); 792 prestashop.emit('updateCart', { 793 reason: { 794 idProduct: $btn.data("product-id"), 795 linkAction: 'add-to-cart' 796 } 797 }); 798 } 799 800 }); 801 }); 802 803 } 804 }); 805 }); 806 807}); 808 809
810function timeString(time) { 811 if (typeof time === 'string') { 812 if (time.length === 3) { 813 return '0' + time.slice(0, 1) + 'h' + time.slice(1, 3); 814 } else if (time.length === 4) { 815 return time.slice(0, 2) + 'h' + time.slice(2, 4); 816 } 817 } 818 return ''; 819} 820 821 822 823/* BONUS v3 */ 824 825if (prestashop.page.page_name == 'module-brico_bonus_rep-homev3') { 826 827 $(document).ready(function () { 828 829 /* 830 $(function () { 831 const $box = $('.js-bv3-orders'); 832 const $toggle = $('.js-toggle-orders'); 833 const $list = $('.js-orders-list'); 834 835 if ($toggle.length && $list.length) { 836 $toggle.on('click', function (e) { 837 e.stopPropagation(); 838 $list.slideToggle(200); 839 $box.toggleClass('opened'); 840 }); 841 842 $(document).on('click', function (e) { 843 if ($box.hasClass('opened') && !$(e.target).closest('.js-bv3-orders').length) { 844 $list.slideUp(200); 845 $box.removeClass('opened'); 846 } 847 }); 848 } else { 849 console.warn('BV3 dropdown : éléments non trouvés'); 850 } 851 }); 852 */ 853 854 $(document).on('click', '.bv3_orders .select_line.first', function (e) { 855 e.stopPropagation(); 856 $('.bv3_orders .listing').slideToggle(200); 857 $('.bv3_orders').toggleClass('opened'); 858 }); 859 860 $(document).on('click', function (event) { 861 if ($('.bv3_orders').hasClass('opened') && !$(event.target).closest('.bv3_orders').length) { 862 $('.bv3_orders .listing').slideUp(200); 863 $('.bv3_orders').removeClass('opened'); 864 } 865 }); 866 867 $(".bv4_product:not(.no_deb)").on("click", function () { 868 $(".bv4_product").removeClass('selected'); 869 $(this).addClass('selected'); 870 $('#submit_product').removeClass('disabled'); 871 }); 872 873 $(document).on('click', '.block_2 #submit_product', function() { 874 875 let next_block = $(".bv3_block_container.block_3"); 876 next_block.removeClass('hidden').slideDown(600); 877 $('html, body').animate({ 878 scrollTop: next_block.offset().top - ($(window).height() / 3) + (next_block.outerHeight() / 3) 879 }, 800); 880 881 }); 882 883 884 $(document).on('change', ".bv3_infos select[name=device_type]", function () { 885 if ($(this).val() == 'Smartphone') { 886 $('.device_line.imei').removeClass('hidden'); 887 $('.device_line.serial').addClass('hidden'); 888 } else { 889 $('.device_line.imei').addClass('hidden'); 890 $('.device_line.serial').removeClass('hidden'); 891 } 892 }); 893 894 $(document).on('input', 'input[name=device_imei]', function () { 895 const value = this.value.replace(/\D/g, '').slice(0, 15); 896 this.value = value; 897 }); 898 899 $(".bv3_infos .insurance_btn").on("click", function () { 900 $(".bv3_infos .insurance_btn").removeClass('selected'); 901 $(this).addClass('selected'); 902 if ($(this).hasClass('show_alert')) { 903 $('.warranty_alert').removeClass('hidden'); 904 } 905 }); 906 $(document).on('click', '.bv3_infos .warranty_btn', function () { 907 $(".bv3_infos .warranty_btn").removeClass('selected'); 908 $(this).addClass('selected'); 909 if ($(this).hasClass('show_alert')) { 910 $('.warranty_alert').removeClass('hidden'); 911 } 912 }); 913 $(".bv3_infos .water_btn").on("click", function () { 914 $(".bv3_infos .water_btn").removeClass('selected'); 915 $(this).addClass('selected'); 916 if ($(this).hasClass('show_alert')) { 917 $('.warranty_alert').removeClass('hidden'); 918 let id_bonus = $('input[name=id_bonus]').val(); 919 $.ajax({ 920 type: "POST", 921 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=bv3_device_water', 922 data: {'id_bonus': id_bonus} 923 }); 924 } 925 }); 926 927 function checkFields() { 928 const allValid = 929 $('select[name=device_type]').val() && 930 $('select[name=device_brand]').val() && 931 $('input[name=device_model]').val().trim() && 932 $('textarea[name=device_description]').val().trim() && 933 $('.insurance_btn').hasClass('selected') && 934 $('.warranty_btn').hasClass('selected') && 935 $('.water_btn').hasClass('selected'); 936 937 $('#submit_infos').toggleClass('disabled', !allValid); 938 } 939 940 $('select[name=device_type], select[name=device_brand]').on('change', checkFields); 941 $('input[name=device_model], textarea[name=device_description]').on('input', checkFields); 942 $('.insurance_btn, .warranty_btn, .water_btn').on('click', function () { 943 checkFields(); 944 }); 945 946 // SIGNATURE BLOCK 947 let signaturePad; 948 $(document).on('click', '#submit_infos', function () { 949 950 let next_block = $(".bv3_block_container.block_4"); 951 next_block.removeClass('hidden').slideDown(600); 952 $('html, body').animate({ 953 scrollTop: next_block.offset().top - ($(window).height() / 3) + (next_block.outerHeight() / 3) 954 }, 800); 955 956 const canvas = document.getElementById('signature_pad'); 957 signaturePad = new SignaturePad(canvas, { 958 backgroundColor: 'transparent' 959 }); 960 961 function resizeCanvas() { 962 const ratio = Math.max(window.devicePixelRatio || 1, 1); 963 canvas.width = canvas.offsetWidth * ratio; 964 canvas.height = canvas.offsetHeight * ratio; 965 canvas.getContext('2d').scale(ratio, ratio); 966 } 967 968 resizeCanvas(); 969 window.addEventListener('resize', resizeCanvas); 970 971 let wasEmpty = true; 972 973 setInterval(function () { 974 if (!signaturePad.isEmpty() && wasEmpty) { 975 $('#submit_signature').removeClass('disabled'); 976 wasEmpty = false;
977 } else if (signaturePad.isEmpty() && !wasEmpty) { 978 $('#submit_signature').addClass('disabled'); 979 wasEmpty = true; 980 } 981 }, 300); // toutes les 300 ms 982 983 $(document).on('click', '#clear_signature', function () { 984 signaturePad.clear(); 985 $('#submit_signature').addClass('disabled'); 986 }); 987 988 }); 989 990 let id_bonus = ''; 991 let device_type = ''; 992 993 // CALENDAR BLOCK 994 $(document).on('click', '#submit_signature', function () { 995 996 id_bonus = $('input[name=id_bonus]').val(); 997 device_type = $('.bv3_infos select[name=device_type]').val(); //$('.bv3_infos .device.selected').data('device_type'); 998 999 let next_block = $(".bv3_block_container.block_5"); 1000 next_block.removeClass('hidden').slideDown(600); 1001 $('html, body').animate({ 1002 scrollTop: next_block.offset().top - ($(window).height() / 3) + (next_block.outerHeight() / 3) 1003 }, 800); 1004 1005 if (!$('.bv3_calendar .calendar').length) { 1006 $.ajax({ 1007 type: "POST", 1008 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=show_calendar', 1009 data: {'id_bonus': id_bonus, 'current_state': 1, 'device_type': device_type}, 1010 success: function (calendar) { 1011 $('.bonus_v3 .bv3_calendar').html(calendar); 1012 if ($(window).width() < 768) { 1013 $('.bonus_v3 .bv3_calendar .date').each(function () { 1014 let html = $(this).html(); 1015 html = html.replace(/<br\s*\/?>/gi, ' '); 1016 $(this).html(html); 1017 }); 1018 } 1019 } 1020 }); 1021 } 1022 1023 }); 1024 1025 let visio = ''; 1026 1027 $(document).on('click', '.bv3_calendar .slots_container .slot:not(.taken)', function() { 1028 1029 let display = $(this).data('display'); 1030 visio = { 1031 'id_tech': $(this).data('id_tech'), 1032 'id_slot': $(this).data('id_slot'), 1033 'date': $(this).data('date'), 1034 'time': $(this).data('time') 1035 }; 1036 let dtv_string = display + ' ' + timeString(visio['time'].toString()); 1037 $('.bv3_calendar .top_bar, .bv3_calendar .slots_container').addClass('hidden'); 1038 $('.bv3_calendar .confirm_window').removeClass('hidden'); 1039 $('.bv3_calendar .confirm_window .confirm_selected_date').text(dtv_string); 1040 1041 }); 1042 1043 // CREATE VISIO 1044 $(document).on('click', '.bv3_calendar #confirm_date', function() { 1045 1046 let device_imei= ''; 1047 let device_serial = ''; 1048 if (device_type === 'Smartphone') { 1049 device_imei = $('.bv3_infos input[name=device_imei]').val(); 1050 } else { 1051 device_serial = $('.bv3_infos input[name=device_seri
1051al]').val(); 1052 } 1053 let signatureData = signaturePad.toDataURL('image/png'); 1054 1055 $.ajax({ 1056 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=bv3_create_visio', 1057 type: 'POST', 1058 dataType: 'json', 1059 data: { 1060 id_bonus: $('input[name=id_bonus]').val(), 1061 id_product: $('.bv3_product .bv4_product.selected').data('id_product'), 1062 device_type: device_type, 1063 device_brand: $('.bv3_infos select[name=device_brand]').val(), 1064 device_model: $('.bv3_infos input[name=device_model]').val(), 1065 device_imei: device_imei, 1066 device_serial: device_serial, 1067 device_description: $('.bv3_infos textarea[name=device_description]').val(), 1068 device_warranty: $('.bv3_infos .warranty_btn.selected').data('int'), 1069 device_insurance:$('.bv3_infos .insurance_btn.selected').data('int'), 1070 signature_img: signatureData, 1071 visio: visio 1072 }, 1073 success: function (response) { 1074 1075 if (response == 'slot_taken') { 1076 alert("Une erreur est survenue"); 1077 } else { 1078 1079 // BONUS CREATED BLOCK 1080 let next_block = $(".bv3_block_container.block_6"); 1081 next_block.removeClass('hidden').slideDown(600); 1082 $('html, body').animate({ 1083 scrollTop: next_block.offset().top - ($(window).height() / 3) + (next_block.outerHeight() / 3) 1084 }, 800); 1085 1086 $('.bv3_block_container .bv3_block:not(.bv3_block_container.block_1 .bv3_block, .bv3_block_container.block_6 .bv3_block)').addClass('locked'); 1087 1088 $('.bv3_bonus_created #dtv_string').text(response['vdt_string']); 1089 $('.bv3_bonus_created #tech_name').text(response['tech']['firstname']); 1090 $('.bv3_bonus_created #visio_url').attr('href', 'https://' + response['visio_url']).text(response['visio_url']); 1091 1092 } 1093 1094 } 1095 }); 1096 1097 }); 1098 1099 $(document).on('click', '.bv3_calendar .confirm_window #cancel_date', function () { 1100 $('.bv3_calendar .confirm_window, .bv3_calendar .slots_container').addClass('hidden'); 1101 $('.bv3_calendar .top_bar, .bv3_calendar .slots_' + visio['date']).removeClass('hidden'); 1102 visio = ''; 1103 }); 1104 $(document).on('click', '.bv3_calendar .return', function() { 1105 visio = ''; 1106 $('.bv3_calendar .date').removeClass('hidden'); 1107 $('.bv3_calendar .top_bar,' + 1108 '.bv3_calendar .selected_date_container,' + 1109 '.bv3_calendar .slots_container,' + 1110 '.bv3_calendar .confirm_window' 1111 ).addClass('hidden'); 1112 }); 1113 1114 }); 1115 1116} 1117 1118if (prestashop.page.page_name == 'module-brico_bonus_rep-mybonusv3') { 1119 1120 $(document).on('click', '.show_history', function (e) { 1121 e.stopPropagation(); 1122 $('.history_container').slideToggle(200).toggleClass('opened'); 1123 }); 1124 1125 $(document).on('click', function (e) { 1126 const $container = $('.history_container'); 1127 if ($container.hasClass('opened') && !$(e.target).closest('.history_container, .show_history').length) { 1128 $container.slideUp(200).removeClass('opened'); 1129 } 1130 }); 1131 1132 function scrollToBlock(targetClass) { 1133 const $targetEl = $('.block.' + targetClass); 1134 if ($targetEl.length) { 1135 const from_top = $(window).width() < 768 ? 60 : 160; 1136 $('html, body').animate({ 1137 scrollTop: $targetEl.offset().top - from_top 1138 }, 600); 1139 } 1140 } 1141 1142 $(document).on('click', '.steps .step', function () { 1143 const target = $(this).data('target'); 1144 scrollToBlock(target); 1145 }); 1146 1147 $(document).ready(function () { 1148 const hash = window.location.hash; 1149 if (hash) { 1150 scrollToBlock(hash.replace('#', '')); 1151 } 1152 }); 1153 1154 $(document).on('input', 'input[name=device_imei]', function () { 1155 const value = this.value.replace(/\D/g, '').slice(0, 15); 1156 this.value = value; 1157 const length = value.length; 1158 const $counter = $('#imei_counter'); 1159 $counter.css({'opacity':'1'}).text(length + '/15'); 1160 if (length === 15) { 1161 $('#check_imei_btn').prop('disabled', false); 1162 // Retire et rajoute la classe pour redéclencher l'animation 1163 $counter.removeClass('valid'); 1164 // Forcer le "repaint" pour que l'animation puisse rejouer 1165 void $counter[0].offsetWidth; 1166 $counter.addClass('valid'); 1167 } else { 1168 $counter.removeClass('valid'); 1169 $('#check_imei_btn').prop('disabled', true); 1170 } 1171 }); 1172 1173 $(document).on('paste', 'input[name=device_imei]', function(e) { 1174 let clipboardData = e.originalEvent.clipboardData || window.clipboardData; 1175 let pastedData = clipboardData.getData('text'); 1176 if (/\D/.test(pastedData)) { 1177 e.preventDefault(); 1178 } 1179 }); 1180 1181 $(document).on('click', '#check_imei_btn', function() { 1182 let id_bonus = $('input[name=id_bonus]').val(); 1183 let imei = $('input[name=device_imei]').val(); 1184 $.ajax({ 1185 'url': baseDir + 'modules/brico_bonus_rep/ajax.php?type=bv3_check_imei', 1186 'type': 'POST', 1187 'data': { 1188 'id_bonus': id_bonus, 1189 'imei': imei 1190 }, 1191 success: function(result) { 1192 console.log(result); 1193 } 1194 }); 1195 }); 1196 1197 $(document).on('click', '#show_calendar_btn', function() { 1198 1199 let id_bonus = $('input[name=id_bonus]').val(); 1200 let device_type = $('#device_type').text(); 1201 let current_state = $('input[name=id_current_state]').val(); 1202 1203 if (!$('.bv3_calendar .calendar').length) { 1204 $.ajax({ 1205 type: "POST", 1206 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=show_calendar', 1207 data: {'id_bonus': id_bonus, 'current_state': current_state, 'device_type': device_type}, 1208 beforeSend: function () { 1209 $('.appointment').addClass('opened'); 1210 }, 1211 success: function (calendar) { 1212 $('.bv3_calendar').html(calendar); 1213 if ($(window).width() < 768) { 1214 $('.my_bonus_v3 .bv3_calendar .date').each(function () { 1215 let html = $(this).html(); 1216 html = html.replace(/<br\s*\/?>/gi, ' '); 1217 $(this).html(html); 1218 }); 1219 } 1220 } 1221 }); 1222 } 1223 1224 }); 1225 1226 let visio = ''; 1227 1228 $(document).on('click', '.bv3_calendar .slots_container .slot:not(.taken)', function() { 1229 1230 let display = $(this).data('display'); 1231 visio = { 1232 'id_tech': $(this).data('id_tech'), 1233 'id_slot': $(this).data('id_slot'), 1234 'date': $(this).data('date'), 1235 'time': $(this).data('time') 1236 };
1237 let dtv_string = display + ' ' + timeString(visio['time'].toString()); 1238 $('.bv3_calendar .top_bar, .bv3_calendar .slots_container').addClass('hidden'); 1239 $('.bv3_calendar .confirm_window').removeClass('hidden'); 1240 $('.bv3_calendar .confirm_window .confirm_selected_date').text(dtv_string); 1241 1242 }); 1243 1244 $(document).on('click', '.bv3_calendar .confirm_window #cancel_date', function () { 1245 $('.bv3_calendar .confirm_window, .bv3_calendar .slots_container').addClass('hidden'); 1246 $('.bv3_calendar .top_bar, .bv3_calendar .slots_' + visio['date']).removeClass('hidden'); 1247 visio = ''; 1248 }); 1249 $(document).on('click', '.bv3_calendar .return', function() { 1250 visio = ''; 1251 $('.bv3_calendar .date').removeClass('hidden'); 1252 $('.bv3_calendar .top_bar,' + 1253 '.bv3_calendar .selected_date_container,' + 1254 '.bv3_calendar .slots_container,' + 1255 '.bv3_calendar .confirm_window' 1256 ).addClass('hidden'); 1257 }); 1258 1259 $(document).on('click', '.bv3_calendar #confirm_date', function () { 1260 $.ajax({ 1261 url: baseDir + 'modules/brico_bonus_rep/ajax.php?type=bv3_change_visio', 1262 type: 'POST', 1263 dataType: 'json', 1264 data: { 1265 id_bonus: $('input[name=id_bonus]').val(), 1266 id_visio: $('input[name=id_visio]').val(), 1267 visio: visio 1268 }, 1269 success: function (response) { 1270 if (response == 'slot_taken') { 1271 alert("Une erreur est survenue"); 1272 } 1273 location.reload(); 1274 }, 1275 error: function (xhr, status, error) { 1276 alert("Erreur HTTP : " + xhr.status); 1277 } 1278 1279 }); 1280 }); 1281 1282 $(document).on('click', '.validation .choices .choice', function() { 1283 $('.validation .choice').removeClass('selected'); 1284 $(this).addClass('selected'); 1285 $('input[name=choice]').val($(this).data('choice')); 1286 $('.validation .choices').removeClass('orange_1'); 1287 checkFieldsValidation(); 1288 }); 1289 $(document).on('click', '.validation .time_rate .range', function() { 1290 $('.validation .time_rate .range').removeClass('selected'); 1291 $(this).addClass('selected'); 1292 $('input[name=duration]').val($(this).data('range')); 1293 $('.validation .time_container').removeClass('orange_2'); 1294 checkFieldsValidation(); 1295 }); 1296 $(document).on('click', '.validation .time_rate .rate', function() { 1297 $('.validation .time_rate .rate').removeClass('selected'); 1298 $(this).addClass('selected'); 1299 $('input[name=rate]').val($(this).data('rate')); 1300 $('.validation .rate_container').removeClass('orange_2'); 1301 checkFieldsValidation(); 1302 }); 1303 1304 function checkFieldsValidation() { 1305 let choice = $('.validation input[name=choice]').val(); 1306 if (choice == 'repaired') { 1307 if (!imei_serial_photo) { 1308 $('.imei_serial_message').removeClass('hidden'); 1309 } 1310 1311 const allValid = 1312 imei_serial_photo && 1313 $('.validation input[name=choice]').val().trim() && 1314 $('.validation input[name=duration]').val().trim() && 1315 $('.validation input[name=rate]').val().trim(); 1316 1317 $('.validation button[name=submit_validation]').prop('disabled', !allValid); 1318 } 1319 if (choice == 'unrepaired') { 1320 $('.validation .choices, .validation .time_container, .validation .rate_container').removeClass('orange_2') 1321 $('.imei_serial_message').addClass('hidden'); 1322 $('.validation button[name=submit_validation]').prop('disabled', false); 1323 } 1324 } 1325 $(document).on('input change', '.validation input[name=choice], .validation input[name=duration], .validation input[name=rate]', checkFieldsValidation); 1326 1327 // PHOTOS 1328 $('#upload_photo_input').on('change', function () { 1329 if (this.files.length > 0) { 1330 $('#upload_photo_form').submit(); 1331 } 1332 }); 1333 1334} 1335 1336// CALENDAR NAV 1337$(document).on('click', '.bv3_calendar .date', function() { 1338 $('.bv3_calendar .date').addClass('hidden'); 1339 let date_selected = $(this).data('date'); 1340 let date_selected_string = $(this).html().replace('<br>', ' '); 1341 $('.bv3_calendar .slots_' + $(this).data('date')).removeClass('hidden'); 1342 $('.bv3_calendar .top_bar, .sdc_' + date_selected).removeClass('hidden'); 1343 //$('.bv3_calendar .return').removeClass('hidden').find('.selected_date').attr('data-date', date_selected).text(date_selected_string); 1344}); 1345 1346$(document).on('click', '.bv3_calendar .change_day', function() { 1347 1348 $('.bv3_calendar .selected_date_container, .bv3_calendar .slots_container').addClass('hidden'); 1349 let date_selected = $(this).data('date'); 1350 $('.bv3_calendar .slots_container.slots_' + date_selected).removeClass('hidden'); 1351 $('.bv3_calendar .sdc_' + date_selected).removeClass('hidden'); 1352 1353}); 1354 1355 1356 1357 1358$(document).on('click', '#imei_modal_btn', function () { 1359 const $modal = $('#bonus_imei_modal'); 1360 const $modalContent = $('.bonus_modal_mobile_scroll'); 1361 1362 $modal.fadeIn(500); 1363 noScrollBehind('on'); 1364 1365 // â ï¸ Supprime les anciens gestionnaires pour éviter les doublons 1366 $(document).off('mousedown.imeiModal'); 1367 1368 // Ajoute un nom d'espace à l'événement pour pouvoir le retirer proprement 1369 $(document).on('mousedown.imeiModal', function (e) { 1370 if ($modal.is(':visible') && 1371 !$modalContent.is(e.target) && 1372 $modalContent.has(e.target).length === 0) { 1373 $modal.fadeOut(500); 1374 noScrollBehind('off'); 1375 $(document).off('mousedown.imeiModal'); // Nettoyage 1376 } 1377 }); 1378 1379 // Gestion du clic sur la croix 1380 $('.close_modal_btn').off('click').on('click', function () { 1381 $modal.fadeOut(500); 1382 noScrollBehind('off'); 1383 $(document).off('mousedown.imeiModal'); // Nettoyage 1384 }); 1385}); 1386 1387$(document).on('click', '#photos_modal_btn', function () { 1388 const $modal = $('#bonus_photos_modal'); 1389 const $modalContent = $('.bonus_modal_mobile_scroll'); 1390 1391 $modal.fadeIn(500); 1392 noScrollBehind('on'); 1393 1394 // â ï¸ Supprime les anciens gestionnaires pour éviter les doublons 1395 $(document).off('mousedown.photosModal'); 1396 1397 // Ajoute un nom d'espace à l'événement pour pouvoir le retirer proprement 1398 $(document).on('mousedown.photosModal', function (e) { 1399 if ($modal.is(':visible') && 1400 !$modalContent.is(e.target) && 1401 $modalContent.has(e.target).length === 0) { 1402 $modal.fadeOut(500); 1403 noScrollBehind('off'); 1404 $(document).off('mousedown.photosModal'); // Nettoyage 1405 } 1406 }); 1407 1408 // Gestion du clic sur la croix 1409 $('.close_modal_btn').off('click').on('click', function () { 1410 $modal.fadeOut(500); 1411 noScrollBehind('off'); 1412 $(document).off('mousedown.photosModal'); // Nettoyage 1413 }); 1414}); 1415 1416function noScrollBehind(mode) { 1417 if (mode == 'on') { 1418 $('body').css({'overflow': 'hidden'}); 1419 } 1420 if (mode == 'off') { 1421 $('body').css({'overflow': 'auto'}); 1422 } 1423}
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.