-
Notifications
You must be signed in to change notification settings - Fork 0
/
setting.js
151 lines (124 loc) · 4.98 KB
/
setting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
$(document).ready(function() {
// main menu
$("#navSetting").addClass('active');
// sub manin
$("#topNavSetting").addClass('active');
// change username
$("#changeUsernameForm").unbind('submit').bind('submit', function() {
var form = $(this);
var username = $("#username").val();
if(username == "") {
$("#username").after('<p class="text-danger">Username field is required</p>');
$("#username").closest('.form-group').addClass('has-error');
} else {
$(".text-danger").remove();
$('.form-group').removeClass('has-error');
$("#changeUsernameBtn").button('loading');
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'json',
success:function(response) {
$("#changeUsernameBtn").button('reset');
// remove text-error
$(".text-danger").remove();
// remove from-group error
$(".form-group").removeClass('has-error').removeClass('has-success');
if(response.success == true) {
// shows a successful message after operation
$('.changeUsenrameMessages').html('<div class="alert alert-success">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
'</div>');
// remove the mesages
$(".alert-success").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
});
}); // /.alert
} else {
// shows a successful message after operation
$('.changeUsenrameMessages').html('<div class="alert alert-warning">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="glyphicon glyphicon-exclamation-sign"></i></strong> '+ response.messages +
'</div>');
// remove the mesages
$(".alert-warning").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
});
}); // /.alert
}
} // /success
}); // /ajax
}
return false;
});
$("#changePasswordForm").unbind('submit').bind('submit', function() {
var form = $(this);
$(".text-danger").remove();
var currentPassword = $("#password").val();
var newPassword = $("#npassword").val();
var conformPassword = $("#cpassword").val();
if(currentPassword == "" || newPassword == "" || conformPassword == "") {
if(currentPassword == "") {
$("#password").after('<p class="text-danger">The Current Password field is required</p>');
$("#password").closest('.form-group').addClass('has-error');
} else {
$("#password").closest('.form-group').removeClass('has-error');
$(".text-danger").remove();
}
if(newPassword == "") {
$("#npassword").after('<p class="text-danger">The New Password field is required</p>');
$("#npassword").closest('.form-group').addClass('has-error');
} else {
$("#npassword").closest('.form-group').removeClass('has-error');
$(".text-danger").remove();
}
if(conformPassword == "") {
$("#cpassword").after('<p class="text-danger">The Conform Password field is required</p>');
$("#cpassword").closest('.form-group').addClass('has-error');
} else {
$("#cpassword").closest('.form-group').removeClass('has-error');
$(".text-danger").remove();
}
} else {
$(".form-group").removeClass('has-error');
$(".text-danger").remove();
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
dataType: 'json',
success:function(response) {
console.log(response);
if(response.success == true) {
$('.changePasswordMessages').html('<div class="alert alert-success">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="glyphicon glyphicon-ok-sign"></i></strong> '+ response.messages +
'</div>');
// remove the mesages
$(".alert-success").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
});
}); // /.alert
} else {
$('.changePasswordMessages').html('<div class="alert alert-warning">'+
'<button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong><i class="glyphicon glyphicon-exclamation-sign"></i></strong> '+ response.messages +
'</div>');
// remove the mesages
$(".alert-warning").delay(500).show(10, function() {
$(this).delay(3000).hide(10, function() {
$(this).remove();
});
}); // /.alert
}
} // /success function
}); // /ajax function
} // /else
return false;
});
}); // /document