Subversion Repositories SmartDukaan

Rev

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