Subversion Repositories SmartDukaan

Rev

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