forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_methods.js
156 lines (145 loc) · 4.95 KB
/
user_methods.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
152
153
154
155
156
/**
Copyright 2011 Red Hat, Inc.
This software is licensed to you under the GNU General Public
License as published by the Free Software Foundation; either version
2 of the License (GPLv2) or (at your option) any later version.
There is NO WARRANTY for this software, express or implied,
including the implied warranties of MERCHANTABILITY,
NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
have received a copy of GPLv2 along with this software; if not, see
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*/
KT.user_page = function() {
var clearHelptips = function() {
var chkbox = $(this);
var url = chkbox.attr("data-url");
chkbox.addClass("disabled");
$.ajax({
type: "POST",
url: url,
data: {},
cache: false,
success: function(data) {
chkbox.button('destroy');
chkbox.text(data);
},
error: function(data) {
chkbox.removeClass("disabled");
chkbox.button('option', 'label', data);
}
});
},
checkboxChanged = function() {
var checkbox = $(this);
var name = $(this).attr("name");
var options = {};
if (checkbox.attr("checked") !== undefined) {
options[name] = "1";
} else {
options[name] = "0";
}
var url = checkbox.attr("data-url");
$.ajax({
type: "PUT",
url: url,
data: options,
cache: false
});
return false;
},
verifyPassword = function() {
var match_button = $('.verify_password');
var a = $('#password_field').val();
var b = $('#confirm_field').val();
if(a!= b){
$("#password_conflict").text(i18n.password_match);
$(match_button).addClass("disabled");
$('#save_password').die('click');
$('#save_user').die('click');
return false;
}
else {
$("#password_conflict").text("");
$(match_button).removeClass("disabled");
//reset the edit user button
$('#save_password').die('click');
$('#save_password').live('click',changePassword);
//reset the new user button
$('#save_user').die('click');
$('#save_user').live('click',createNewUser);
return true;
}
},
createNewUser = function() {
var button = $(this);
if (button.hasClass("disabled")) {
return false;
}
if (verifyPassword()) {
button.addClass('disabled');
var username = $('#username_field').val();
var password = $('#password_field').val();
var org_id = $('#org_id_org_idorg_id').val();
$.ajax({
type: "POST",
url: button.attr('data-url'),
data: { "user":{"username":username, "password":password, "org_id":org_id }},
cache: false,
success: function(data) {
button.removeClass('disabled');
KT.panel.list.add(data);
KT.panel.closePanel($('#panel'));
},
error: function(){button.removeClass('disabled');}
});
}
},
changePassword = function() {
var button = $(this);
var url = button.attr("data-url");
var password = $('#password_field').val();
button.addClass("disabled");
$.ajax({
type: "PUT",
url: url,
data: { "user":{"password":password}},
cache: false,
success: function() {
button.removeClass("disabled");
},
error: function(e) {
button.removeClass('disabled');
}
});
},
updateRoles = function(e) {
e.preventDefault();
var button = $(this).find('input[type|="submit"]');
button.attr("disabled","disabled");
$(this).ajaxSubmit({
success: function(data) {
button.removeAttr('disabled');
},
error: function(e) {
button.removeAttr('disabled');
}
});
},
registerEdits = function() {
$('#password_field').live('keyup.katello', verifyPassword);
$('#confirm_field').live('keyup.katello',verifyPassword);
$('#save_user').live('click', createNewUser);
$('#clear_helptips').live('click',clearHelptips);
$('#save_password').live('click',changePassword);
$('#update_roles').live('submit', updateRoles);
};
return {
createNewUser: createNewUser,
verifyPassword: verifyPassword,
changePassword: changePassword,
checkboxChanged: checkboxChanged,
clearHelptips: clearHelptips,
updateRoles: updateRoles,
registerEdits: registerEdits
}
}();