Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23343 ashik.ali 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', ".create-scheme", function() {
23343 ashik.ali 3
		loadScheme("main-content");
4
	});
23752 govind 5
 
27755 amit.gupta 6
	$(document).on('click', "#schemes-paginated .next",
23752 govind 7
			function() {
26802 tejbeer 8
				var category = $('#partner-category').val();
23752 govind 9
				var searchText = $("#scheme-item-search-text").val();
26802 tejbeer 10
 
26763 tejbeer 11
				var category = $('#partner-category').val();
23752 govind 12
				if (typeof (searchText) == "undefined" || !searchText) {
13
					searchText = "";
14
				}
26802 tejbeer 15
				if (typeof (category) == "undefined" || !category) {
16
					category = "";
17
				}
23752 govind 18
 
26802 tejbeer 19
				if ((searchText) && (category)) {
20
 
23752 govind 21
					var params = {};
26802 tejbeer 22
					params['searchItem'] = currentItem.itemId;
23
					params['partnerType'] = category
24
					loadPaginatedNextItems('/getPaginatedSchemes', params,
25
							'schemes-paginated', 'schemes-table',
23752 govind 26
							'scheme-details-container');
26763 tejbeer 27
 
26802 tejbeer 28
				} else if ((searchText)) {
26763 tejbeer 29
					var params = {};
26802 tejbeer 30
					params['searchItem'] = currentItem.itemId;
31
					loadPaginatedNextItems('/getPaginatedSchemes', params,
32
							'schemes-paginated', 'schemes-table',
26763 tejbeer 33
							'scheme-details-container');
26802 tejbeer 34
 
23752 govind 35
				} else {
26912 tejbeer 36
					var params = {};
37
					params['partnerType'] = category
38
					loadPaginatedNextItems('/getPaginatedSchemes', params,
23752 govind 39
							'schemes-paginated', 'schemes-table',
40
							'scheme-details-container');
41
				}
42
				$(this).blur();
43
			});
44
 
27755 amit.gupta 45
	$(document).on('click', "#schemes-paginated .previous",
23752 govind 46
			function() {
47
				var searchText = $("#scheme-item-search-text").val();
26763 tejbeer 48
				var category = $('#partner-category').val();
23752 govind 49
				// var searchTxt=$("#scheme-search-text").val();
50
				console.log(searchText);
51
				if (typeof (searchText) == "undefined" || !searchText) {
52
					searchText = "";
53
				}
26802 tejbeer 54
				if (typeof (category) == "undefined" || !category) {
55
					category = "";
56
				}
23752 govind 57
 
26802 tejbeer 58
				console.log(searchText)
59
 
60
				if ((searchText) && (category)) {
61
 
23752 govind 62
					var params = {};
26802 tejbeer 63
					params['searchItem'] = currentItem.itemId;
64
					params['partnerType'] = category
65
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
66
							'schemes-paginated', 'schemes-table',
23752 govind 67
							'scheme-details-container');
26763 tejbeer 68
 
26802 tejbeer 69
				} else if ((searchText)) {
26763 tejbeer 70
					var params = {};
26802 tejbeer 71
					params['searchItem'] = currentItem.itemId;
72
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
73
							'schemes-paginated', 'schemes-table',
26763 tejbeer 74
							'scheme-details-container');
75
 
26802 tejbeer 76
				} else {
26912 tejbeer 77
					var params = {};
78
					params['partnerType'] = category
79
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
23752 govind 80
							'schemes-paginated', 'schemes-table',
81
							'scheme-details-container');
82
				}
83
				$(this).blur();
84
			});
85
 
27754 amit.gupta 86
	$(document).on('click', ".scheme-details", function() {
23343 ashik.ali 87
		var schemeId = $(this).attr('data');
23752 govind 88
		console.log("schemeId = " + schemeId);
23343 ashik.ali 89
		loadSchemeDetails(schemeId, "scheme-details-container");
90
	});
23752 govind 91
 
27754 amit.gupta 92
	$(document).on('click', ".active-scheme", function() {
23343 ashik.ali 93
		var schemeId = $(this).attr('data');
23752 govind 94
		console.log("active-scheme id : " + schemeId);
95
		var start = $("#schemes-paginated .start").text();
96
		// var end = $( "#schemes-paginated .end" ).text();
23343 ashik.ali 97
		var offset = start - 1;
23752 govind 98
		if (confirm("Are you sure you want to Active Scheme!") == true) {
23343 ashik.ali 99
			activeScheme(schemeId, offset, "schemes-table");
100
		}
101
	});
23752 govind 102
 
27754 amit.gupta 103
	$(document).on('click', ".expire-scheme", function() {
23343 ashik.ali 104
		var schemeId = $(this).attr('data');
25069 amit.gupta 105
		var expireDate = startDate;
23752 govind 106
		var start = $("#schemes-paginated .start").text();
107
		// var end = $( "#schemes-paginated .end" ).text();
23343 ashik.ali 108
		var offset = start - 1;
23752 govind 109
		if (confirm("Are you sure you want to Expire Scheme!") == true) {
25069 amit.gupta 110
			expireScheme(schemeId, expireDate, offset, "schemes-table");
23343 ashik.ali 111
		}
112
	});
27755 amit.gupta 113
	$(document).on('click', "#extendDatetime-button",
23914 govind 114
					function() {
115
						console.log("extendAll button click");
116
						var extendDatetime = $('input[name="extendDatetime"]')
117
								.val();
118
						console.log("extendDatetime : " + extendDatetime);
119
						if (extendDatetime) {
120
							if (confirm("Are you sure you want to Extend expireDateTime for All Scheme!") == true) {
121
								extendAllScheme(extendDatetime, "schemes-table")
122
							}
123
						} else {
124
							alert("feild can't be blank");
125
						}
126
					});
27755 amit.gupta 127
	$(document).on('click', "#extendScheme-button",
23914 govind 128
					function() {
129
						console.log("extend button click");
130
						var extendDatetime = $('input[name="extendScheme"]')
131
								.val();
132
						var schemeId = $('#schemeId').val()
133
						console.log("extendDatetime : " + extendDatetime);
134
						console.log(schemeId);
135
						if (extendDatetime) {
136
							if (confirm("Are you sure you want to Extend expireDateTime for Scheme!") == true) {
137
								extendSchemeById(schemeId)
138
							}
139
						} else {
140
							alert("feild can't be blank");
141
						}
142
					});
23752 govind 143
 
27754 amit.gupta 144
	$(document).on('click', ".schemes", function() {
23347 ashik.ali 145
		console.log("Active Schemes Button Clicked...")
27648 tejbeer 146
	  schemes("main-content");
23347 ashik.ali 147
	});
23752 govind 148
 
27754 amit.gupta 149
    $(document).on('click', ".margin-calculator", function() {
27648 tejbeer 150
		console.log("Active Schemes Button Clicked...")
151
	   marginCalculator("main-content");
152
	});
153
 
27754 amit.gupta 154
	$(document).on('click', ".schemes-download-page", function() {
23347 ashik.ali 155
		console.log("Schemes Download Clicked...")
156
		loadSchemesDownloadPage("main-content");
22860 ashik.ali 157
	});
23752 govind 158
 
27754 amit.gupta 159
	$(document).on('click', ".schemes-update", function() {
23556 amit.gupta 160
		loadSchemeUpdatePage("main-content");
161
	});
23557 amit.gupta 162
 
27754 amit.gupta 163
	$(document).on('click', ".add-item", function() {
23928 govind 164
 
165
		schemeIds = $("#schemeids").val();
166
		itemIds = $("#itemids").val();
167
		console.log(schemeIds);
168
		console.log(itemIds);
169
		if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
26763 tejbeer 170
			if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
171
				alert("fields shouldn't be blank");
172
				return;
173
			}
174
			updateSingleScheme(schemeIds, itemIds);
23928 govind 175
		}
176
	});
27754 amit.gupta 177
	$(document).on('click', ".add-schemes", function() {
23752 govind 178
 
23557 amit.gupta 179
		schemeIds = $("#schemeids").val();
180
		itemIds = $("#itemids").val();
23914 govind 181
		console.log(schemeIds);
182
		console.log(itemIds);
183
		if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
26763 tejbeer 184
			if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
185
				alert("fields shouldn't be blank");
186
				return;
187
			}
188
			updateSchemes(schemeIds, itemIds);
23557 amit.gupta 189
		}
190
	});
27754 amit.gupta 191
	$(document).on('click', ".delete-schemes", function() {
23819 govind 192
		if (confirm("Are you sure you want to delete Scheme!") == true) {
23914 govind 193
			schemeId = $(this).data('schemeid');
194
			itemId = $(this).data('itemid');
195
			console.log(schemeId);
196
			console.log(itemId);
197
			deleteScheme(schemeId, itemId);
23715 govind 198
		}
23752 govind 199
	});
200
 
27755 amit.gupta 201
	$(document).on('click', "#scheme-search-button",
26802 tejbeer 202
			function() {
203
				var searchText = $("#scheme-search-text").val();
204
				if (typeof (searchText) == "undefined" || !searchText) {
205
					searchText = "";
206
				}
207
				doGetAjaxRequestHandler(context + "/getSchemes/?searchTerm="
208
						+ searchText, function(response) {
209
					$('#' + "main-content").html(response);
210
				});
211
			});
212
 
27754 amit.gupta 213
	$(document).on("keyup", "#scheme-search-text", function(e) {
23752 govind 214
		var keyCode = e.keyCode || e.which;
215
		if (keyCode == 13) {
216
			$("#scheme-search-button").click();
217
		}
218
	});
27754 amit.gupta 219
	$(document).on('click', "#scheme-item-search-button", function() {
23752 govind 220
		var searchText = $("#scheme-item-search-text").val();
221
		if (typeof (searchText) == "undefined" || !searchText) {
222
			searchText = "";
26497 amit.gupta 223
			alert("please select item");
224
			return;
23752 govind 225
		}
27094 tejbeer 226
		if (typeof currentItem != "undefined") {
227
			console.log(currentItem);
228
			loadSchemeItemSearchInfo(currentItem);
229
		} else {
230
			console.log("reeffff")
231
			alert("Data No Found")
232
		}
233
 
23752 govind 234
	});
235
 
27755 amit.gupta 236
	$(document).on('click', ".categoryWiseSchemeHistory",
26763 tejbeer 237
			function() {
238
				var category = $('#partner-category').val();
239
				console.log(category);
240
 
26912 tejbeer 241
				doGetAjaxRequestHandler(context + "/getSchemes?partnerType="
26802 tejbeer 242
						+ category, function(response) {
243
					$('#' + "main-content").html(response);
244
					$('#partner-category').val(category);
245
					window.dispatchEvent(new Event('resize'));
246
				});
26763 tejbeer 247
 
248
			});
249
 
27754 amit.gupta 250
	$(document).on("keyup", "#scheme-item-search-text", function(e) {
23752 govind 251
		var keyCode = e.keyCode || e.which;
252
		if (keyCode == 13) {
253
			$("#scheme-item-search-button").click();
254
		}
255
	});
22860 ashik.ali 256
});
257
 
23752 govind 258
function configureTagListingItemsDescriptionDropDown() {
23347 ashik.ali 259
	$(document).ready(function() {
23752 govind 260
		$('#tagListingItemsDescription').multiselect({
261
			includeSelectAllOption : true,
262
			maxHeight : 200,
263
			buttonWidth : '180px',
264
			numberDisplayed : 1,
265
			nonSelectedText : 'Items',
266
			nSelectedText : ' - Items Selected',
267
			allSelectedText : 'All Items Selected',
268
			enableFiltering : true,
269
			enableCaseInsensitiveFiltering : true
270
 
271
		});
272
	});
23343 ashik.ali 273
}
274
 
23752 govind 275
function schemesDownload() {
23343 ashik.ali 276
	console.log("downloadItemLedgerReport Button clicked")
23914 govind 277
	var startDateTime = $('input[name="startDateTime"]').val();
278
	console.log("startDateTime : " + startDateTime);
279
	var endDateTime = $('input[name="endDateTime"]').val();
280
	console.log("endDateTime : " + endDateTime);
23752 govind 281
	doAjaxGetDownload(context + "/schemes/download?startDateTime="
23914 govind 282
			+ startDateTime + "&endDateTime=" + endDateTime,
23347 ashik.ali 283
			"SchemesReport.xlsx");
23343 ashik.ali 284
}
23914 govind 285
function selectedbrand() {
286
	var brands = $('#tag-listing-brands').val();
287
	console.log(brands);
288
	if (brands) {
289
		loadTagListingItemsDescriptionByBrand(
290
				"tag-listing-items-description-container", brands);
291
	}
292
}
23752 govind 293
function loadSchemeDetails(schemeId, domId) {
294
	doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
295
			function(response) {
296
				$('#' + domId).html(response);
297
				window.dispatchEvent(new Event('resize'));
298
			});
23343 ashik.ali 299
}
300
 
23752 govind 301
function activeScheme(schemeId, offset, domId) {
302
	doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
303
			+ "&offset=" + offset, function(response) {
23343 ashik.ali 304
		$('#' + domId).html(response);
305
		$('#scheme-details-container').html('');
306
	});
23752 govind 307
 
23343 ashik.ali 308
}
309
 
25069 amit.gupta 310
function expireScheme(schemeId, expireDate, offset, domId) {
23752 govind 311
	doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
26763 tejbeer 312
			+ "&offset=" + offset + "&expireTimestamp=" + expireDate, function(
313
			response) {
314
		alert("Scheme - " + schemeId + " marked for expiry successfully!");
23343 ashik.ali 315
		$('#' + domId).html(response);
316
		$('#scheme-details-container').html('');
317
	});
318
}
23914 govind 319
function extendAllScheme(domId) {
26763 tejbeer 320
	doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
321
			.stringify(startDate), function(response) {
23914 govind 322
		if (response == 'true') {
323
			alert("Scheme All Extended successfully");
324
			schemes("main-content");
325
		} else {
326
			alert("No scheme Activated Currently");
327
			schemes("main-content");
328
		}
329
	});
23343 ashik.ali 330
 
23914 govind 331
}
332
function extendSchemeById(schemeId) {
26763 tejbeer 333
	doPostAjaxRequestWithJsonHandler(context + "/extendSchemeById?schemeId="
334
			+ schemeId, JSON.stringify(startDate), function(response) {
23914 govind 335
		if (response == 'true') {
336
			alert("Scheme extended successfully");
337
			schemes("main-content");
338
		} else {
339
			alert("Scheme already Expired");
340
			schemes("main-content");
341
		}
342
	});
343
 
344
}
345
 
23752 govind 346
function loadScheme(domId) {
347
	doGetAjaxRequestHandler(context + "/createScheme", function(response) {
23343 ashik.ali 348
		$('#' + domId).html(response);
349
	});
23752 govind 350
 
23343 ashik.ali 351
}
352
 
23914 govind 353
// function loadTagListingItemsDescriptionByBrand(domId, brand) {
354
// doGetAjaxRequestHandler(context + "/getTagListingItemsByBrand?brand="
355
// + brand, function(response) {
356
// $('#' + domId).html(response);
357
// configureTagListingItemsDescriptionDropDown();
358
// });
359
//
360
// }
361
function loadTagListingItemsDescriptionByBrand(domId, brands) {
362
	doPostAjaxRequestWithJsonHandler(context + '/getTagListingItemsByBrand',
363
			JSON.stringify(brands), function(response) {
364
				$('#' + domId).html(response);
365
				configureTagListingItemsDescriptionDropDown();
366
			});
23752 govind 367
 
23343 ashik.ali 368
}
369
 
23752 govind 370
function schemes(domId) {
371
	doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
23343 ashik.ali 372
		$('#' + domId).html(response);
373
	});
374
}
27648 tejbeer 375
function marginCalculator(domId) {
376
	doGetAjaxRequestHandler(context + "/getMarginCalculator", function(response) {
377
		$('#' + domId).html(response);
378
	});
379
}
23343 ashik.ali 380
 
23752 govind 381
function loadSchemesDownloadPage(domId) {
382
	doGetAjaxRequestHandler(context + "/schemes/downloadPage", function(
383
			response) {
23343 ashik.ali 384
		$('#' + domId).html(response);
385
	});
23556 amit.gupta 386
}
387
 
23752 govind 388
function loadSchemeUpdatePage(domId) {
389
	doGetAjaxRequestHandler(context + "/schemes/update-schemes-page", function(
390
			response) {
23556 amit.gupta 391
		$('#' + domId).html(response);
392
	});
23557 amit.gupta 393
}
394
 
23928 govind 395
function updateSingleScheme(shcemeIds, itemIds) {
396
	doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
23752 govind 397
			.stringify({
398
				"itemIds" : itemIds.split(",").map(Number),
399
				"schemeIds" : schemeIds.split(",").map(Number)
400
			}), function(response) {
26763 tejbeer 401
		if (response == 'true') {
23914 govind 402
			alert("Item Added to scheme successfully");
403
			// $('#newItemToSchemeModal').modal('hide');
404
			loadSchemeDetails(shcemeIds, "scheme-details-container");
405
		} else {
406
			alert("Item already present");
407
			loadSchemeDetails(shcemeIds, "scheme-details-container");
23557 amit.gupta 408
		}
409
	});
23715 govind 410
}
23928 govind 411
function updateSchemes(shcemeIds, itemIds) {
412
	doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
413
			.stringify({
414
				"itemIds" : itemIds.split(",").map(Number),
415
				"schemeIds" : schemeIds.split(",").map(Number)
416
			}), function(response) {
417
		if (response == 'true') {
418
			alert("Item Added to scheme successfully");
419
			// $('#newItemToSchemeModal').modal('hide');
420
			loadSchemeUpdatePage("main-content");
26763 tejbeer 421
		}
23928 govind 422
	});
423
}
23914 govind 424
function deleteScheme(shcemeId, itemId) {
425
	doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + shcemeId
426
			+ "&itemId=" + itemId, function(response) {
23752 govind 427
		if (response == 'true') {
23914 govind 428
			alert("ItemId Deleted successfully from Scheme");
429
			loadSchemeDetails(shcemeId, "scheme-details-container");
23715 govind 430
		}
431
	});
23752 govind 432
}
433
function loadSearchScheme(domId, search_text) {
434
	doGetAjaxRequestHandler(context + "/searchScheme/?searchTerm="
435
			+ search_text, function(response) {
436
		$('#' + domId).html(response);
437
	});
438
}
26497 amit.gupta 439
function loadSearchItemScheme(domId, selected_item) {
26802 tejbeer 440
	var category = $('#partner-category').val();
441
	var searchText = $("#scheme-item-search-text").val();
26763 tejbeer 442
 
26802 tejbeer 443
	var category = $('#partner-category').val();
26912 tejbeer 444
 
445
	console.log(category)
446
 
26802 tejbeer 447
	if (typeof (searchText) == "undefined" || !searchText) {
448
		searchText = "";
449
	}
450
	if (typeof (category) == "undefined" || !category) {
451
		category = "";
452
	}
453
	if ((searchText) && (category)) {
454
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
455
				+ selected_item.itemId + "&partnerType=" + category, function(
456
				response) {
457
			$('#' + domId).html(response);
458
			$('#partner-category').val(category);
459
			$('#scheme-item-search-text').val(selected_item.itemDescription);
460
 
461
		});
26912 tejbeer 462
	} else if ((searchText)) {
26802 tejbeer 463
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
464
				+ selected_item.itemId, function(response) {
465
			$('#' + domId).html(response);
466
			$('#scheme-item-search-text').val(selected_item.itemDescription);
467
 
468
		});
26912 tejbeer 469
 
470
	}
471
 
23752 govind 472
}
473
function loadSchemeSearchInfo(search_text) {
474
	loadSearchScheme("main-content", search_text);
475
}
26497 amit.gupta 476
function loadSchemeItemSearchInfo(selectedItem) {
477
	loadSearchItemScheme("main-content", selectedItem);
23914 govind 478
}