Subversion Repositories SmartDukaan

Rev

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