Subversion Repositories SmartDukaan

Rev

Rev 30596 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(document).on('click', ".web-offers", function() {
        doAjaxRequestHandler(context + "/web-offers", "GET", function(response) {
                $('#main-content').html(response);
        });
});
$(document).on('click', "a.web-offer-details", function() {
        var webOfferId = $(this).data("id");
        doAjaxRequestHandler(`${context}/web-offer/${webOfferId}`, "GET", function(response) {
                $('.web-offer-products-container').html(response);
        });
        
})

$(document).on('click', ".update-rank", function(){
        if(confirm("Are you sure you want to update ranks?")) {
                var webListingId=$(this).data("id");
                var webProductIds=[];
                $("#web-product-listing-tbody").find("tr").each(function(){
                        console.log(this);
                        webProductIds.push($(this).data("id"));
                });
                doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
                        $('.web-products-container').html(response);
                });
        }
});
$(document).on('click', "#add-to-offer", function() {
        var webOfferId=$(this).data("id");
        var entityIds = [entityId];

        var entityIdTxt=$("#entityData").val();
        if(entityIdTxt.length > 0) {
                if(entityIdTxt.indexOf(",") > 0) {
                        entityIds = entityIdTxt.split(",");
                }
        } else {
                alert("Please enter items");
                return;
        }
        json = [];
        for(var e of entityIds) {
                json.push({webOfferId:webOfferId, entityId: e});
        }
        console.log(json);
        console.log(JSON.stringify(json))
        doPostAjaxRequestWithJsonHandler(`${context}/web-offer-product/add`, JSON.stringify(json), function(response) {
                $('.web-offer-products-container').html(response);
        });
        
});

$(document).on('click', "a.product-remove", function() {
        var webOfferProductId = $(this).closest('tr').data("id");
        if (confirm("Are you sure you want to remove the Item!") == true) {

                doDeleteAjaxRequestHandler(`${context}/web-offer-product/remove?webOfferProductId=${webOfferProductId}`, function(response) {
                                alert("Product removed successfully");
                                $('.web-products-container').html(response);
                        });
        }

})

function addWebOffer() {
        webOfferTitle = $("#web-offer-title").val();
        smallText = $("#small-text").val();
        largeText = $("#large-text").val();
        smallBannerUrl = $("#offer-banner-small").val();
        var json = {
                id : 0,
                title : webOfferTitle,
                smallText : smallText,
                largeText : largeText,
                smallBannerUrl : smallBannerUrl,
                startDate : startDate,
                endDate : endDate
        }
        doPostAjaxRequestWithJsonHandler(context + "/web-offer/add", JSON.stringify(json), function(response) {
                $('#main-content').html(response);
        });
}


$(document).on('mousedown', ".grab", function (e) {
    var tr = $(e.target).closest("TR"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
    b.addClass("grabCursor").css("userSelect", "none");
    tr.addClass("grabbed");
    function move (e) {
        console.log(Math.abs(e.pageY - sy));
        if (!drag && Math.abs(e.pageY - sy) < 10) return;
        drag = true;
        tr.siblings().each(function() {
            var s = $(this), i = s.index(), y = s.offset().top;
            if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
                if (e.pageY <= y + (s.outerHeight()/2))
                    tr.insertBefore(s);
                else
                    tr.insertAfter(s);
                return false;
            }
        });
    }
    function up (e) {
        if (drag && si != tr.index()) {
            drag = false;
            $(".update-rank").prop('disabled', false);
        }
        $(document).unbind("mousemove", move).unbind("mouseup", up);
        b.removeClass("grabCursor").css("userSelect", "none");
        tr.removeClass("grabbed");
    }
    $(document).mousemove(move).mouseup(up);
});

$(document).on('click', ".update-rank", function() {
        if (confirm("Are you sure you want to update ranks?")) {
                var webListingId = $(this).data("id");
                var webProductIds = [];
                $("#web-product-listing-tbody").find("tr").each(function() {
                        console.log(this);
                        webProductIds.push($(this).data("id"));
                });
                doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
                        $('.web-offer-products-container').html(response);
                });
        }
});