Subversion Repositories SmartDukaan

Rev

Rev 25366 | Rev 27595 | 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() {
2
	$(".add-auth-user").live('click', function() {
3
		console.log("Add Auth User clicked......");
4
		loadAddAuthUser("main-content");
5
	});
6
	$(".change-auth-user-password").live('click', function() {
7
		console.log("change auth user password clicked......");
8
		loadChangeAuthUserPassword("main-content");
9
	});
25570 tejbeer 10
	$(".mk_gmail_edit")
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")
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
					});
25570 tejbeer 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");
82
					}
83
				});
84
			}
85
			});
86
 
24417 govind 87
	$(".change-password")
88
			.live(
89
					'click',
90
					function() {
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);
113
							}
114
						} else {
115
							alert("new Password and confirm Password must be match");
116
						}
117
					});
24383 amit.gupta 118
	$(".create-auth-user")
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();
24478 amit.gupta 127
						var gmailId = $("#authUserGmailId").val();
24383 amit.gupta 128
 
129
						if (emailId == "" || emailId == null
130
								|| emailId == undefined) {
131
							alert("emailId cann't be blank");
132
							return;
133
						}
25570 tejbeer 134
 
24478 amit.gupta 135
						if (gmailId == "" || gmailId == null
136
								|| gmailId == undefined) {
25570 tejbeer 137
							gmailId = null;
24478 amit.gupta 138
						}
24383 amit.gupta 139
						validateEmail(emailId);
140
						if (firstName == "" || firstName == null
141
								|| firstName == undefined) {
24478 amit.gupta 142
							alert("firstName can't be blank");
24383 amit.gupta 143
							return;
144
						}
145
						if (lastName == "" || lastName == null
146
								|| lastName == undefined) {
24478 amit.gupta 147
							alert("lastName can't be blank");
24383 amit.gupta 148
							return;
149
						}
150
						if (mobileNumber == "" || mobileNumber == null
151
								|| mobileNumber == undefined) {
24478 amit.gupta 152
							alert("mobileNumber can't be blank");
24383 amit.gupta 153
							return;
154
						}
155
						if (mobileNumber.length != 10) {
156
 
157
							alert("required 10 digits, match requested format!");
158
							return;
159
						}
160
						if (confirm("Are you sure you want to create Auth user!") == true) {
161
							addAuthUser(emailId, firstName, lastName,
25570 tejbeer 162
									mobileNumber, gmailId);
24383 amit.gupta 163
						}
164
					});
165
	$("#authUsers-paginated .next").live(
166
			'click',
167
			function() {
24417 govind 168
 
169
				loadPaginatedNextItems('/getPaginatedAuthUser', null,
170
						'authUsers-paginated', 'auth-user-table',
171
						'auth-user-details-container');
24383 amit.gupta 172
				$(this).blur();
173
			});
174
 
175
	$("#authUsers-paginated .previous").live(
176
			'click',
177
			function() {
24417 govind 178
 
24383 amit.gupta 179
				loadPaginatedPreviousItems('/getPaginatedAuthUser', null,
24417 govind 180
						'authUsers-paginated', 'auth-user-table',
181
						'auth-user-details-container');
24383 amit.gupta 182
				$(this).blur();
183
			});
184
 
185
});
186
 
187
function loadChangeAuthUserPassword(domId) {
188
	doGetAjaxRequestHandler(context + "/changePassword", function(response) {
189
		$('#' + domId).html(response);
190
	});
191
}
192
function changeAuthUserPassword(oldPassword, newPassword) {
193
	var params = {
194
		"oldPassword" : oldPassword,
195
		"newPassword" : newPassword
196
	}
197
	doPostAjaxRequestWithParamsHandler(context + "/changePassword", params,
198
			function(response) {
199
				alert("Password changed successfully");
200
				loadChangeAuthUserPassword("main-content");
201
			});
202
}
25570 tejbeer 203
function addAuthUser(emailId, firstName, lastName, mobileNumber, gmailId) {
24383 amit.gupta 204
	var params = {
205
		"emailId" : emailId,
206
		"firstName" : firstName,
207
		"lastName" : lastName,
25366 tejbeer 208
		"mobileNumber" : mobileNumber,
25570 tejbeer 209
		"gmailId" : gmailId
24383 amit.gupta 210
	}
211
	doPostAjaxRequestWithParamsHandler(
212
			context + "/createAuthUser",
213
			params,
214
			function(response) {
215
				alert("User successfully added! Password sent to registered email="
24417 govind 216
						+ emailId);
24383 amit.gupta 217
				$('#' + "main-content").html(response);
218
			});
219
}
220
function loadAddAuthUser(domId) {
221
	doGetAjaxRequestHandler(context + "/createAuthUser", function(response) {
222
		$('#' + domId).html(response);
223
	});
224
}
24417 govind 225
function resetAuthUserPassword(domId, emailId) {
226
	var params = {
227
		"emailId" : emailId
24383 amit.gupta 228
	}
229
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
230
			function(response) {
24417 govind 231
				if (response == "true") {
232
					alert("Password send to " + emailId + "  Successfully ");
233
					loadAddAuthUser(domId);
234
				}
235
 
236
			});
24383 amit.gupta 237
}
238
function validateEmail(emailField) {
239
	var reg = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
240
	if (reg.test(emailField) == false) {
241
		alert('Invalid Email Address');
242
		return false;
243
	}
244
 
245
	return true;
246
 
247
}