HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/douven.komma.pro/resources/assets/js/shop/cart.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();