1/** 2 * 2007-2017 Leotheme 3 * 4 * NOTICE OF LICENSE 5 * 6 * Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list 7 * 8 * DISCLAIMER 9 * 10 * @Module Name: Leo Feature 11 * @author leotheme <[email protected]> 12 * @copyright 2007-2018 Leotheme 13 * @license http://leotheme.com - prestashop template provider 14 */ 15$(document).ready(function(){ 16 createLeoWishlistModalPopup(); 17 LeoWishlistButtonAction(); 18 if ($('body').is('#product').length == 0) { 19 window.prestashop.on('updateProductList', function() { 20 LeoWishlistButtonAction(); 21 }); 22 } 23 //DONGND:: recall button action if need when change attribute at product page 24 window.prestashop.on('updatedProduct', function() { 25 LeoWishlistButtonAction(); 26 }); 27 window.prestashop.on('clickQuickView', function() { 28 check_active_wishlist = setInterval(function(){ 29 if($('.quickview.modal').length) 30 { 31 $('.quickview.modal').on('shown.bs.modal', function (e) { 32 LeoWishlistButtonAction(); 33 }) 34 clearInterval(check_active_wishlist); 35 } 36 37 }, 300); 38 39 }); 40 41 // $('.quickview.modal').on('shown.bs.modal', function (e) { 42 // console.log('aaa'); 43 // }) 44 activeEventModalWishlist(); 45 LeoListWishlistAction(); 46 $('.leo-save-wishlist-bt').click(function(){ 47 if (!$(this).hasClass('active')) 48 { 49 $(this).addClass('active'); 50 $('.new-wishlist .has-danger .form-control-feedback').html(''); 51 $('.new-wishlist .has-success .form-control-feedback').html(''); 52 var name_wishlist = $.trim($('#wishlist_name').val()); 53 if (!name_wishlist) 54 { 55 $('#wishlist_name').parent().addClass('has-error'); 56 $(this).removeClass('active'); 57 } 58 else 59 { 60 var object_e = $(this); 61 $('#wishlist_name').parent().removeClass('has-error'); 62 $('.leo-save-wishlist-bt-text').hide(); 63 $('.leo-save-wishlist-loading').css({'display':'block'}); 64 $.ajax({ 65 type: 'POST', 66 headers: {"cache-control": "no-cache"}, 67 url: wishlist_url+ '?rand=' + new Date().getTime(), 68 async: true, 69 cache: false, 70 data: { 71 "ajax": 1, 72 "action": "add-wishlist", 73 "name_wishlist": name_wishlist, 74 "token": leo_token 75 }, 76 success: function (result) 77 { 78 var object_result = $.parseJSON(result); 79 if (object_result.errors.length) 80 { 81 // console.log(object_result.errors); 82 $('.new-wishlist .has-success .form-control-feedback').html(''); 83 $('.new-wishlist .has-danger .form-control-feedback').html(object_result.errors).fadeIn(); 84 } 85 else 86 { 87 $('.new-wishlist .has-danger .form-control-feedback').html(''); 88 $('.new-wishlist .has-success .form-control-feedback').html(object_result.result.message).fadeIn(); 89 setTimeout(function() { 90 $('.new-wishlist .has-success .form-control-feedback').fadeOut(); 91 }, 3000); 92 $('#wishlist_name').val(''); 93 94 $('.list-wishlist table tbody').append(object_result.result.wishlist); 95 $('html, body').animate({ 96 scrollTop: $('.list-wishlist table tr.new').offset().top 97 }, 500, function (){ 98 $('.list-wishlist table tr.new').removeClass('new'); 99 }); 100 LeoListWishlistAction(); 101 //DONGND:: reload list product if a wishlist current view 102 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 103 } 104 $('.leo-save-wishlist-bt-text').show(); 105 $('.leo-save-wishlist-loading').hide(); 106 object_e.removeClass('active'); 107 }, 108 error: function (XMLHttpRequest, textStatus, errorThrown) { 109 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 110 } 111 }); 112 113 } 114 } 115 return false; 116 }) 117}); 118 119function createLeoWishlistModalPopup() 120{ 121 var leoWishlistModalPopup = ''; 122 leoWishlistModalPopup += '<div class="modal leo-modal leo-modal-wishlist fade" tabindex="-1" role="dialog" aria-hidden="true">'; 123 leoWishlistModalPopup += '<div class="modal-dialog" role="document">'; 124 leoWishlistModalPopup += '<div class="modal-content">'; 125 leoWishlistModalPopup += '<div class="modal-header">'; 126 leoWishlistModalPopup += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'; 127 leoWishlistModalPopup += '<span aria-hidden="true">×</span>'; 128 leoWishlistModalPopup += '</button>'; 129 leoWishlistModalPopup += '<h5 class="modal-title text-xs-center">'; 130 leoWishlistModalPopup += '</h5>'; 131 leoWishlistModalPopup += '</div>'; 132 leoWishlistModalPopup += '<div class="modal-footer">'; 133 leoWishlistModalPopup += '<button type="button" class="btn btn-secondary" data-dismiss="modal">'+wishlist_cancel_txt+'</button>'; 134 leoWishlistModalPopup += '<button type="button" class="leo-modal-wishlist-bt btn btn-primary">'; 135 leoWishlistModalPopup += '<span class="leo-modal-wishlist-loading cssload-speeding-wheel"></span>'; 136 leoWishlistModalPopup += '<span class="leo-modal-wishlist-bt-text">'; 137 leoWishlistModalPopup += wishlist_ok_txt; 138 leoWishlistModalPopup += '</span>'; 139 leoWishlistModalPopup += '</button>'; 140 leoWishlistModalPopup += '</div>'; 141 leoWishlistModalPopup += '</div>'; 142 leoWishlistModalPopup += '</div>'; 143 leoWishlistModalPopup += '</div>'; 144 $('body').append(leoWishlistModalPopup); 145} 146 147function LeoWishlistButtonAction() 148{ 149 if (!$('.leo-wishlist-button').hasClass('show-list')) 150 { 151 $('.leo-wishlist-button').click(function(){ 152 if (!$('.leo-wishlist-button.active').length) 153 { 154 var id_product = $(this).data('id-product'); 155 var id_wishlist = $(this).data('id-wishlist'); 156 var id_product_attribute = $(this).data('id-product-attribute'); 157 var content_wishlist_mess_remove = wishlist_remove+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 158 var content_wishlist_mess_add = wishlist_add+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 159 160 $(this).addClass('active'); 161 162 if (!isLogged) 163 { 164 //DONGND:: display quicklogin if enable 165 // if ($('.leo-quicklogin').length) 166 // { 167 // $('.leo-quicklogin').first().trigger('click'); 168 // resetButtonAction(); 169 // } 170 // else 171 // {
172 $('.leo-modal-wishlist .modal-title').html(wishlist_loggin_required); 173 $('.leo-modal-wishlist').modal('show'); 174 // } 175 return false; 176 } 177 178 var object_e = $(this); 179 object_e.find('.leo-wishlist-bt-loading').css({'display':'block'}); 180 object_e.find('.leo-wishlist-bt-content').hide(); 181 if ($(this).hasClass('added') || $(this).hasClass('delete')) 182 { 183 //DONGND:: remove product form wishlist 184 $.ajax({ 185 type: 'POST', 186 headers: {"cache-control": "no-cache"}, 187 url: wishlist_url+ '?rand=' + new Date().getTime(), 188 async: true, 189 cache: false, 190 data: { 191 "ajax": 1, 192 "action": "remove", 193 "id_product": id_product, 194 "id_wishlist": id_wishlist, 195 "id_product_attribute": id_product_attribute, 196 "quantity": 1, 197 "token": leo_token 198 }, 199 success: function (result) 200 { 201 var object_result = $.parseJSON(result); 202 if (object_result.errors.length) 203 { 204 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 205 $('.leo-modal-wishlist').modal('show'); 206 } 207 else 208 { 209 //Leotheme add: update number product on icon wishlist after remove from wishlist 210 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 211 { 212 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 213 var new_num_wishlist = old_num_wishlist-1; 214 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 215 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 216 if (new_num_wishlist > 0) { 217 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', ''); 218 } else { 219 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', 'none'); 220 } 221 } 222 223 // compared_products.splice($.inArray(parseInt(id_product), compared_products), 1); 224 if (object_e.hasClass('delete')) 225 { 226 //DONGND:: remove from page wishlist 227 $('td.product-'+id_product).fadeOut(function(){ 228 $(this).remove(); 229 }); 230 } 231 else 232 { 233 //DONGND:: remove from page product list 234 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_remove); 235 $('.leo-modal-wishlist').modal('show'); 236 $('.leo-wishlist-button[data-id-product='+id_product+']').removeClass('added'); 237 $('.leo-wishlist-button[data-id-product='+id_product+']').attr('title',buttonwishlist_title_add); 238 object_e.find('.leo-wishlist-bt-loading').hide(); 239 object_e.find('.leo-wishlist-bt-content').show(); 240 } 241 } 242 }, 243 error: function (XMLHttpRequest, textStatus, errorThrown) { 244 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 245 } 246 }); 247 } 248 else 249 { 250 251 //DONGND:: add product to list product wishlist 252 $.ajax({ 253 type: 'POST', 254 headers: {"cache-control": "no-cache"}, 255 url: wishlist_url+ '?rand=' + new Date().getTime(), 256 async: true, 257 cache: false, 258 data: { 259 "ajax": 1, 260 "action": "add", 261 "id_product": id_product, 262 "id_wishlist": id_wishlist, 263 "id_product_attribute": id_product_attribute, 264 "quantity": 1, 265 "token": leo_token 266 }, 267 success: function (result) 268 { 269 // console.log(result); 270 var object_result = $.parseJSON(result); 271 if (object_result.errors.length) 272 { 273 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 274 $('.leo-modal-wishlist').modal('show'); 275 } 276 else 277 { 278 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_add); 279 $('.leo-modal-wishlist').modal('show'); 280 //Leotheme add: update number product on icon wishlist after add from wishlist 281 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 282 { 283 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 284 var new_num_wishlist = old_num_wishlist+1; 285 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 286 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 287 if (new_num_wishlist > 0) { 288 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', ''); 289 } else { 290 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', 'none'); 291 } 292 } 293 294 // console.log(object_result.result.id_wishlist); 295 //DONGND:: update id wishlist if the first add of user 296 if (id_wishlist == '') 297 { 298 $('.leo-wishlist-button').data('id-wishlist', object_result.result.id_wishlist); 299 // wishlist_products[object_result.result.id_wishlist].push(id_product); 300 } 301 // else 302 // { 303 // wishlist_products[id_wishlist].push(id_product); 304 // } 305 306 $('.leo-wishlist-button[data-id-product='+id_product+']').addClass('added'); 307 $('.leo-wishlist-button[data-id-product='+id_product+']').attr('title',buttonwishlist_title_remove); 308 object_e.find('.leo-wishlist-bt-loading').hide(); 309 object_e.find('.leo-wishlist-bt-content').show(); 310 } 311 312 }, 313 error: function (XMLHttpRequest, textStatus, errorThrown) { 314 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 315 } 316 }); 317 } 318 } 319 return false;
320 }) 321 } 322 else 323 { 324 // $('.leo-wishlist-button').each(function(){ 325 326 // $(this).click(function(e){ 327 328 // e.preventDefault(); 329 // }); 330 // var htmlContent = $(this).next().html(); 331 // $(this).popover({ 332 // placement : 'bottom', //placement of the popover. also can use top, bottom, left or right 333 // title : '', //this is the top title bar of the popover. add some basic css 334 // html: true, //needed to show html of course 335 // content : htmlContent, //this is the content of the html box. add the image here or anything you want really. 336 // template: '<div class="popover popover-list-wishlist" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>' 337 // }); 338 339 // }); 340 341 // $('.popover').popover('hide'); 342 343 // $('.leo-wishlist-button').click(function(){ 344 // if ($(this).hasClass('active')) 345 // { 346 // $(this).next().fadeOut(); 347 // $(this).removeClass('active'); 348 // } 349 // else 350 // { 351 // $('.leo-wishlist-button.active').next().fadeOut(); 352 // $('.leo-wishlist-button.active').removeClass('active'); 353 // $(this).addClass('active'); 354 // $(this).next().fadeIn(); 355 // } 356 357 // return false; 358 // }); 359 360 // $('.popover').on('show.bs.popover' , function () { 361 //DONGND:: add/remove wishlist with list wishlist 362 $('.wishlist-item').click(function(){ 363 if (!$('.wishlist-item.active-add').length) 364 { 365 var id_product = $(this).data('id-product'); 366 var id_wishlist = $(this).data('id-wishlist'); 367 var id_product_attribute = $(this).data('id-product-attribute'); 368 var content_wishlist_mess_remove = wishlist_remove+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 369 var content_wishlist_mess_add = wishlist_add+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 370 371 $(this).addClass('active-add'); 372 373 if (!isLogged) 374 { 375 //DONGND:: display quicklogin if enable 376 // if ($('.leo-quicklogin').length) 377 // { 378 // $('.leo-quicklogin').first().trigger('click'); 379 // resetButtonAction(); 380 // } 381 // else 382 // { 383 $('.leo-modal-wishlist .modal-title').html(wishlist_loggin_required); 384 $('.leo-modal-wishlist').modal('show'); 385 // } 386 return false; 387 } 388 389 var object_e = $(this); 390 var parents_e = object_e.parents('.leo-wishlist-button-dropdown'); 391 parents_e.find('.leo-wishlist-button').addClass('active'); 392 parents_e.find('.leo-wishlist-bt-loading').css({'display':'block'}); 393 parents_e.find('.leo-wishlist-bt-content').hide(); 394 if ($(this).hasClass('added') || $(this).hasClass('delete')) 395 { 396 //DONGND:: remove product form wishlist 397 $.ajax({ 398 type: 'POST', 399 headers: {"cache-control": "no-cache"}, 400 url: wishlist_url+ '?rand=' + new Date().getTime(), 401 async: true, 402 cache: false, 403 data: { 404 "ajax": 1, 405 "action": "remove", 406 "id_product": id_product, 407 "id_wishlist": id_wishlist, 408 "id_product_attribute": id_product_attribute, 409 "quantity": 1, 410 "token": leo_token 411 }, 412 success: function (result) 413 { 414 var object_result = $.parseJSON(result); 415 if (object_result.errors.length) 416 { 417 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 418 $('.leo-modal-wishlist').modal('show'); 419 } 420 else 421 { 422 //Leotheme add: update number product on icon wishlist after remove from wishlist 423 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 424 { 425 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 426 var new_num_wishlist = old_num_wishlist-1; 427 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 428 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 429 if (new_num_wishlist > 0) { 430 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', ''); 431 } else { 432 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', 'none'); 433 } 434 } 435 436 // compared_products.splice($.inArray(parseInt(id_product), compared_products), 1); 437 if (object_e.hasClass('delete')) 438 { 439 //DONGND:: remove from page wishlist 440 $('td.product-'+id_product).fadeOut(function(){ 441 $(this).remove(); 442 }); 443 } 444 else 445 { 446 //DONGND:: remove from page product list
447 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_remove); 448 $('.leo-modal-wishlist').modal('show'); 449 450 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').removeClass('added'); 451 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').attr('title',buttonwishlist_title_add); 452 if (!$('.wishlist-item[data-id-product='+id_product+']').hasClass('added')) 453 { 454 $('.leo-wishlist-button[data-id-product='+id_product+']').removeClass('added'); 455 } 456 457 parents_e.find('.leo-wishlist-bt-loading').hide(); 458 parents_e.find('.leo-wishlist-bt-content').show(); 459 parents_e.find('.leo-wishlist-button').removeClass('active'); 460 } 461 } 462 }, 463 error: function (XMLHttpRequest, textStatus, errorThrown) { 464 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 465 } 466 }); 467 } 468 else 469 { 470 //DONGND:: add product to list product wishlist 471 $.ajax({ 472 type: 'POST', 473 headers: {"cache-control": "no-cache"}, 474 url: wishlist_url+ '?rand=' + new Date().getTime(), 475 async: true, 476 cache: false, 477 data: { 478 "ajax": 1, 479 "action": "add", 480 "id_product": id_product, 481 "id_wishlist": id_wishlist, 482 "id_product_attribute": id_product_attribute, 483 "quantity": 1, 484 "token": leo_token 485 }, 486 success: function (result) 487 { 488 // console.log(result); 489 var object_result = $.parseJSON(result); 490 if (object_result.errors.length) 491 { 492 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 493 $('.leo-modal-wishlist').modal('show'); 494 } 495 else 496 { 497 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_add); 498 $('.leo-modal-wishlist').modal('show'); 499 //Leotheme add: update number product on icon wishlist after add from wishlist 500 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 501 { 502 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 503 var new_num_wishlist = old_num_wishlist+1; 504 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 505 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 506 if (new_num_wishlist > 0) { 507 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', ''); 508 } else { 509 $('.ap-btn-wishlist .js-wishlist-top-bottom_count').css('display', 'none'); 510 } 511 } 512 513 // console.log(object_result.result.id_wishlist); 514 515 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').addClass('added'); 516 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').attr('title',buttonwishlist_title_remove); 517 if (!$('.leo-wishlist-button[data-id-product='+id_product+']').hasClass('added')) 518 { 519 $('.leo-wishlist-button[data-id-product='+id_product+']').addClass('added'); 520 } 521 522 parents_e.find('.leo-wishlist-bt-loading').hide(); 523 parents_e.find('.leo-wishlist-bt-content').show(); 524 parents_e.find('.leo-wishlist-button').removeClass('active'); 525 } 526 527 }, 528 error: function (XMLHttpRequest, textStatus, errorThrown) { 529 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 530 } 531 }); 532 } 533 } 534 return false; 535 }); 536 // }); 537 538 } 539 540} 541 542function LeoListWishlistAction() 543{ 544 //DONGND:: click delete wishlist 545 $('.delete-wishlist').click(function(){ 546 if (!$(this).hasClass('active')) 547 { 548 $(this).addClass('active'); 549 $(this).parents('tr').addClass('active'); 550 if ($('.list-wishlist tr.active .default-wishlist').is(":checked")) 551 {
552 $('.leo-modal-wishlist .modal-title').html(wishlist_del_default_txt); 553 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 554 } 555 else 556 { 557 $('.leo-modal-wishlist .modal-title').html(wishlist_confirm_del_txt); 558 $('.leo-modal-wishlist').addClass('enable-action').modal('show'); 559 } 560 } 561 562 return false; 563 }); 564 565 //DONGND:: confirm delete wishlist 566 $('.leo-modal-wishlist-bt').click(function(){ 567 if (!$(this).hasClass('active')) 568 { 569 // console.log('test'); 570 $(this).addClass('active'); 571 var object_e = $(this); 572 var id_wishlist = $('.delete-wishlist.active').data('id-wishlist'); 573 $('.leo-modal-wishlist-bt-text').hide(); 574 $('.leo-modal-wishlist-loading').css({'display':'block'}); 575 576 $.ajax({ 577 type: 'POST', 578 headers: {"cache-control": "no-cache"}, 579 url: wishlist_url+ '?rand=' + new Date().getTime(), 580 async: true, 581 cache: false, 582 data: { 583 "ajax": 1, 584 "action": "delete-wishlist", 585 "id_wishlist": id_wishlist, 586 "token": leo_token 587 }, 588 success: function (result) 589 { 590 var object_result = $.parseJSON(result); 591 if (object_result.errors.length) 592 { 593 594 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 595 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 596 } 597 else 598 { 599 var object_delete = $('.list-wishlist tr.active'); 600 $('.leo-modal-wishlist').modal('hide'); 601 object_delete.fadeOut(function(){ 602 if ($(this).hasClass('show')) 603 { 604 $('.leo-wishlist-product').fadeOut().html(''); 605 } 606 else 607 { 608 //DONGND:: reload list product if a wishlist current view 609 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 610 } 611 $(this).remove(); 612 }) 613 614 } 615 $('.leo-modal-wishlist-loading').hide(); 616 $('.leo-modal-wishlist-bt-text').show(); 617 object_e.removeClass('active'); 618 619 }, 620 error: function (XMLHttpRequest, textStatus, errorThrown) { 621 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 622 } 623 }); 624 } 625 }) 626 627 //DONGND:: change default wishlist 628 $('.default-wishlist').click(function(){ 629 if ($(this).is(":checked")) 630 { 631 // console.log('test'); 632 if (!$('.default-wishlist.active').length) 633 { 634 $(this).addClass('active'); 635 var object_e = $(this); 636 var id_wishlist = $('.default-wishlist.active').data('id-wishlist'); 637 $.ajax({ 638 type: 'POST', 639 headers: {"cache-control": "no-cache"}, 640 url: wishlist_url+ '?rand=' + new Date().getTime(), 641 async: true, 642 cache: false, 643 data: { 644 "ajax": 1, 645 "action": "default-wishlist", 646 "id_wishlist": id_wishlist, 647 "token": leo_token 648 }, 649 success: function (result) 650 { 651 var object_result = $.parseJSON(result); 652 if (object_result.errors.length) 653 { 654 655 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 656 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 657 } 658 else 659 { 660 $('.default-wishlist:checked').removeAttr('checked'); 661 object_e.prop('checked', true); 662 } 663 664 object_e.removeClass('active'); 665 666 }, 667 error: function (XMLHttpRequest, textStatus, errorThrown) { 668 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 669 } 670 }); 671 } 672 } 673 // else 674 // { 675 // console.log('test1'); 676 677 // } 678 return false; 679 }) 680 681 //DONGND:: show list product of wishlist 682 $('.view-wishlist-product').click(function(){ 683 if (!$('.view-wishlist-product.active').length) 684 { 685 $(this).addClass('active'); 686 $(this).next('.leo-view-wishlist-product-loading').show(); 687 $('.list-wishlist tr.show').removeClass('show'); 688 $(this).parents('tr').addClass('show'); 689 var object_e = $(this); 690 var id_wishlist = $(this).data('id-wishlist'); 691 // $('.send-wishlist').fadeOut(); 692 // $('.leo-wishlist-product').fadeOut(function(){ 693 //$('.leo-wishlist-product').html(''); 694 $.ajax({ 695 type: 'POST', 696 headers: {"cache-control": "no-cache"}, 697 url: wishlist_url+ '?rand=' + new Date().getTime(), 698 async: true, 699 cache: false, 700 data: { 701 "ajax": 1, 702 "action": "show-wishlist-product", 703 "id_wishlist": id_wishlist, 704 "token": leo_token 705 }, 706 success: function (result) 707 { 708 var object_result = $.parseJSON(result); 709 if (object_result.errors.length) 710 { 711
712 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 713 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 714 } 715 else 716 { 717 $('.leo-wishlist-product').hide(); 718 $('.leo-wishlist-product').html(object_result.result.html).fadeIn(); 719 if (object_result.result.show_send_wishlist) 720 { 721 $('.send-wishlist').fadeIn(); 722 // LeoWishlistButtonAction(); 723 if (!$('.leo-modal-send-wishlist').length) 724 { 725 createLeoSendWishlistModalPopup(); 726 LeoListWishlistProductModalAction(); 727 } 728 else 729 { 730 $('.leo-modal-reset-send-wishlist-bt').trigger('click'); 731 } 732 LeoListWishlistProductAction(); 733 734 } 735 else 736 { 737 $('.send-wishlist').hide(); 738 } 739 refeshWishlist(id_wishlist); 740 741 } 742 743 object_e.removeClass('active'); 744 object_e.next('.leo-view-wishlist-product-loading').hide(); 745 746 }, 747 error: function (XMLHttpRequest, textStatus, errorThrown) { 748 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 749 } 750 }); 751 // }) 752 } 753 return false; 754 }) 755} 756function LeoListWishlistProductModalAction() 757{ 758 //DONGND:: send wishlist 759 $('.leo-send-wishlist-button').click(function(){ 760 var name_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('name-wishlist'); 761 $('.leo-modal-send-wishlist .modal-title').html(wishlist_send_wishlist_txt+' "'+name_wishlist+'"'); 762 $('.leo-modal-send-wishlist').modal('show'); 763 764 return false; 765 }) 766 767 $('.leo-modal-send-wishlist').submit(function(){ 768 // if ($(this).find('.form-group.leo-has-error').length) 769 if ($('.leo-fake-send-wishlist-button').hasClass('validate-ok')) 770 { 771 return false; 772 } 773 }); 774 775 //DONGND:: submit send wishlist 776 $('.leo-modal-send-wishlist-bt').click(function(){ 777 if (!$(this).hasClass('active')) 778 { 779 var check_submit_wishlist = true; 780 var list_email = []; 781 $(this).addClass('active'); 782 var object_e = $(this); 783 $('.leo-modal-reset-send-wishlist-bt').fadeOut(); 784 785 $('.wishlist_email').each(function(key, val){ 786 if ($(this).val() !== '' && !$(this).parents('.form-group').hasClass('has-success') && !$(this).parents('.form-group').hasClass('has-warning')) 787 { 788 if (!validateEmail($(this).val())) 789 { 790 $(this).parents('.form-group').addClass('leo-has-error'); 791 check_submit_wishlist = false; 792 } 793 else 794 { 795 $(this).parents('.form-group').removeClass('leo-has-error'); 796 list_email.push(key); 797 } 798 } 799 800 }) 801 // console.log(check_submit_wishlist); 802 if (check_submit_wishlist) 803 { 804 // if (list_email.length == 0) 805 // console.log(list_email.length); 806 // console.log(list_email); 807 if (list_email.length == 0) 808 { 809 $('.wishlist_email').each(function(key, val){ 810 if ($(this).val() == '') 811 { 812 $(this).parents('.form-group').addClass('leo-has-error'); 813 $(this).attr("required", ""); 814 return false; 815 } 816 }) 817 object_e.removeClass('active'); 818 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 819 } 820 else 821 { 822 $('.leo-fake-send-wishlist-button').addClass('validate-ok'); 823 var id_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('id-wishlist'); 824 // console.log(list_email); 825 826 $('.leo-modal-send-wishlist-bt-text').hide(); 827 $('.leo-modal-send-wishlist-loading').css({'display':'block'}); 828 829 $.each(list_email,function(key, val){ 830 var index_wishlist_email = val + 1; 831 var email = $('#wishlist_email_'+index_wishlist_email).val(); 832 var object_parent_e = $('#wishlist_email_'+index_wishlist_email).parents('.form-group'); 833 object_parent_e.find('.wishlist_email_status_loading').show(); 834 835 $.ajax({ 836 type: 'POST', 837 headers: {"cache-control": "no-cache"}, 838 url: wishlist_url+ '?rand=' + new Date().getTime(), 839 async: true, 840 cache: false, 841 data: { 842 "ajax": 1, 843 "action": "send-wishlist", 844 "id_wishlist": id_wishlist, 845 "email": email, 846 "token": leo_token 847 }, 848 success: function (result) 849 { 850 object_parent_e.find('.wishlist_email_status_loading').hide(); 851 var object_result = $.parseJSON(result); 852 if (object_result.errors.length) 853 { 854 object_parent_e.addClass('has-warning').find('.send_wishlist_error').fadeIn(); 855 } 856 else 857 { 858 object_parent_e.addClass('has-success').find('.send_wishlist_success').fadeIn(); 859 } 860 861 }, 862 error: function (XMLHttpRequest, textStatus, errorThrown) { 863 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 864 } 865 }); 866 867 }); 868 $(document).ajaxStop(function() { 869 // console.log('test'); 870 $('.leo-modal-send-wishlist-loading').hide(); 871 $('.leo-modal-send-wishlist-bt-text').show(); 872 $('.leo-fake-send-wishlist-button').removeClass('validate-ok'); 873 object_e.removeClass('active'); 874 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 875 }); 876 877 } 878 if ($('.form-send-wishlist .form-group.leo-has-error').length) 879 { 880 $('.leo-fake-send-wishlist-button').trigger('click'); 881 } 882 } 883 else 884 {
885 object_e.removeClass('active'); 886 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 887 $('.leo-fake-send-wishlist-button').trigger('click'); 888 } 889 890 } 891 }) 892 893 //DONGND:: reset from send wishlist 894 $('.leo-modal-reset-send-wishlist-bt').click(function(){ 895 $('.wishlist_email').val('').removeAttr('required'); 896 $('.send_wishlist_form_content .form-group').removeClass('leo-has-error has-success has-warning'); 897 $('.wishlist_email_status_loading').fadeOut(); 898 $('.send_wishlist_msg').fadeOut(); 899 }) 900} 901 902function LeoListWishlistProductAction() 903{ 904 //DONGND:: delete product of wishlist 905 $('.leo-wishlist-button-delete').click(function(){ 906 if (!$(this).hasClass('active')) 907 { 908 $(this).addClass('active'); 909 var object_e = $(this); 910 var object_parent_e = object_e.parents('.leo-wishlist-product'); 911 var id_wishlist_product = $(this).data('id-wishlist-product'); 912 var id_wishlist = $(this).data('id-wishlist'); 913 $.ajax({ 914 type: 'POST', 915 headers: {"cache-control": "no-cache"}, 916 url: wishlist_url+ '?rand=' + new Date().getTime(), 917 async: true, 918 cache: false, 919 data: { 920 "ajax": 1, 921 "action": "delete-wishlist-product", 922 "id_wishlist": id_wishlist, 923 "id_wishlist_product": id_wishlist_product, 924 "token": leo_token 925 }, 926 success: function (result) 927 { 928 var object_result = $.parseJSON(result); 929 if (object_result.errors.length) 930 { 931 932 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 933 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 934 } 935 else 936 { 937 object_e.parents('.leo-wishlistproduct-item').fadeOut(function(){ 938 $(this).remove(); 939 // console.log(object_parent_e); 940 // console.log(object_parent_e.find('.leo-wishlistproduct-item')); 941 // console.log(object_parent_e.find('.leo-wishlistproduct-item').length); 942 if (!object_parent_e.find('.leo-wishlistproduct-item').length) 943 { 944 $('.send-wishlist').hide(); 945 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 946 } 947 }) 948 refeshWishlist(id_wishlist); 949 } 950 951 object_e.removeClass('active'); 952 953 }, 954 error: function (XMLHttpRequest, textStatus, errorThrown) { 955 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 956 } 957 }); 958 } 959 return false; 960 }) 961 962 //DONGND:: 963 $('.leo-wishlist-product-save-button').click(function(){ 964 if (!$(this).hasClass('active')) 965 { 966 $(this).addClass('active'); 967 var object_e = $(this); 968 var id_wishlist_product = $(this).data('id-wishlist-product'); 969 var id_wishlist = $(this).data('id-wishlist'); 970 // $('.leo-wishlistproduct-item-'+id_wishlist_product).addClass('update'); 971 var quantity = $('.wishlist-product-quantity-'+id_wishlist_product).val(); 972 var priority = $('.wishlist-product-priority-'+id_wishlist_product).val(); 973 974 if(Math.floor(quantity) == quantity && $.isNumeric(quantity) && quantity > 0) 975 { 976 $('.wishlist-product-quantity-'+id_wishlist_product).parents('.form-group').removeClass('has-error'); 977 $.ajax({ 978 type: 'POST', 979 headers: {"cache-control": "no-cache"}, 980 url: wishlist_url+ '?rand=' + new Date().getTime(), 981 async: true, 982 cache: false, 983 data: { 984 "ajax": 1, 985 "action": "update-wishlist-product", 986 "id_wishlist": id_wishlist, 987 "id_wishlist_product": id_wishlist_product, 988 "quantity": quantity, 989 "priority": priority, 990 "token": leo_token 991 }, 992 success: function (result) 993 { 994 var object_result = $.parseJSON(result); 995 if (object_result.errors.length) 996 { 997 998 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 999 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1000 } 1001 else 1002 { 1003 $('.leo-wishlistproduct-item-'+id_wishlist_product).hide(); 1004 $('.leo-wishlistproduct-item-'+id_wishlist_product).fadeIn(); 1005 refeshWishlist(id_wishlist); 1006 } 1007 1008 object_e.removeClass('active'); 1009 1010 }, 1011 error: function (XMLHttpRequest, textStatus, errorThrown) { 1012 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 1013 } 1014 }); 1015 } 1016 else 1017 {
1018 $('.wishlist-product-quantity-'+id_wishlist_product).parents('.form-group').addClass('has-error'); 1019 $('.leo-modal-wishlist .modal-title').html(wishlist_quantity_required); 1020 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1021 object_e.removeClass('active'); 1022 } 1023 } 1024 return false; 1025 }) 1026 1027 $('.move-wishlist-item').click(function(){ 1028 if (!$(this).hasClass('active')) 1029 { 1030 $(this).addClass('active'); 1031 var object_e = $(this); 1032 var object_parent_e = object_e.parents('.leo-wishlist-product'); 1033 var id_wishlist_product = $(this).data('id-wishlist-product'); 1034 var id_product = $(this).data('id-product'); 1035 var id_product_attribute = $(this).data('id-product-attribute'); 1036 var id_old_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('id-wishlist'); 1037 var id_new_wishlist = $(this).data('id-wishlist'); 1038 var priority = $('.wishlist-product-priority-'+id_wishlist_product).val(); 1039 var quantity = $('.wishlist-product-quantity-'+id_wishlist_product).val(); 1040 $.ajax({ 1041 type: 'POST', 1042 headers: {"cache-control": "no-cache"}, 1043 url: wishlist_url+ '?rand=' + new Date().getTime(), 1044 async: true, 1045 cache: false, 1046 data: { 1047 "ajax": 1, 1048 "action": "move-wishlist-product", 1049 "id_new_wishlist": id_new_wishlist, 1050 "id_wishlist_product": id_wishlist_product, 1051 "id_old_wishlist": id_old_wishlist, 1052 "id_product" : id_product, 1053 "id_product_attribute": id_product_attribute, 1054 "quantity": quantity, 1055 "priority": priority, 1056 "token": leo_token 1057 }, 1058 success: function (result) 1059 { 1060 var object_result = $.parseJSON(result); 1061 if (object_result.errors.length) 1062 { 1063 1064 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 1065 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1066 } 1067 else 1068 { 1069 object_e.parents('.leo-wishlistproduct-item').fadeOut(function(){ 1070 $(this).remove(); 1071 if (!object_parent_e.find('.leo-wishlistproduct-item').length) 1072 { 1073 $('.send-wishlist').hide(); 1074 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 1075 } 1076 }); 1077 refeshWishlist(id_new_wishlist); 1078 refeshWishlist(id_old_wishlist); 1079 } 1080 1081 object_e.removeClass('active'); 1082 1083 }, 1084 error: function (XMLHttpRequest, textStatus, errorThrown) { 1085 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 1086 } 1087 }); 1088 } 1089 return false; 1090 }) 1091} 1092 1093function activeEventModalWishlist() 1094{ 1095 $('.leo-modal-wishlist').on('hide.bs.modal', function (e) { 1096 resetButtonAction(); 1097 }) 1098 1099 $('.leo-modal-wishlist').on('hidden.bs.modal', function (e) { 1100 $('body').css('padding-right', ''); 1101 }) 1102 $('.leo-modal-wishlist').on('show.bs.modal', function (e) { 1103 if ($('.quickview.modal').length) 1104 { 1105 $('.quickview.modal').modal('hide'); 1106 } 1107 1108 }); 1109} 1110 1111//DONGND:: reset button add wishlist after click 1112function resetButtonAction(){ 1113 // console.log($('.leo-modal-review-bt').length); 1114 if ($('.leo-wishlist-button.active').length) 1115 { 1116 // console.log('aaa'); 1117 $('.leo-wishlist-button.active').removeClass('active'); 1118 } 1119 1120 if ($('.wishlist-item.active-add').length) 1121 { 1122 // console.log('aaa'); 1123 $('.wishlist-item.active-add').removeClass('active-add'); 1124 } 1125 // $('.leo-list-wishlist').fadeOut(); 1126 $('.default-wishlist.active').removeClass('active'); 1127 $('.delete-wishlist.active').removeClass('active'); 1128 1129 $('.list-wishlist tr.active').removeClass('active'); 1130 1131 // $('.leo-modal-wishlist').removeClass('enable-action'); 1132} 1133 1134function createLeoSendWishlistModalPopup() 1135{ 1136 var leoSendWishlistModalPopup = ''; 1137 leoSendWishlistModalPopup += '<div class="modal leo-modal leo-modal-send-wishlist fade" tabindex="-1" role="dialog" aria-hidden="true">'; 1138 leoSendWishlistModalPopup += '<div class="modal-dialog" role="document">'; 1139 leoSendWishlistModalPopup += '<div class="modal-content">'; 1140 leoSendWishlistModalPopup += '<div class="modal-header">'; 1141 leoSendWishlistModalPopup += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'; 1142 leoSendWishlistModalPopup += '<span aria-hidden="true">×</span>'; 1143 leoSendWishlistModalPopup += '</button>'; 1144 leoSendWishlistModalPopup += '<h5 class="modal-title text-xs-center">'; 1145 leoSendWishlistModalPopup += '</h5>'; 1146 leoSendWishlistModalPopup += '</div>'; 1147 leoSendWishlistModalPopup += '<div class="modal-body">'; 1148 leoSendWishlistModalPopup += '<div class="send_wishlist_form_content">'; 1149 leoSendWishlistModalPopup += '<form class="form-send-wishlist" action="#" method="post">' 1150 for (var $i=1; $i<= 10; $i++) 1151 { 1152 leoSendWishlistModalPopup += '<div class="form-group row">'; 1153 leoSendWishlistModalPopup += '<label class="col-form-label col-sm-2 text-sm-left" for="wishlist_email_'+$i+'">'+wishlist_email_txt+' '+$i+'</label>'; 1154 leoSendWishlistModalPopup += '<div class="wishlist_email_status col-sm-1">'; 1155 leoSendWishlistModalPopup += '<div class="wishlist_email_status_loading cssload-speeding-wheel">'; 1156 leoSendWishlistModalPopup += '</div>'; 1157 leoSendWishlistModalPopup += '<i class="send_wishlist_msg send_wishlist_success material-icons"></i>'; 1158 leoSendWishlistModalPopup += '<i class="send_wishlist_msg send_wishlist_error material-icons"></i>'; 1159 leoSendWishlistModalPopup += '</div>'; 1160 leoSendWishlistModalPopup += '<div class="col-sm-9">'; 1161 leoSendWishlistModalPopup += '<input class="form-control wishlist_email" id="wishlist_email_'+$i+'" name="wishlist_email_'+$i+'" type="email">'; 1162 leoSendWishlistModalPopup += '</div>'; 1163 leoSendWishlistModalPopup += '</div>'; 1164 } 1165 leoSendWishlistModalPopup += '<button class="btn btn-primary form-control-submit leo-fake-send-wishlist-button pull-xs-right" type="submit"></button>'; 1166 leoSendWishlistModalPopup += '</form>'; 1167 leoSendWishlistModalPopup += '</div>'; 1168 leoSendWishlistModalPopup += '</div>'; 1169 leoSendWishlistModalPopup += '<div class="modal-footer">'; 1170 leoSendWishlistModalPopup += '<button type="button" class="btn btn-primary leo-modal-reset-send-wishlist-bt">'+wishlist_reset_txt+'</button>'; 1171 leoSendWishlistModalPopup += '<button type="button" class="btn btn-secondary" data-dismiss="modal">'+wishlist_cancel_txt+'</button>'; 1172 leoSendWishlistModalPopup += '<button type="button" class="leo-modal-send-wishlist-bt btn btn-primary">'; 1173 leoSendWishlistModalPopup += '<span class="leo-modal-send-wishlist-loading cssload-speeding-wheel"></span>'; 1174 leoSendWishlistModalPopup += '<span class="leo-modal-send-wishlist-bt-text">'; 1175 leoSendWishlistModalPopup += wishlist_send_txt; 1176 leoSendWishlistModalPopup += '</span>'; 1177 leoSendWishlistModalPopup += '</button>'; 1178 leoSendWishlistModalPopup += '</div>'; 1179 leoSendWishlistModalPopup += '</div>'; 1180 leoSendWishlistModalPopup += '</div>'; 1181 leoSendWishlistModalPopup += '</div>';
1182 $('body').append(leoSendWishlistModalPopup); 1183} 1184 1185function validateEmail(email) { 1186 // var regex = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 1187 // return regex.test(email); 1188 var reg = /^[a-z\p{L}0-9!#$%&'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/i; 1189 return reg.test(email); 1190} 1191 1192//DONGND:: update quantity of wishlist 1193function refeshWishlist(id_wishlist) 1194{ 1195 $('.leo-view-wishlist-product-loading-'+id_wishlist).show(); 1196 $.ajax({ 1197 type: 'POST', 1198 headers: {"cache-control": "no-cache"}, 1199 url: wishlist_url+ '?rand=' + new Date().getTime(), 1200 async: true, 1201 cache: false, 1202 data: { 1203 "ajax": 1, 1204 "action": "get-wishlist-info", 1205 "id_wishlist": id_wishlist, 1206 "token": leo_token 1207 }, 1208 success: function (result) 1209 { 1210 var object_result = $.parseJSON(result); 1211 if (object_result.errors.length) 1212 { 1213 1214 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 1215 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1216 } 1217 else 1218 { 1219 $('.wishlist-numberproduct-'+id_wishlist).html(object_result.result.number_product); 1220 } 1221 $('.leo-view-wishlist-product-loading-'+id_wishlist).hide(); 1222 }, 1223 error: function (XMLHttpRequest, textStatus, errorThrown) { 1224 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 1225 } 1226 }); 1227}
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.