Subversion Repositories SmartDukaan

Rev

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