manage_users.js
6.69 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
$(function() {
$('form.new-account-form').live('submit', new_account_form_submit);
$('#change-user-function').load(ajax_change_user_fun_form, 'user_id=', function(){
$('#change-user-function #id_user').live('change', user_changed);
$('#change-user-function #user-delete').live('click', delete_user);
});
$('form.user-function-form').live('submit', user_function_form_submit);
});
function user_changed()
{
user_id = $('#change-user-function #id_user').val();
$('#change-user-function').empty();
$('#change-user-function').load(ajax_change_user_fun_form, 'user_id='+user_id, function(){
// $('#change-user-function #id_user').live('change', user_changed);
});
}
function new_account_form_submit() {
ShowProgressAnimation();
this_form = $(this);
form_data = this_form.serializeArray();
form_data = $.map(form_data, function(elem)
{
if (elem.name != 'group' && elem.name != 'username' &&
elem.name != 'password1' && elem.name != 'password2' &&
elem.name != 'email')
return elem;
else {
if (elem.name == 'group')
group = elem.value;
else if (elem.name == 'username')
username = elem.value;
else if (elem.name == 'password1')
password1 = elem.value;
else if (elem.name == 'password2')
password2 = elem.value;
else if (elem.name == 'email')
email = elem.value;
}
});
form_data.push({name: 'group', value: group});
form_data.push({name: 'username', value: username});
form_data.push({name: 'email', value: email});
form_data.push({name: 'password1', value: password1});
form_data.push({name: 'password2', value: password2});
$.ajaxJSON({
method: 'post',
url: ajax_new_account_form_submit,
data: {
form_data: form_data
},
callback: function(result) {
$('#change-user-function').load(ajax_change_user_fun_form, 'user_id=', function(){
// $('#change-user-function #id_user').live('change', user_changed);
});
resetForm($('.new-account-form'));
HideProgressAnimation();
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
error_alert(status + ': ' + error);
//if (ctrl)
// ctrl.remove();
},
bad_data_callback: function(result) {
//if (ctrl)
// ctrl.remove();
if (result == 'empty fields') {
HideProgressAnimation();
error_alert('Wszystkie pola formularza muszą zostać wypełnione.');
return false;
}
else if (result == 'wrong e-mail form')
{
HideProgressAnimation();
error_alert('Nieprawidłowa forma maila.');
return false;
}
else if (result == 'passwords not match')
{
HideProgressAnimation();
error_alert('Podane hasła nie są zgodne.');
return false;
}
else if (result == 'invalid username')
{
HideProgressAnimation();
error_alert('Podana nazwa użytkownika jest niewłaściwa.');
return false;
}
else if (result == 'invalid password')
{
HideProgressAnimation();
error_alert('Podane hasło jest niewłaściwe.');
return false;
}
else if (result == 'user exist')
{
HideProgressAnimation();
error_alert('Użytkownik o podanej nazwie już istnieje.');
return false;
}
else
{
HideProgressAnimation();
return true;
}
},
});
return false;
}
function user_function_form_submit() {
ShowProgressAnimation();
this_form = $(this);
form_data = this_form.serializeArray();
form_data = $.map(form_data, function(elem)
{
if (elem.name != 'user' && elem.name != 'group')
return elem;
else {
if (elem.name == 'group')
group = elem.value;
else if (elem.name == 'user')
user = elem.value;
}
});
form_data.push({name: 'group', value: group});
form_data.push({name: 'user', value: user});
$.ajaxJSON({
method: 'post',
url: ajax_change_user_fun_form_submit,
data: {
form_data: form_data
},
callback: function(result) {
$('#change-user-function').load(ajax_change_user_fun_form, 'user_id=', function(){
// $('#change-user-function #id_user').live('change', user_changed);
});
HideProgressAnimation();
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
error_alert(status + ': ' + error);
//if (ctrl)
// ctrl.remove();
},
bad_data_callback: function(result) {
//if (ctrl)
// ctrl.remove();
if (result == 'empty fields') {
HideProgressAnimation();
error_alert('Wszystkie pola formularza muszą zostać wypełnione.');
return false;
}
else if (result == 'is superuser')
{
HideProgressAnimation();
error_alert('Nie można modyfikować praw superużytkownika.');
return false;
}
else
{
HideProgressAnimation();
return true;
}
},
});
return false;
}
function delete_user() {
ShowProgressAnimation();
user_id = $('#change-user-function #id_user').val();
$.ajaxJSON({
method: 'post',
url: ajax_delete_user,
data: {
user_id: user_id
},
callback: function(result) {
$('#change-user-function').load(ajax_change_user_fun_form, 'user_id=', function(){
// $('#change-user-function #id_user').live('change', user_changed);
});
HideProgressAnimation();
},
error_callback: function(xhr, status, error) {
HideProgressAnimation();
error_alert(status + ': ' + error);
//if (ctrl)
// ctrl.remove();
},
bad_data_callback: function(result) {
//if (ctrl)
// ctrl.remove();
if (result == 'user not selected') {
HideProgressAnimation();
error_alert('Wybierz użytkownika, którego chcesz usunąć.');
return false;
}
else if (result == 'is superuser')
{
HideProgressAnimation();
error_alert('Nie można usunąć superużytkownika.');
return false;
}
else if (result == 'deleting own account')
{
HideProgressAnimation();
error_alert('Ogarnij się!');
return false;
}
else
{
HideProgressAnimation();
return true;
}
},
});
return false;
}