2 * Functions used in Setup configuration forms
5 // show this window in top frame
7 window
.top
.location
.href
= location
;
10 // ------------------------------------------------------------------
14 // stores hidden message ids
15 var hiddenMessages
= [];
18 var hidden
= hiddenMessages
.length
;
19 for (var i
= 0; i
< hidden
; i
++) {
20 $('#'+hiddenMessages
[i
]).css('display', 'none');
23 var link
= $('#show_hidden_messages');
24 link
.click(function(e
) {
26 for (var i
= 0; i
< hidden
; i
++) {
27 $('#'+hiddenMessages
[i
]).show(500);
31 link
.html(link
.html().replace('#MSG_COUNT', hidden
));
32 link
.css('display', '');
38 // ------------------------------------------------------------------
40 // ------------------------------------------------------------------
41 // Form validation and field operations
44 $.extend(true, validators
, {
50 * @param {boolean} isKeyUp
52 hide_db: function(isKeyUp
) {
53 if (!isKeyUp
&& this.value
!= '') {
55 data
[this.id
] = this.value
;
56 ajaxValidate(this, 'Servers/1/hide_db', data
);
61 * TrustedProxies field
63 * @param {boolean} isKeyUp
65 TrustedProxies: function(isKeyUp
) {
66 if (!isKeyUp
&& this.value
!= '') {
68 data
[this.id
] = this.value
;
69 ajaxValidate(this, 'TrustedProxies', data
);
74 // fieldset validators
77 * Validates Server fieldset
79 * @param {boolean} isKeyUp
81 Server: function(isKeyUp
) {
83 ajaxValidate(this, 'Server', getAllValues());
88 * Validates Server_login_options fieldset
90 * @param {boolean} isKeyUp
92 Server_login_options: function(isKeyUp
) {
93 return validators
._fieldset
.Server
.apply(this, [isKeyUp
]);
96 * Validates Server_pmadb fieldset
98 * @param {boolean} isKeyUp
100 Server_pmadb: function(isKeyUp
) {
105 var prefix
= getIdPrefix($(this).find('input'));
106 var pmadb_active
= $('#' + prefix
+ 'pmadb').val() != '';
108 ajaxValidate(this, 'Server_pmadb', getAllValues());
117 * Calls server-side validation procedures
119 * @param {Element} parent input field in <fieldset> or <fieldset>
120 * @param {String} id validator id
121 * @param {Object} values values hash {element1_id: value, ...}
123 function ajaxValidate(parent
, id
, values
)
126 // ensure that parent is a fieldset
127 if (parent
.attr('tagName') != 'FIELDSET') {
128 parent
= parent
.closest('fieldset');
129 if (parent
.length
== 0) {
134 if (parent
.data('ajax') != null) {
135 parent
.data('ajax').abort();
138 parent
.data('ajax', $.ajax({
143 token
: parent
.closest('form').find('input[name=token]').val(),
145 values
: $.toJSON(values
)
147 success: function(response
) {
148 if (response
== null) {
153 if (typeof response
!= 'object') {
154 error
[parent
.id
] = [response
];
155 } else if (typeof response
['error'] != 'undefined') {
156 error
[parent
.id
] = [response
['error']];
158 for (var key
in response
) {
159 var value
= response
[key
];
160 error
[key
] = jQuery
.isArray(value
) ? value
: [value
];
163 displayErrors(error
);
165 complete: function() {
166 parent
.removeData('ajax');
174 // END: Form validation and field operations
175 // ------------------------------------------------------------------
177 // ------------------------------------------------------------------
178 // User preferences allow/disallow UI
182 $('.userprefs-allow').click(function(e
) {
183 if (this != e
.target
) {
186 var el
= $(this).find('input');
187 if (el
.attr('disabled')) {
190 el
.attr('checked', !el
.attr('checked'));
195 // END: User preferences allow/disallow UI
196 // ------------------------------------------------------------------