File: D:/HostingSpaces/SBogers10/douven.komma.pro/wwwroot/js/shop/shop.js
var ShoppingCart = {
// Initialize click event
init: function () {
$('.userMenu').bind('click', function () {
console.log($(this).children('.dropdown').show());
});
$('[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').bind('change', function() {
var amount = parseInt($(this).val());
var id = $(this).data('id');
if(amount > 0) {
ShoppingCart.setItemAmountInShoppingcart(id, amount);
}
});
},
addProductToShoppingcart: function (id) {
var amount = parseInt($('.order-box .amount').val());
if(amount > 0) {
$.post("/addProductToShoppingcart", {itemID: id, amount: amount})
.done(function (data) {
ShoppingCart.updateCartButtonCounter();
if(window.location.href !== "/offerte") {
window.location = "/offerte";
}
});
}
},
removeItemFromShoppingcart: function (id) {
$.post("/removeItemFromShoppingcart", {itemID: id})
.done(function (data) {
$(".shoppingCartContent").html(data);
ShoppingCart.updateCartButtonCounter();
});
},
setItemAmountInShoppingcart: function (id, amount) {
if (amount > 0) {
$.post("/setItemAmountInShoppingcart", {itemID: id, amount: amount})
.done(function (data) {
$(".shoppingCartContent").html(data);
ShoppingCart.updateCartButtonCounter();
});
} else if (amount === 0) {
this.removeItemFromShoppingcart(id);
}
},
updateCartButtonCounter: function () {
$.get("/getCartItemCount", (function (data) {
$("span.shoppingCartButtonCounter").html(data > 0 ? data : '');
}));
}
};
ShoppingCart.init();