Subversion Repositories SmartDukaan

Rev

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