Subversion Repositories SmartDukaan

Rev

Rev 24107 | Rev 24833 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

var targetSlab = [];
var slabmonth;
var slabInputs = {};
$(function() {

        $(".upload-target").live('click', function() {
                console.log("upload target Button Clicked...")
                uploadTarget("main-content");
        });
        $(".partner-target").live('click', function() {
                console.log("partner target Button Clicked...")
                partnerTarget("main-content");
        });
        $("#partner-target-details-paginated .next").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/getAllPartnerTargetPaginated', null,
                                                'partner-target-details-paginated',
                                                'partner-target-details-table',
                                                'partner-target-details-container');
                                $(this).blur();
                        });

        $("#partner-target-details-paginated .previous").live(
                        'click',
                        function() {
                                loadPaginatedPreviousItems('/getAllPartnerTargetPaginated',
                                                null, 'partner-target-details-paginated',
                                                'partner-target-details-table',
                                                'partner-target-details-container');
                                $(this).blur();
                        });
        $(".partner-target-details").live('click', function() {
                var targetId = $(this).attr('data');
                console.log("targetId = " + targetId);
                loadPartnerTargetDetails(targetId, "partner-target-details-container");
        });
        $(".deleteslab").live('click', function() {
                console.log("delete slab button clicked");
                var index = $(this).data('index');
                console.log(index);
                targetSlab.splice(-1, 1);
                $(".div-" + index).remove();
                $("#index-" + (index - 1)).show();
                console.log(targetSlab);
                if (targetSlab.length == 0) {
                        $("#uploadfile").prop('disabled', false);
                        $("#targetName").prop('disabled', false);
                        $("#targetDuration").prop('disabled', false);
                        $('#target-brands').prop('disabled', false);
                }

        });

        $("#addSlab")
                        .live(
                                        'click',
                                        function() {
                                                console.log("Add slab Button Clicked...");
                                                var labelName = $("#label").val();
                                                var slabpercentage = $("#slabpercentage").val();
                                                var rewardPercentage = $("#rewardPercentage").val();
                                                var slabName = $("#slabNameId").val();
                                                $("#uploadfile").prop('disabled', true);
                                                $("#targetName").prop('disabled', true);
                                                $("#targetDuration").prop('disabled', true);
                                                $('#target-brands').prop('disabled', true);
                                                if (slabpercentage == "" || rewardPercentage == ""
                                                                || slabName === "") {
                                                        alert("Input field can't be empty");
                                                        return;
                                                }
                                                console.log(targetSlab.length);

                                                if (targetSlab.length > 0) {
                                                        console.log("#index-"
                                                                        + parseFloat(targetSlab.length - 1));

                                                        if (parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) < parseFloat(slabpercentage)) {
                                                                $("#index-" + parseFloat(targetSlab.length - 1))
                                                                                .hide();
                                                                slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
                                                                slabInputs['maxSlabPercentage'] = slabpercentage;
                                                                slabInputs['rewardPercentage'] = rewardPercentage;
                                                                slabInputs['slabName'] = slabName;
                                                                console.log(slabInputs);
                                                                targetSlab.push(slabInputs);
                                                                console.log(slabInputs)
                                                                $("#slab-input")
                                                                                .html(
                                                                                                "       <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
                                                                                                                + "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
                                                                                                                + "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
                                                                                                                + "<input type=button class=btn-primary  value=+ id=addSlab>"

                                                                                );

                                                                var htmlString = $("<div class=div-"
                                                                                + parseFloat(targetSlab.length - 1)
                                                                                + ">"
                                                                                + "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
                                                                                + "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
                                                                                + slabpercentage
                                                                                + ">  "
                                                                                + "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
                                                                                + rewardPercentage
                                                                                + ">  "
                                                                                + "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
                                                                                + slabName
                                                                                + ">"
                                                                                + "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
                                                                                + parseFloat(targetSlab.length - 1)
                                                                                + "\"id=index-"
                                                                                + parseFloat(targetSlab.length - 1)
                                                                                + ">" + "  <div><br>");
                                                                $("#slab-order").append(htmlString);
                                                                slabInputs = {};
                                                        } else {
                                                                alert("Slab Percentage is not less than previous Slab Percentage");
                                                                return false;
                                                        }
                                                } else {
                                                        slabInputs['minSlabPercentage'] = 0;
                                                        slabInputs['maxSlabPercentage'] = slabpercentage;
                                                        slabInputs['rewardPercentage'] = rewardPercentage;
                                                        slabInputs['slabName'] = slabName;
                                                        console.log(slabInputs);
                                                        targetSlab.push(slabInputs);
                                                        console.log(slabInputs)
                                                        $("#slab-input")
                                                                        .html(
                                                                                        "       <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
                                                                                                        + "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
                                                                                                        + "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
                                                                                                        + "<input type=button class=btn-primary  value=+ id=addSlab>"

                                                                        );

                                                        var htmlString = $("<div class=div-"
                                                                        + parseFloat(targetSlab.length - 1)
                                                                        + ">"
                                                                        + "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
                                                                        + "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
                                                                        + slabpercentage
                                                                        + ">  "
                                                                        + "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
                                                                        + rewardPercentage
                                                                        + ">  "
                                                                        + "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
                                                                        + slabName
                                                                        + ">"
                                                                        + "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
                                                                        + parseFloat(targetSlab.length - 1)
                                                                        + "\" id=index-"
                                                                        + parseFloat(targetSlab.length - 1) + ">"
                                                                        + "  <div><br><div>");
                                                        $("#slab-order").append(htmlString);
                                                        $("#slabdate").prop('disabled', true);
                                                        slabInputs = {};
                                                }

                                        });

        $("#uploadExcel")
                        .live(
                                        'click',
                                        function() {
                                                var excelfile = $('#uploadfile')[0].files[0];
                                                var targetName = $('#targetName').val();
                                                var slabName = $("#slabNameId").val();
                                                console.log(excelfile);
                                                console.log(targetName);
                                                if (!excelfile) {
                                                        alert("choose excel file for upload");
                                                        return;
                                                }
                                                var ext = $('#uploadfile').val().split('.').pop()
                                                                .toLowerCase();
                                                if ($.inArray(ext, [ 'xlsx' ]) == -1) {
                                                        alert('invalid extension!');
                                                        return;
                                                }
                                                if (targetName === null ||targetName ==="") {
                                                        alert("targetName Field is not empty");
                                                        return;
                                                }
                                                if (slabName === null ||slabName === "") {
                                                        alert("slabName Field is not empty");
                                                        return;
                                                }
                                                var brandName = $('#target-brands').val();
                                                console.log(brandName);
                                                if (brandName == "") {
                                                        brandName = null;
                                                }
                                                console.log("excelfile" + excelfile);
                                                var labelName = $("#label").val();
                                                var rewardPercentage = $("#rewardPercentage").val();
                                                if (rewardPercentage == "" || slabName === "") {
                                                        alert("Input field can't be empty");
                                                        return;
                                                }
                                                slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
                                                slabInputs['maxSlabPercentage'] = -1;
                                                slabInputs['rewardPercentage'] = rewardPercentage;
                                                slabInputs['slabName'] = slabName;
                                                console.log(slabInputs);
                                                targetSlab.push(slabInputs);
                                                slabInputs = {};
                                                console.log(targetSlab);
                                                if (confirm("Are you sure you want to upload excel file!") == true) {
                                                        var data = {
                                                                targetName : targetName,
                                                                startDate : startDate,
                                                                endDate : endDate,
                                                                brandName : brandName,
                                                                targetSlabs : targetSlab
                                                        }

                                                        doAjaxUploadRequestJsonHandler(context
                                                                        + "/uploadPartnersTarget", 'POST',
                                                                        excelfile, JSON.stringify(data), function(
                                                                                        response) {
                                                                                if (response == "true") {
                                                                                        alert("successfully uploaded");
                                                                                        targetSlab = [];
                                                                                        uploadTarget("main-content");
                                                                                }
                                                                                targetSlab = [];

                                                                        });
                                                }
                                        });

});

function labelChange() {
        var labelName = $("#label").val();
        console.log(labelName);
        if (labelName == "upto") {

                $("#slab-input")
                                .html(
                                                "       <input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
                                                                + "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
                                                                + "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
                                                                + "<input type=button class=btn-primary  value=+ id=addSlab>"

                                );

        } else {
                $("#slab-input")
                                .html(

                                                "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">"
                                                                + "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "+
                                                                "<input class=\"btn btn-primary\" type=button value=upload id=uploadExcel>");
        }
}

function uploadTarget(domId) {
        doGetAjaxRequestHandler(context + "/uploadPartnerTargetPage", function(
                        response) {
                $('#' + domId).html(response);
        });
}
function partnerTarget(domId) {
        doGetAjaxRequestHandler(context + "/getAllPartnerTarget",
                        function(response) {
                                $('#' + domId).html(response);
                        });
}
function loadPartnerTargetDetails(targetId, domId) {
        doGetAjaxRequestHandler(context + "/getPartnerTarget?targetId=" + targetId,
                        function(response) {
                                $('#' + domId).html(response);
                                window.dispatchEvent(new Event('resize'));
                        });
}