var json_save_note = {}; var modalEl = document.getElementById('modalNote'); if(modalEl) { var modalNote = new bootstrap.Modal(modalEl); } function toggleTextBlackIconNote(product_id, mag, action, id_cart_row_note){ if (document.getElementById('icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note)) { if(action == 'add') { $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).removeClass('text-black-50'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).removeClass('far'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).addClass('text-black'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).addClass('fa'); } if(action == 'remove') { $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).removeClass('text-black'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).removeClass('fa'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).addClass('text-black-50'); $('#icon-note-prod-' + product_id + '-mag-' + mag + '-' + id_cart_row_note).addClass('far'); } } } function modalHide(){ if (modalNote) { modalNote.hide(); } } function showModal(exist_note, el){ if(exist_note){ $("#iconNote").val(el[0].id); $('.js-save-cart-note-btn').addClass('d-none'); $('.js-mod-cart-note-btn').removeClass('d-none'); $('.js-canc-cart-note-btn').removeClass('d-none'); } else { $("#iconNote").val(''); $('.js-mod-cart-note-btn').addClass('d-none'); $('.js-canc-cart-note-btn').addClass('d-none'); $('.js-save-cart-note-btn').removeClass('d-none'); } modalNote.show(); } function getNotesFromIdProduct(product_id, mag, warehouse_id, company_address_id, qta, id_cart_row, el){ var exist_note = false; $.ajax({ url: "https://staging-fabrics.piacenza1733.com/assets/ajax/get-cart.php", type: "POST", success: function (data) { if(data.status == "success") { data.products.forEach(function (product) { if (product.product_id == product_id && product.cart_id == id_cart_row) { if (mag == 'it') { if (product.note_warehouse_1 != '' && product.note_warehouse_1 != ' ' && product.note_warehouse_1 != null && product.note_warehouse_1 != undefined) { $('#js-note-textarea').val(product.note_warehouse_1); exist_note = true; } else { $('#js-note-textarea').val(''); } } if (mag == 'hk') { if (product.note_warehouse_2 != '' && product.note_warehouse_2 != ' ' && product.note_warehouse_2 != null && product.note_warehouse_2 != undefined) { $('#js-note-textarea').val(product.note_warehouse_2); exist_note = true; } else { $('#js-note-textarea').val(''); } } $('#id_cart_row_note').val(id_cart_row); } }); json_save_note = { "warehouse_id": warehouse_id, "quantity": qta, "company_address_id": company_address_id } showModal(exist_note, el); } else if (data.status == "error"){ if (data.reload != ''){ setTimeout(function (){ location.reload() }, 1000); } } } }); } $(document).ready(function() { if ($('.js-add-cart-note i.it').length > 0) { $('.js-add-cart-note i.it').each(function() { var $this = $(this); $this.on('click', function() { const product_id = $(this).closest('.js-add-cart-note').data('product-id'); const warehouse_id = $(this).closest('.js-add-cart-note').data('warehouse-id'); const company_address_id = $(this).closest('.js-add-cart-note').data('company-address-id'); const id_cart_row = $(this).closest('.js-add-cart-note').data('id-cart-row'); const qta = $(this).closest('.js-add-cart-note').data('qta'); $('#note_product_id').val(product_id); $('#note_mag').val('it'); getNotesFromIdProduct(product_id, 'it', warehouse_id, company_address_id, qta, id_cart_row, $this); }); }); } if ($('.js-add-cart-note i.hk').length > 0) { $('.js-add-cart-note i.hk').each(function() { var $this = $(this); $this.on('click', function() { const product_id = $(this).closest('.js-add-cart-note').data('product-id'); const warehouse_id = $(this).closest('.js-add-cart-note').data('warehouse-id'); const company_address_id = $(this).closest('.js-add-cart-note').data('company-address-id'); const qta = $(this).closest('.js-add-cart-note').data('qta'); const id_cart_row = $(this).closest('.js-add-cart-note').data('id-cart-row'); $('#note_product_id').val(product_id); $('#note_mag').val('hk'); getNotesFromIdProduct(product_id, 'hk', warehouse_id, company_address_id, qta, id_cart_row, $this); }); }); } if ($('.js-save-cart-note').length > 0) { $('.js-save-cart-note').on('click', function(){ var nota = document.getElementById('js-note-textarea'); var product_id = document.getElementById('note_product_id').value; var mag = document.getElementById('note_mag').value; var id_cart_row_note = document.getElementById('id_cart_row_note').value; var el = document.querySelector('#icon-note-prod-'+product_id+'-mag-'+mag+'-'+id_cart_row_note); if(nota){ prepareQuantity(true, false, product_id, nota.value, el, 0, id_cart_row_note, mag); if(nota.value != '' && nota.value != ' ' && nota.value != null && nota.value != undefined){ toggleTextBlackIconNote(product_id, mag, 'add', id_cart_row_note); } else { toggleTextBlackIconNote(product_id, mag, 'remove', id_cart_row_note); } } }); } if ($('.js-canc-cart-note').length > 0) { $('.js-canc-cart-note').on('click', function() { swal({ title: "