File: D:/HostingSpaces/Eurotools/euro-tools.nl/wwwroot/js/shop/shop.js
var ShoppingCart = {
// Initialize click event
init: function init() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('[contenteditable]').bind('blur', function () {
///storeProjectBilledAmount
var amount = $(this).html();
var id = $(this).data('id');
if (amount > 0) {
ShoppingCart.setItemAmountInShoppingcart(id, amount);
}
});
$('[contenteditable]').bind('keypress', function (e) {
if (event.keyCode === 10 || event.keyCode === 13) {
$(this).blur();
e.preventDefault();
}
});
$('.order-box .amount, .amount-box .amount').on('change', function () {
var amount = parseInt($(this).val());
var id = $(this).data('id');
if (amount > 0) {
ShoppingCart.setItemAmountInShoppingcart(id, amount);
}
});
},
addProductToShoppingcart: function addProductToShoppingcart(id, type) {
var amount = parseInt($('.order-box .amount').val());
if (amount > 0) {
$.post("/addProductToShoppingcart", { productableID: id, itemType: type, amount: amount }).done(function (redirectUrl) {
window.location = redirectUrl;
});
}
//ShoppingCart.animateButtonToShoppingcartIcon();
},
removeItemFromShoppingcart: function removeItemFromShoppingcart(id, type) {
ShoppingCart.showModal(id, type);
},
setItemAmountInShoppingcart: function setItemAmountInShoppingcart(id, amount) {
if (amount > 0) {
$.post("/setItemAmountInShoppingcart", { itemID: id, amount: amount }).done(function (data) {
$(".shoppingCartContent").html(data);
ShoppingCart.init();
ShoppingCart.updateCartButtonCounter();
});
} else if (amount === 0) {
this.removeItemFromShoppingcart(id);
}
},
updateCartButtonCounter: function updateCartButtonCounter() {
$.get("/getCartItemCount", function (data) {
$("span.shoppingCartButtonCounter").attr('data-counter', data);
});
},
showModal: function showModal(id, type) {
$('.delete-modal').css("display", "flex");
$('.delete-modal a.close, .delete-modal a.no').bind('click', function (ev) {
$('.delete-modal').hide();
});
$('.delete-modal a.yes').bind('click', function () {
$.post("/removeItemFromShoppingcart", { productableID: id, itemType: type }).done(function (data) {
$(".shoppingCartContent").html(data);
ShoppingCart.updateCartButtonCounter();
});
});
},
animateButtonToShoppingcartIcon: function animateButtonToShoppingcartIcon() {
var $addToCartButton = $('a.shoppingCart');
var $shoppingCartButton = $('a.shoppingCartButton:visible');
if ($addToCartButton && $shoppingCartButton) {
var startPosition = $addToCartButton.offset();
var endPosition = $shoppingCartButton.offset();
var $flyButton = $addToCartButton.clone().appendTo('body > .content');
$flyButton.html('');
$flyButton.css({ position: 'absolute', left: startPosition.left + 'px', top: startPosition.top + 'px', width: $addToCartButton.width() + 'px', opacity: '0.5', backgroundColor: '#cccccc' });
$flyButton.animate({
opacity: 0,
left: endPosition.left,
top: 0,
width: 0
}, 500, 'linear', function () {
$(this).remove();
$shoppingCartButton.addClass('inflate');
setTimeout(function () {
$shoppingCartButton.removeClass('inflate');
}, 200);
});
}
}
};
ShoppingCart.init();
var vatCheck = {
check: function check(vatCode) {
console.log('checking vat: ' + vatCode);
return axios.post('/validateVat', {
company_vat_number: vatCode
});
}
};
document.addEventListener("DOMContentLoaded", function () {
var inputField = document.getElementById('company_vat_number');
if (!inputField) return;
inputField.addEventListener('change', function () {
var checkPromise = vatCheck.check(inputField.value);
checkPromise.then(function (response) {
console.log(response);
if (response.data === true) {
console.log('vat is valid');
inputField.classList.remove('invalid');
inputField.classList.add('valid');
} else {
console.log('vat is not valid');
inputField.classList.remove('valid');
inputField.classList.add('invalid');
}
}).catch(function (error) {
console.log('Vat check error');
console.error(error);
});
});
});