Subversion Repositories SmartDukaan

Rev

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