Subversion Repositories SmartDukaan

Rev

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