Subversion Repositories SmartDukaan

Rev

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