Subversion Repositories SmartDukaan

Rev

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

$(function () {
    $(document).on('click', ".trial_users", function () {
        loadPendingTrialForms("main-content");
    });
    $(document).on('click', ".verified_trial_users", function () {
        loadVerifiedTrialForms("main-content");
    });

    $(document).on('click', ".mk_trial_create", function () {
        let trialFormId = $(this.closest('tr')).data('id');
    });

    $(document).on('click', ".mk_trial_cancel", function () {
        let trialFormId = $(this.closest('tr')).data('id');
        cancelTrialForm(trialFormId);
    });

    function loadPendingTrialForms(domId) {
        doGetAjaxRequestHandler(context + "/trial/pending", function (response) {
            $('#' + domId).html(response);
        });
    }

    function loadVerifiedTrialForms(domId) {
        doGetAjaxRequestHandler(context + "/trial/verified", function (response) {
            $('#' + domId).html(response);
        });
    }

    function trialCreate(trialFormId) {
        doAjaxRequestHandler(`${context}/trial/create/${trialFormId}`, "GET", function (response) {
            $('#main-content').html(response);
        });
    }

    function cancelTrialForm(trialFormId) {
        if (confirm("Are you sure you want to cancel this trial?")) {
            doPostAjaxRequestHandler(`${context}/trial/cancel/${trialFormId}`, function (response) {
                if (response == "true") {
                    loadPendingTrialForms("main-content");
                }
            });
        }
    }
});
$(document).on('click', '.openBrandModal', function () {
    let trialFormId = $(this).data('id');
    console.log("trialFormId sent:", trialFormId);
    $('#brandPotentialForm input[name="trialFormId"]').val(trialFormId);
});


function saveBrandPotential() {

    let params = {};

    params["trialFormId"] = $('#brandPotentialForm input[name="trialFormId"]').val();

    let row = 1;
    $('#brandPotentialRows tr').each(function () {
        let brand = $(this).find('input[name="brand_' + row + '"]').val();
        let potential = $(this).find('input[name="potential_' + row + '"]').val();

        if (brand && potential) {
            params["brand_" + row] = brand;
            params["potential_" + row] = potential;
        }
        row++;
    });

    console.log("PARAMS SENT:", params);

    doPostAjaxRequestWithParamsHandler(
        context + "/trial/brand-Potential",
        params,
        function (response) {
            $('#brandPotentialModal').modal('hide');
            loadPendingTrialForms("main-content");
            alert("Verifed - Brand Potential Saved Successfully");
        }
    );

}