Subversion Repositories SmartDukaan

Rev

Rev 32463 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
24383 amit.gupta 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', ".add-auth-user", function() {
24383 amit.gupta 3
		console.log("Add Auth User clicked......");
4
		loadAddAuthUser("main-content");
5
	});
27754 amit.gupta 6
	$(document).on('click', ".change-auth-user-password", function() {
24383 amit.gupta 7
		console.log("change auth user password clicked......");
8
		loadChangeAuthUserPassword("main-content");
9
	});
37105 amit 10
	$(document).on('click', ".reset-user-password", function() {
11
		console.log("reset user password clicked......");
12
		loadResetPassword("main-content");
13
	});
27755 amit.gupta 14
	$(document).on('click', ".mk_gmail_edit",
27595 tejbeer 15
			function() {
16
				var $that = $(this);
17
				bootbox
18
					.prompt(
19
						"New Gmail Id",
20
						function(result) {
21
							if (result
22
								&& result
23
									.indexOf('@gmail.com') > 0) {
24
								doGetAjaxRequestHandler(
25
									context
26
									+ "/authuser/edit?emailId="
27
									+ $that
28
										.data("id")
29
									+ "&gmailId="
30
									+ result,
31
									function(response) {
32
										if (response == "true") {
33
											bootbox
34
												.alert("Gmail Id updated successfully");
35
											$that
36
												.closest(
37
													'td')
38
												.find(
39
													'span')
40
												.html(
41
													result);
42
											$that
43
												.closest(
44
													'td')
45
												.find(
46
													'button')
47
												.html(
48
													'Edit');
49
											return;
50
										}
51
									});
52
							} else {
53
								bootbox
54
									.alert("Gmail id is required");
55
							}
56
						});
57
			});
32463 jai.hind 58
			$(document).on('click', ".img_edit",
59
            			function() {
60
            				var $that = $(this);
61
            				bootbox
62
            					.prompt(
63
            						"New Image Url",
64
            						function(result) {
65
            							if (result) {
66
            								doGetAjaxRequestHandler(
67
            									context
68
            									+ "/authuser/editImageUrl?emailId="
69
            									+ $that
70
            										.data("id")
71
            									+ "&imageUrl="
72
            									+ result,
73
            									function(response) {
74
            										if (response == "true") {
75
            											bootbox
76
            												.alert("Image Url updated successfully");
77
            											$that
78
            												.closest(
79
            													'td')
80
            												.find(
81
            													'span')
82
            												.html(
83
            													result);
84
            											$that
85
            												.closest(
86
            													'td')
87
            												.find(
88
            													'button')
89
            												.html(
90
            													'Edit');
91
            											return;
92
            										}
93
            									});
94
            							} else {
95
            								bootbox
96
            									.alert("Image url is required");
97
            							}
98
            						});
99
            			});
24417 govind 100
 
32463 jai.hind 101
 
27755 amit.gupta 102
	$(document).on('click', ".reset-password",
27595 tejbeer 103
			function() {
104
				console.log("reset-password clicked......");
105
				var emailId = $(this).data('id');
106
				console.log(emailId);
107
				if (confirm("Are you sure you want to reset password of Auth userEmail=!"
108
					+ emailId) == true) {
109
					resetAuthUserPassword("main-content", emailId);
110
				}
111
			});
112
 
27755 amit.gupta 113
	$(document).on('click', ".remove-user",
27595 tejbeer 114
		function() {
115
			console.log("heelo");
116
			var $that = $(this);
117
 
118
			if (confirm("Are you sure you want to remove the user")) {
119
				doPostAjaxRequestHandler(context + "/authuser/remove?id="
120
					+ $that.data("id"), function(response) {
121
						if (response == "true") {
122
							alert("Remove User Successfully");
123
							loadAddAuthUser("main-content");
24417 govind 124
						}
125
					});
27595 tejbeer 126
			}
127
		});
25570 tejbeer 128
 
27755 amit.gupta 129
	$(document).on('click', ".change-password",
25570 tejbeer 130
			function() {
27595 tejbeer 131
				console.log("change-password button clicked......");
132
				var oldPassword = $("#currentPassword").val();
133
				var newPassword = $("#newPassword").val();
134
				var confirmPassword = $("#confirmPassword").val();
135
				if (oldPassword == "" || oldPassword == null
136
					|| oldPassword == undefined) {
137
					alert("oldPassword cann't be blank");
138
					return;
139
				}
140
				if (newPassword == "" || newPassword == null
141
					|| newPassword == undefined) {
142
					alert("lastName cann't be blank");
143
					return;
144
				}
145
				if (confirmPassword == "" || confirmPassword == null
146
					|| confirmPassword == undefined) {
147
					alert("confirmPassword cann't be blank");
148
					return;
149
				}
150
				if (confirmPassword == newPassword) {
151
					if (confirm("Are you sure you want to change user password!") == true) {
152
						changeAuthUserPassword(oldPassword, newPassword);
25570 tejbeer 153
					}
27595 tejbeer 154
				} else {
155
					alert("new Password and confirm Password must be match");
156
				}
25570 tejbeer 157
			});
27755 amit.gupta 158
	$(document).on('click', ".create-auth-user",
27595 tejbeer 159
			function() {
160
				console.log("Create Auth User button clicked......");
161
				var emailId = $("#authUserEmail").val();
162
				var firstName = $("#authUserFirstName").val();
163
				var lastName = $("#authUserLastName").val();
164
				var mobileNumber = $("#authUserMobileNumber").val();
165
				var gmailId = $("#authUserGmailId").val();
166
				var employeeCode = $("#authUserEmployeeCode").val();
32463 jai.hind 167
				var imageUrl=$("#authUserImage").val();
24383 amit.gupta 168
 
27595 tejbeer 169
				if (emailId == "" || emailId == null
170
					|| emailId == undefined) {
171
					alert("emailId cann't be blank");
172
					return;
173
				}
25570 tejbeer 174
 
27595 tejbeer 175
				if (gmailId == "" || gmailId == null
176
					|| gmailId == undefined) {
177
					gmailId = null;
178
				}
179
				validateEmail(emailId);
180
				if (firstName == "" || firstName == null
181
					|| firstName == undefined) {
182
					alert("firstName can't be blank");
183
					return;
184
				}
185
				if (lastName == "" || lastName == null
186
					|| lastName == undefined) {
187
					alert("lastName can't be blank");
188
					return;
189
				}
24383 amit.gupta 190
 
27595 tejbeer 191
				if (employeeCode == "" || employeeCode == null
192
					|| employeeCode == undefined) {
193
					alert("Employee Code can't be blank");
194
					return;
195
				}
24417 govind 196
 
27595 tejbeer 197
				if (mobileNumber == "" || mobileNumber == null
198
					|| mobileNumber == undefined) {
199
					alert("mobileNumber can't be blank");
200
					return;
201
				}
202
				if (mobileNumber.length != 10) {
203
 
204
					alert("required 10 digits, match requested format!");
205
					return;
206
				}
32463 jai.hind 207
 
27595 tejbeer 208
				if (confirm("Are you sure you want to create Auth user!") == true) {
209
					addAuthUser(emailId, firstName, lastName,
32463 jai.hind 210
						mobileNumber, gmailId, employeeCode,imageUrl);
27595 tejbeer 211
				}
24383 amit.gupta 212
			});
27755 amit.gupta 213
	$(document).on('click', "#authUsers-paginated .next",
27595 tejbeer 214
		function() {
24383 amit.gupta 215
 
27595 tejbeer 216
			loadPaginatedNextItems('/getPaginatedAuthUser', null,
217
				'authUsers-paginated', 'auth-user-table',
218
				'auth-user-details-container');
219
			$(this).blur();
220
		});
29209 manish 221
	$(document).on('click', ".add-manager",
222
			function() {
223
		var row = $(this).closest("tr");
224
 
225
		var authId = $(this).data("id");
226
		console.log("authId"+authId);
227
 
228
		var managerId = $(row).find("#auth-users option:selected").val();
229
 
230
		console.log("managerId"+managerId);
231
 
232
		doPostAjaxRequestHandler(context + "/addManagerId?authId="
233
				+ authId + "&managerId=" +  managerId, function(response) {
234
					if (response == "true") {
235
						alert("Add Manager Successfully");
236
						loadAddAuthUser("main-content");
237
					}
238
				});
239
 
240
			});
27595 tejbeer 241
 
27755 amit.gupta 242
	$(document).on('click', "#authUsers-paginated .previous",
27595 tejbeer 243
		function() {
24417 govind 244
 
27595 tejbeer 245
			loadPaginatedPreviousItems('/getPaginatedAuthUser', null,
246
				'authUsers-paginated', 'auth-user-table',
247
				'auth-user-details-container');
248
			$(this).blur();
249
		});
24383 amit.gupta 250
 
251
});
252
 
253
function loadChangeAuthUserPassword(domId) {
254
	doGetAjaxRequestHandler(context + "/changePassword", function(response) {
255
		$('#' + domId).html(response);
256
	});
257
}
29209 manish 258
 
37105 amit 259
function loadResetPassword(domId) {
260
	doGetAjaxRequestHandler(context + "/authUser/resetPasswordPage", function(response) {
261
		$('#' + domId).html(response);
262
	});
263
}
29209 manish 264
 
265
 
37105 amit 266
 
24383 amit.gupta 267
function changeAuthUserPassword(oldPassword, newPassword) {
268
	var params = {
27595 tejbeer 269
		"oldPassword": oldPassword,
270
		"newPassword": newPassword
24383 amit.gupta 271
	}
272
	doPostAjaxRequestWithParamsHandler(context + "/changePassword", params,
27595 tejbeer 273
		function(response) {
274
			alert("Password changed successfully");
275
			loadChangeAuthUserPassword("main-content");
276
		});
24383 amit.gupta 277
}
32463 jai.hind 278
function addAuthUser(emailId, firstName, lastName, mobileNumber, gmailId, employeeCode, imageUrl) {
24383 amit.gupta 279
	var params = {
27595 tejbeer 280
		"emailId": emailId,
281
		"firstName": firstName,
282
		"lastName": lastName,
283
		"mobileNumber": mobileNumber,
284
		"gmailId": gmailId,
32463 jai.hind 285
		"employeeCode": employeeCode,
286
		"imageUrl":imageUrl
24383 amit.gupta 287
	}
288
	doPostAjaxRequestWithParamsHandler(
27595 tejbeer 289
		context + "/createAuthUser",
290
		params,
291
		function(response) {
292
			alert("User successfully added! Password sent to registered email="
293
				+ emailId);
294
			$('#' + "main-content").html(response);
295
		});
24383 amit.gupta 296
}
297
function loadAddAuthUser(domId) {
298
	doGetAjaxRequestHandler(context + "/createAuthUser", function(response) {
299
		$('#' + domId).html(response);
300
	});
301
}
24417 govind 302
function resetAuthUserPassword(domId, emailId) {
303
	var params = {
27595 tejbeer 304
		"emailId": emailId
24383 amit.gupta 305
	}
306
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
27595 tejbeer 307
		function(response) {
308
			if (response == "true") {
309
				alert("Password send to " + emailId + "  Successfully ");
310
				loadAddAuthUser(domId);
311
			}
24417 govind 312
 
27595 tejbeer 313
		});
24383 amit.gupta 314
}
315
function validateEmail(emailField) {
316
	var reg = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
317
	if (reg.test(emailField) == false) {
318
		alert('Invalid Email Address');
319
		return false;
320
	}
321
 
322
	return true;
323
 
324
}