Subversion Repositories SmartDukaan

Rev

Rev 32595 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(document).on('click', ".banner-listing", function() {
        loadBannerListing("main-content");
});

$(document).on('click', "a.banner-listing-detail",
                function() {
                        var bannerListingId = $(this).data("id");
                        doAjaxRequestHandler(
                                        `${context}/banner-listing/${bannerListingId}`, "GET",
                                        function(response) {
                                                $('.banner-products-container').html(response);
                                        });

                });

$(document).on('click', "a.banner-remove",
                function() {
                        var bannerId = $(this).data("bannerid");
                        var bannerListingId = $(this).data("bannerlistingid");

                        if (confirm("Are you sure you want to remove banner") == true) {
                                doPostAjaxRequestHandler(context
                                                + "/banner-listing-detail/remove?bannerId=" + bannerId
                                                + "&bannerListingId=" + bannerListingId, function(
                                                response) {
                                        $('.banner-products-container').html(response);

                                });

                        }

                });

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

$(document).on('click', "#addBannerUrl",
                function() {
                        bannerUrl = $("#banner-url").val();
                        targetUrl = $("#target-url").val();
                        rank = $("#rank").val();
                        bannerListingId = $(this).data("id");
                        mediaType = $("#media-type").val();
            isTrial = $("#is-trial").prop('checked');

            json = {
                                bannerUrl : bannerUrl,
                                targetUrl: targetUrl,
                                rank : rank,
                                bannerListingId : bannerListingId,
                mediaType: mediaType,
                trial: isTrial

                        };

                        console.log(json)

                        doPostAjaxRequestWithJsonHandler(context
                                        + "/banner-listing-detail/add", JSON.stringify(json),
                                        function(response) {
                                                $('.banner-products-container').html(response);
                                        });

                });

function loadBannerListing(domId) {
        doAjaxRequestHandler(context + "/banner-listing", "GET",
                        function(response) {
                                $('#' + domId).html(response);
                        });
}

function addBannerListing() {
        pageUrl = $("#page-url").val();
        pageDescription = $("#page-description").val();
        websiteName = $("#website-name").val();
        json = {
                pageUrl : pageUrl,
                pageDescription : pageDescription,
                websiteName : websiteName
        };

        console.log(json)
        doPostAjaxRequestWithJsonHandler(context + "/banner-listing/add", JSON
                        .stringify(json), function(response) {
                $('#main-content').html(response);
        });
}

$(document).on('mousedown', ".grab-banner",
                                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-banner-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);
                                });