Subversion Repositories SmartDukaan

Rev

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

$(function () {
        $(document).on('click', ".price-circular", function () {
                loadPriceCircular("main-content");
        });

        $(document).on('click', ".partner-price-circular", function () {

                bootbox.confirm({
                        message: "<div class = 'disclosurehindata'> <img src='resources/images/disclosure.png' style='width:100%'> </div>"
                        ,
                        buttons: {
                                confirm: {
                                        label: 'I agree',
                                        className: 'btn-success'
                                },
                                cancel: {
                                        label: 'I disagree',
                                        className: 'btn-danger'
                                }
                        },
                        callback: function (result) {
                                if (result == true) {
                                        loadPartnerPriceCircular("main-content");
                                }
                        }
                });

        });

        $(document).on('click', ".submit-circular-request", function () {
                let brand = $("#brands").val();
                let priceCircularUrl = `${context}/priceCircularByBrand?brand=${brand}`;
                if (typeof partnerId == "number") {
                        priceCircularUrl = `${priceCircularUrl}&fofoId=${partnerId}`;
                }
                doGetAjaxRequestHandler(priceCircularUrl,
                        function (response) {
                                console.log(response)
                                $('.price-circular-container').html(response);
                        });
        });

        $(document).on('click', ".download-nlc", function () {
                let brand = $("#brands").val();
                let downloadNlcUrl = `${context}/downloadNlcByBrand?brand=${brand}`;
                if (typeof partnerId == "number") {
                        downloadNlcUrl = `${downloadNlcUrl}&fofoId=${partnerId}`;
                }
                doAjaxGetDownload(downloadNlcUrl, `${brand}-nlc.csv`);
        });


});

function loadPriceCircular(domId) {
        doGetAjaxRequestHandler(context + "/priceCircular",
                function (response) {
                        $('#' + domId).html(response);
                });
}

function loadPartnerPriceCircular(domId) {
        doGetAjaxRequestHandler(context + "/partnerPriceCircular",
                function (response) {
                        $('#' + domId).html(response);
                });
}

$(document).on('click', ".today-offer", function () {
        loadTodayOfferVM("main-content");
});

// Main function called to load the shell
function loadTodayOfferVM(domId) {
        doGetAjaxRequestHandler(context + `/todayOffer`, function (response) {
        // Load the brand tabs
        $('#' + domId).html(response);

        // AUTO-LOAD Samsung immediately after tabs are ready
                loadBrandOffers("Motorola", 0);
    });
}


// Click listener for tabs
$(document).on('click', ".brand-tab", function () {
    let fofoId = $(this).data('fofoid');
    let brand = $(this).data("brand");
    loadBrandOffers(brand, fofoId);
});


// Function to handle the actual data loading
function loadBrandOffers(brandName, fofoId) {


    // 1. Show the loader immediately
    const loaderHtml = `
        <center><div class="loader-wrapper">
            <i class="fa fa-spinner fa-spin fa-4x"></i>
            <span class="loader-text">Loading offers for ${brandName}...</span>
        </div></center>`;

    $('.today-offer-container').html(loaderHtml);

    // 2. Prepare the URL
    let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
    if (typeof partnerId == "number") {
        todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
    }

    // 3. Hit the API
    doGetAjaxRequestHandler(todayOfferUrl, function (response) {
        // Success: The loader is replaced by the actual table response
        $('.today-offer-container').html(response);

        // Update Active Tab UI
        $(".brand-tabs li").removeClass("active");
        $(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
    });
}


$(document).on('click', '.today-offer-view', function () {
    let offerId = $(this).data("offerid");
    doGetAjaxRequestHandler(`${context}/getOfferMargins?offerId=${offerId}`, function (data) {
        $('#todayOfferDescription .modal-content').html(data);
        $("#todayOfferDescription").modal('show');
    });
});


$(document).on('click', '.today-fofo-offer', function () {
    let fofoId = $(this).data("fofoid");
    doGetAjaxRequestHandler(`${context}/todayFofoOffer?fofoId=${fofoId}`, function (data) {
        $(".today-fofo-offer-view").show();
        $(".fofo-summry-view").hide();
        $('.today-fofo-offer-view').html(data);
        // AUTO-LOAD Samsung immediately after tabs are ready
        loadFofoBrandOffers("Motorola", fofoId);
    });
});


$(document).on('click', '.fofo-stock-info', function () {

        $(".today-fofo-offer-view").hide();
        $(".fofo-summry-view").show();
});


$(document).on('click', ".fofo-brand-tab", function () {
    let fofoId = $(this).data('fofoid');
    let brand = $(this).data("brand");
    loadFofoBrandOffers(brand, fofoId);
});


// Function to handle the actual data loading
function loadFofoBrandOffers(brandName, fofoId) {


    // 1. Show the loader immediately
    const loaderHtml = `
        <center><div class="loader-wrapper">
            <i class="fa fa-spinner fa-spin fa-4x"></i>
            <span class="loader-text">Loading offers for ${brandName}...</span>
        </div></center>`;

    $('.today-fofo-offer-container').html(loaderHtml);

    // 2. Prepare the URL
    let todayOfferUrl = `${context}/todayOfferList?brand=${brandName}&fofoId=${fofoId}`;
    if (typeof partnerId == "number") {
        todayOfferUrl = `${todayOfferUrl}&fofoId=${partnerId}`;
    }

    // 3. Hit the API
    doGetAjaxRequestHandler(todayOfferUrl, function (response) {
        // Success: The loader is replaced by the actual table response
        $('.today-fofo-offer-container').html(response);

        // Update Active Tab UI
        $(".brand-tabs li").removeClass("active");
        $(`.brand-tab[data-brand='${brandName}']`).closest('li').addClass("active");
    });
}