Subversion Repositories SmartDukaan

Rev

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