Subversion Repositories SmartDukaan

Rev

Rev 24383 | Rev 24478 | 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
	});
24417 govind 10
 
11
	$(".reset-password")
12
			.live(
13
					'click',
14
					function() {
15
						console.log("reset-password clicked......");
16
						var emailId = $(this).data('id');
17
						console.log(emailId);
18
						if (confirm("Are you sure you want to reset password of Auth userEmail=!"
19
								+ emailId) == true) {
20
							resetAuthUserPassword("main-content", emailId);
21
						}
22
					});
23
	$(".change-password")
24
			.live(
25
					'click',
26
					function() {
27
						console.log("change-password button clicked......");
28
						var oldPassword = $("#currentPassword").val();
29
						var newPassword = $("#newPassword").val();
30
						var confirmPassword = $("#confirmPassword").val();
31
						if (oldPassword == "" || oldPassword == null
32
								|| oldPassword == undefined) {
33
							alert("oldPassword cann't be blank");
34
							return;
35
						}
36
						if (newPassword == "" || newPassword == null
37
								|| newPassword == undefined) {
38
							alert("lastName cann't be blank");
39
							return;
40
						}
41
						if (confirmPassword == "" || confirmPassword == null
42
								|| confirmPassword == undefined) {
43
							alert("confirmPassword cann't be blank");
44
							return;
45
						}
46
						if (confirmPassword == newPassword) {
47
							if (confirm("Are you sure you want to change user password!") == true) {
48
								changeAuthUserPassword(oldPassword, newPassword);
49
							}
50
						} else {
51
							alert("new Password and confirm Password must be match");
52
						}
53
					});
24383 amit.gupta 54
	$(".create-auth-user")
55
			.live(
56
					'click',
57
					function() {
58
						console.log("Create Auth User button clicked......");
59
						var emailId = $("#authUserEmail").val();
60
						var firstName = $("#authUserFirstName").val();
61
						var lastName = $("#authUserLastName").val();
62
						var mobileNumber = $("#authUserMobileNumber").val();
63
 
64
						if (emailId == "" || emailId == null
65
								|| emailId == undefined) {
66
							alert("emailId cann't be blank");
67
							return;
68
						}
69
						validateEmail(emailId);
70
						if (firstName == "" || firstName == null
71
								|| firstName == undefined) {
72
							alert("firstName cann't be blank");
73
							return;
74
						}
75
						if (lastName == "" || lastName == null
76
								|| lastName == undefined) {
77
							alert("lastName cann't be blank");
78
							return;
79
						}
80
						if (mobileNumber == "" || mobileNumber == null
81
								|| mobileNumber == undefined) {
82
							alert("mobileNumber cann't be blank");
83
							return;
84
						}
85
						if (mobileNumber.length != 10) {
86
 
87
							alert("required 10 digits, match requested format!");
88
							return;
89
						}
90
						if (confirm("Are you sure you want to create Auth user!") == true) {
91
							addAuthUser(emailId, firstName, lastName,
92
									mobileNumber);
93
						}
94
					});
95
	$("#authUsers-paginated .next").live(
96
			'click',
97
			function() {
24417 govind 98
 
99
				loadPaginatedNextItems('/getPaginatedAuthUser', null,
100
						'authUsers-paginated', 'auth-user-table',
101
						'auth-user-details-container');
24383 amit.gupta 102
				$(this).blur();
103
			});
104
 
105
	$("#authUsers-paginated .previous").live(
106
			'click',
107
			function() {
24417 govind 108
 
24383 amit.gupta 109
				loadPaginatedPreviousItems('/getPaginatedAuthUser', null,
24417 govind 110
						'authUsers-paginated', 'auth-user-table',
111
						'auth-user-details-container');
24383 amit.gupta 112
				$(this).blur();
113
			});
114
 
115
});
116
 
117
function loadChangeAuthUserPassword(domId) {
118
	doGetAjaxRequestHandler(context + "/changePassword", function(response) {
119
		$('#' + domId).html(response);
120
	});
121
}
122
function changeAuthUserPassword(oldPassword, newPassword) {
123
	var params = {
124
		"oldPassword" : oldPassword,
125
		"newPassword" : newPassword
126
	}
127
	doPostAjaxRequestWithParamsHandler(context + "/changePassword", params,
128
			function(response) {
129
				alert("Password changed successfully");
130
				loadChangeAuthUserPassword("main-content");
131
			});
132
}
133
function addAuthUser(emailId, firstName, lastName, mobileNumber) {
134
	var params = {
135
		"emailId" : emailId,
136
		"firstName" : firstName,
137
		"lastName" : lastName,
138
		"mobileNumber" : mobileNumber
139
	}
140
	doPostAjaxRequestWithParamsHandler(
141
			context + "/createAuthUser",
142
			params,
143
			function(response) {
144
				alert("User successfully added! Password sent to registered email="
24417 govind 145
						+ emailId);
24383 amit.gupta 146
				$('#' + "main-content").html(response);
147
			});
148
}
149
function loadAddAuthUser(domId) {
150
	doGetAjaxRequestHandler(context + "/createAuthUser", function(response) {
151
		$('#' + domId).html(response);
152
	});
153
}
24417 govind 154
function resetAuthUserPassword(domId, emailId) {
155
	var params = {
156
		"emailId" : emailId
24383 amit.gupta 157
	}
158
	doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
159
			function(response) {
24417 govind 160
				if (response == "true") {
161
					alert("Password send to " + emailId + "  Successfully ");
162
					loadAddAuthUser(domId);
163
				}
164
 
165
			});
24383 amit.gupta 166
}
167
function validateEmail(emailField) {
168
	var reg = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
169
	if (reg.test(emailField) == false) {
170
		alert('Invalid Email Address');
171
		return false;
172
	}
173
 
174
	return true;
175
 
176
}