Subversion Repositories SmartDukaan

Rev

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

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


        $(document).on('click', ".samsung-upgrade-offer", function() {
                loadSamsungUpgradeOffer("main-content");
        });

        $(document).on('click', ".createoffer", function() {


                var offerName = $("#offername").val();

                if (offerName === "") {
                        alert("Offer Name is required");
                        return;
                }

                var params = {
                        "offerName": offerName,
                        "startDate": startDate,
                        "endDate": endDate,

                }
                if (confirm("Are you sure you want to create offer!") == true) {
                        doPostAjaxRequestWithParamsHandler(context
                                + "/createCustomerOffer", params, function(response) {
                                        if (response = true) {


                                                alert("create  successfully");
                                                loadCustomerOffer("main-content");
                                        }
                                });
                }


        });

        $(document).on('click', "#downloadCustomerOfferTemplate", function() {

                window.location.href = context + "/customerOffer/downloadTemplate";
        });


        $(document).on('click', ".downloadOffer", function() {
                var id = $(this).data('requestid');

                window.location.href = context + "/customerOfferItem/download?offerId=" + id;
        });



        $(document).on('click', ".extendeDate-button", function() {
                var id = $(this).data('requestid');


                var row = $(this).closest("tr");

                var params = {
                        "id": id,
                        "endDate": startDate,


                }

                if (confirm("Are you sure you want extend the offer") == true) {
                        doPostAjaxRequestWithParamsHandler(context
                                + "/extendCustomerOffer", params, function(response) {
                                        row.html(response);
                                });
                }

        });


        $(document).on('click', ".customerofferitemupload", function() {
                var id = $(this).data('requestid');
                console.log("id");

                if (confirm('Confirm upload ?')) {
                        var fileSelector = $(this)[0];
                        if (fileSelector != undefined) {
                                var url = `${context}/customerOfferItem/upload?offerId=` + id;
                                console.log(url);
                                var file = $("#customerofferitem")[0].files[0];
                                let fileInput = $(this);
                                console.log("file" + file);
                                console.log("fileInput" + fileInput);
                                doAjaxUploadRequestHandler(
                                        url,
                                        'POST',
                                        file, function(response) {

                                                console.log(response)
                                                alert("successfully uploaded");

                                        });

                        }
                }
        });



        $(document).on('click', ".upgrade-approved", function() {
                var id = $(this).data('requestid');
                var row = $(this).closest("tr");

                if (confirm("Are you sure you want Approve r!") == true) {
                        doPostAjaxRequestHandler(context + "/approveSamsungUpgradeOffer?id="
                                + id, function(response) {

                                        alert("Successfully Approved");

                                        row.html(response);


                                        return false;
                                });
                }

        });


        $(document).on('click', ".upgrade-rejected", function() {
                var id = $(this).data('requestid');


                if (confirm("Are you sure you want Reject!") == true) {
                        doPostAjaxRequestHandler(context + "/rejectSamsungUpgradeOffer?id="
                                + id, function(response) {
                                        if (response == 'true') {
                                                alert("Successfully Rejected");

                                                loadWalletRequest("main-content");
                                        }

                                        return false;
                                });
                }
        });


});

function loadCustomerOffer(domId) {

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

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