Subversion Repositories SmartDukaan

Rev

Rev 25570 | Rev 27754 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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