Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
24107 govind 1
var targetSlab = [];
2
var slabmonth;
3
var slabInputs = {};
4
$(function() {
5
 
6
	$(".upload-target").live('click', function() {
7
		console.log("upload target Button Clicked...")
8
		uploadTarget("main-content");
9
	});
10
	$(".partner-target").live('click', function() {
11
		console.log("partner target Button Clicked...")
24171 govind 12
		partnerTarget("main-content");
24107 govind 13
	});
24171 govind 14
	$("#partner-target-details-paginated .next").live(
15
			'click',
16
			function() {
17
				loadPaginatedNextItems('/getAllPartnerTargetPaginated', null,
18
						'partner-target-details-paginated',
19
						'partner-target-details-table',
20
						'partner-target-details-container');
21
				$(this).blur();
22
			});
24107 govind 23
 
24171 govind 24
	$("#partner-target-details-paginated .previous").live(
25
			'click',
26
			function() {
27
				loadPaginatedPreviousItems('/getAllPartnerTargetPaginated',
28
						null, 'partner-target-details-paginated',
29
						'partner-target-details-table',
30
						'partner-target-details-container');
31
				$(this).blur();
32
			});
33
	$(".partner-target-details").live('click', function() {
34
		var targetId = $(this).attr('data');
35
		console.log("targetId = " + targetId);
36
		loadPartnerTargetDetails(targetId, "partner-target-details-container");
24107 govind 37
	});
38
	$(".deleteslab").live('click', function() {
39
		console.log("delete slab button clicked");
40
		var index = $(this).data('index');
41
		console.log(index);
42
		targetSlab.splice(-1, 1);
43
		$(".div-" + index).remove();
44
		$("#index-" + (index - 1)).show();
45
		console.log(targetSlab);
24171 govind 46
		if (targetSlab.length == 0) {
47
			$("#uploadfile").prop('disabled', false);
48
			$("#targetName").prop('disabled', false);
49
			$("#targetDuration").prop('disabled', false);
50
			$('#target-brands').prop('disabled', false);
51
		}
24107 govind 52
 
53
	});
54
 
55
	$("#addSlab")
56
			.live(
57
					'click',
58
					function() {
59
						console.log("Add slab Button Clicked...");
60
						var labelName = $("#label").val();
61
						var slabpercentage = $("#slabpercentage").val();
62
						var rewardPercentage = $("#rewardPercentage").val();
24171 govind 63
						var slabName = $("#slabNameId").val();
64
						$("#uploadfile").prop('disabled', true);
65
						$("#targetName").prop('disabled', true);
66
						$("#targetDuration").prop('disabled', true);
67
						$('#target-brands').prop('disabled', true);
68
						if (slabpercentage == "" || rewardPercentage == ""
69
								|| slabName === "") {
24107 govind 70
							alert("Input field can't be empty");
71
							return;
72
						}
73
						console.log(targetSlab.length);
74
 
75
						if (targetSlab.length > 0) {
76
							console.log("#index-"
77
									+ parseFloat(targetSlab.length - 1));
78
 
79
							if (parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) < parseFloat(slabpercentage)) {
80
								$("#index-" + parseFloat(targetSlab.length - 1))
81
										.hide();
82
								slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
83
								slabInputs['maxSlabPercentage'] = slabpercentage;
84
								slabInputs['rewardPercentage'] = rewardPercentage;
24171 govind 85
								slabInputs['slabName'] = slabName;
24107 govind 86
								console.log(slabInputs);
87
								targetSlab.push(slabInputs);
88
								console.log(slabInputs)
89
								$("#slab-input")
90
										.html(
24171 govind 91
												"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
92
														+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
93
														+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
24107 govind 94
														+ "<input type=button class=btn-primary  value=+ id=addSlab>"
95
 
96
										);
97
 
98
								var htmlString = $("<div class=div-"
99
										+ parseFloat(targetSlab.length - 1)
100
										+ ">"
101
										+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
102
										+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
103
										+ slabpercentage
24171 govind 104
										+ ">  "
24107 govind 105
										+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
106
										+ rewardPercentage
24171 govind 107
										+ ">  "
108
										+ "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
109
										+ slabName
110
										+ ">"
24107 govind 111
										+ "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
112
										+ parseFloat(targetSlab.length - 1)
113
										+ "\"id=index-"
114
										+ parseFloat(targetSlab.length - 1)
24171 govind 115
										+ ">" + "  <div><br>");
24107 govind 116
								$("#slab-order").append(htmlString);
117
								slabInputs = {};
118
							} else {
119
								alert("Slab Percentage is not less than previous Slab Percentage");
120
								return false;
121
							}
122
						} else {
123
							slabInputs['minSlabPercentage'] = 0;
124
							slabInputs['maxSlabPercentage'] = slabpercentage;
125
							slabInputs['rewardPercentage'] = rewardPercentage;
24171 govind 126
							slabInputs['slabName'] = slabName;
24107 govind 127
							console.log(slabInputs);
128
							targetSlab.push(slabInputs);
129
							console.log(slabInputs)
130
							$("#slab-input")
131
									.html(
24171 govind 132
											"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
133
													+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
134
													+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
24107 govind 135
													+ "<input type=button class=btn-primary  value=+ id=addSlab>"
136
 
137
									);
138
 
139
							var htmlString = $("<div class=div-"
140
									+ parseFloat(targetSlab.length - 1)
141
									+ ">"
142
									+ "<label class=\"control-label col-sm-2\" for=\"upto\" style=\"left:10%\">Upto:</label>"
143
									+ "<div><input disabled type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\" value="
144
									+ slabpercentage
24171 govind 145
									+ ">  "
24107 govind 146
									+ "<input disabled type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\" value="
147
									+ rewardPercentage
24171 govind 148
									+ ">  "
149
									+ "<input disabled type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\" value="
150
									+ slabName
151
									+ ">"
24107 govind 152
									+ "<input type=button value=x  class=\"btn btn-primary deleteslab\"  data-index=\""
153
									+ parseFloat(targetSlab.length - 1)
154
									+ "\" id=index-"
155
									+ parseFloat(targetSlab.length - 1) + ">"
24171 govind 156
									+ "  <div><br><div>");
24107 govind 157
							$("#slab-order").append(htmlString);
158
							$("#slabdate").prop('disabled', true);
159
							slabInputs = {};
160
						}
161
 
162
					});
163
 
164
	$("#uploadExcel")
165
			.live(
166
					'click',
167
					function() {
168
						var excelfile = $('#uploadfile')[0].files[0];
24171 govind 169
						var targetName = $('#targetName').val();
170
						var slabName = $("#slabNameId").val();
171
						console.log(excelfile);
172
						console.log(targetName);
173
						if (!excelfile) {
174
							alert("choose excel file for upload");
175
							return;
176
						}
177
						var ext = $('#uploadfile').val().split('.').pop()
178
								.toLowerCase();
179
						if ($.inArray(ext, [ 'xlsx' ]) == -1) {
180
							alert('invalid extension!');
181
							return;
182
						}
183
						if (targetName === null ||targetName ==="") {
184
							alert("targetName Field is not empty");
185
							return;
186
						}
187
						if (slabName === null ||slabName === "") {
188
							alert("slabName Field is not empty");
189
							return;
190
						}
191
						var brandName = $('#target-brands').val();
192
						console.log(brandName);
193
						if (brandName == "") {
194
							brandName = null;
195
						}
24107 govind 196
						console.log("excelfile" + excelfile);
24171 govind 197
						var labelName = $("#label").val();
198
						var rewardPercentage = $("#rewardPercentage").val();
199
						if (rewardPercentage == "" || slabName === "") {
200
							alert("Input field can't be empty");
201
							return;
202
						}
203
						slabInputs['minSlabPercentage'] = parseFloat(targetSlab[targetSlab.length - 1].maxSlabPercentage) + 1;
204
						slabInputs['maxSlabPercentage'] = -1;
205
						slabInputs['rewardPercentage'] = rewardPercentage;
206
						slabInputs['slabName'] = slabName;
207
						console.log(slabInputs);
208
						targetSlab.push(slabInputs);
209
						slabInputs = {};
210
						console.log(targetSlab);
24107 govind 211
						if (confirm("Are you sure you want to upload excel file!") == true) {
24171 govind 212
							var data = {
213
								targetName : targetName,
214
								startDate : startDate,
215
								endDate : endDate,
216
								brandName : brandName,
217
								targetSlabs : targetSlab
24107 govind 218
							}
219
 
24171 govind 220
							doAjaxUploadRequestJsonHandler(context
221
									+ "/uploadPartnersTarget", 'POST',
222
									excelfile, JSON.stringify(data), function(
223
											response) {
224
										if (response == "true") {
225
											alert("successfully uploaded");
226
											targetSlab = [];
227
											uploadTarget("main-content");
228
										}
229
										targetSlab = [];
230
 
231
									});
24107 govind 232
						}
233
					});
234
 
235
});
236
 
237
function labelChange() {
238
	var labelName = $("#label").val();
239
	console.log(labelName);
24171 govind 240
	if (labelName == "upto") {
24107 govind 241
 
24171 govind 242
		$("#slab-input")
243
				.html(
244
						"	<input type=number class=\"form-control input-sm\" id=slabpercentage placeholder=\"Enter upto percentage\">  "
245
								+ "<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">  "
246
								+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "
247
								+ "<input type=button class=btn-primary  value=+ id=addSlab>"
24107 govind 248
 
24171 govind 249
				);
24107 govind 250
 
24171 govind 251
	} else {
252
		$("#slab-input")
253
				.html(
24107 govind 254
 
24171 govind 255
						"<input type=number class=\"form-control input-sm\" id=rewardPercentage placeholder=\"Enter Reward Percentage\">"
256
								+ "<input type=text class=\"form-control input-sm\" id=slabNameId placeholder=\"Enter Slab Name\">  "+
257
								"<input class=\"btn btn-primary\" type=button value=upload id=uploadExcel>");
24107 govind 258
	}
259
}
260
 
261
function uploadTarget(domId) {
262
	doGetAjaxRequestHandler(context + "/uploadPartnerTargetPage", function(
263
			response) {
264
		$('#' + domId).html(response);
265
	});
266
}
24171 govind 267
function partnerTarget(domId) {
268
	doGetAjaxRequestHandler(context + "/getAllPartnerTarget",
269
			function(response) {
270
				$('#' + domId).html(response);
271
			});
24107 govind 272
}
24171 govind 273
function loadPartnerTargetDetails(targetId, domId) {
274
	doGetAjaxRequestHandler(context + "/getPartnerTarget?targetId=" + targetId,
275
			function(response) {
276
				$('#' + domId).html(response);
277
				window.dispatchEvent(new Event('resize'));
278
			});
24107 govind 279
}