Rev 28725 | Blame | Compare with Previous | Last modification | View Log | RSS feed
var targetSlab = [];var slabmonth;var slabInputs = {};$(function() {$(document).on('click', ".upload-target", function() {console.log("upload target Button Clicked...")uploadTarget("main-content");});$(document).on('click', ".create-partner-target-button",function() {var targetId = $("#partnerTargetdetailsforAddTarget").val();var fofoId = $("#partnerNameForTarget").val();var targetValue = $(".targetValue").val();if (fofoId == "" || fofoId == undefined|| fofoId == null) {alert("select partner");return false;}if (targetValue == "" || targetValue == undefined|| targetValue == null) {alert("Target value input field can't be empty");return false;}if (confirm("Are you sure you want to create partner target") == true) {createPartnerTarget(targetId, fofoId, targetValue);}});$(document).on('click', "#add-single-partner-target", function() {var id = $(this).data('id');addPartnerTarget(id);});$(document).on('click', "#edit-partner-target", function() {var partnerTargetId = $(this).data('targetid');getEditPartnerTarget(partnerTargetId);});$(document).on('click', ".modify-partner-target-button",function() {var partnerTargetId = $(this).data('id');var partnerTargetDetailsId = $("#partnerTargetdetails").val();var targetValue = $(".partnerTargetValue").val();console.log(partnerTargetId);if (confirm("Are you sure you want to modify partner target") == true) {modifyPartnerTarget(partnerTargetId,partnerTargetDetailsId, targetValue);}});$(document).on('click', ".partner-target", function() {console.log("partner target Button Clicked...")partnerTarget("main-content");});$(document).on('click', "#partner-target-details-paginated .next",function() {loadPaginatedNextItems('/getAllPartnerTargetPaginated', null,'partner-target-details-paginated','partner-target-details-table','partner-target-details-container');$(this).blur();});$(document).on('click', "#partner-target-details-paginated .previous",function() {loadPaginatedPreviousItems('/getAllPartnerTargetPaginated',null, 'partner-target-details-paginated','partner-target-details-table','partner-target-details-container');$(this).blur();});$(document).on('click', ".partner-target-details", function() {var targetId = $(this).attr('data');console.log("targetId = " + targetId);loadPartnerTargetDetails(targetId, "partner-target-details-container");});$(document).on('click', ".deleteslab", 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);}});$(document).on('click', "#addSlab",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 = {};}});$(document).on('click', "#uploadExcel",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: getDatesFromPicker($('input[name="targetDuration"]')).startDate,endDate: getDatesFromPicker($('input[name="targetDurarion"]')).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'));});}function getEditPartnerTarget(partnerTargetId) {doGetAjaxRequestHandler(context + "/getAllPartnerRelatedTarget?id="+ partnerTargetId, function(response) {$(".edit-partner-target-container .modal-content").html(response);});}function modifyPartnerTarget(partnerTargetId, partnerTargetDetailsId,targetValue) {var params = {"partnerTargetId" : partnerTargetId,"partnerTargetDetailsId" : partnerTargetDetailsId,"targetValue" : targetValue,}doPostAjaxRequestWithParamsHandler(context + "/updatePartnerTarget",params, function(response) {if (response == "true") {alert("Target successfully modified");getEditPartnerTarget(partnerTargetId)} else {alert("Target already defined");}});}function addPartnerTarget(id) {doGetAjaxRequestHandler(context + "/addPartnerTarget?id=" + id, function(response) {$(".add-partner-target-container .modal-content").html(response);});}function loadTargetInfoPage(domId) {doGetAjaxRequestHandler(context + "/getTargetInfo", function(response) {$('#' + domId).html(response);});}function createPartnerTarget(targetId, fofoId, targetValue) {var params = {"fofoId" : fofoId,"partnerTargetDetailsId" : targetId,"targetValue" : targetValue,}console.log(targetValue);doPostAjaxRequestWithParamsHandler(context + "/addPartnerTarget", params,function(response) {if (response == "true") {alert("successfully created!");} else {alert("You are not authorized to create partner target");}});}