1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Functions used in Setup configuration forms
6 // show this window in top frame
8 window.top.location.href = location;
11 // ------------------------------------------------------------------
15 // stores hidden message ids
16 var hiddenMessages = [];
19 var hidden = hiddenMessages.length;
20 for (var i = 0; i < hidden; i++) {
21 $('#'+hiddenMessages[i]).css('display', 'none');
24 var link = $('#show_hidden_messages');
25 link.click(function(e) {
27 for (var i = 0; i < hidden; i++) {
28 $('#'+hiddenMessages[i]).show(500);
32 link.html(link.html().replace('#MSG_COUNT', hidden));
33 link.css('display', '');
39 // ------------------------------------------------------------------
41 // ------------------------------------------------------------------
42 // Form validation and field operations
46 * Automatic form submission on change.
48 $('.autosubmit').live('change', function(e) {
49 e.target.form.submit();
52 $.extend(true, validators, {
58 * @param {boolean} isKeyUp
60 hide_db: function(isKeyUp) {
61 if (!isKeyUp && this.value != '') {
63 data[this.id] = this.value;
64 ajaxValidate(this, 'Servers/1/hide_db', data);
69 * TrustedProxies field
71 * @param {boolean} isKeyUp
73 TrustedProxies: function(isKeyUp) {
74 if (!isKeyUp && this.value != '') {
76 data[this.id] = this.value;
77 ajaxValidate(this, 'TrustedProxies', data);
82 // fieldset validators
85 * Validates Server fieldset
87 * @param {boolean} isKeyUp
89 Server: function(isKeyUp) {
91 ajaxValidate(this, 'Server', getAllValues());
96 * Validates Server_login_options fieldset
98 * @param {boolean} isKeyUp
100 Server_login_options: function(isKeyUp) {
101 return validators._fieldset.Server.apply(this, [isKeyUp]);
104 * Validates Server_pmadb fieldset
106 * @param {boolean} isKeyUp
108 Server_pmadb: function(isKeyUp) {
113 var prefix = getIdPrefix($(this).find('input'));
114 var pmadb_active = $('#' + prefix + 'pmadb').val() != '';
116 ajaxValidate(this, 'Server_pmadb', getAllValues());
125 * Calls server-side validation procedures
127 * @param {Element} parent input field in <fieldset> or <fieldset>
128 * @param {String} id validator id
129 * @param {Object} values values hash {element1_id: value, ...}
131 function ajaxValidate(parent, id, values)
134 // ensure that parent is a fieldset
135 if (parent.attr('tagName') != 'FIELDSET') {
136 parent = parent.closest('fieldset');
137 if (parent.length == 0) {
142 if (parent.data('ajax') != null) {
143 parent.data('ajax').abort();
146 parent.data('ajax', $.ajax({
151 token: parent.closest('form').find('input[name=token]').val(),
153 values: $.toJSON(values)
155 success: function(response) {
156 if (response == null) {
161 if (typeof response != 'object') {
162 error[parent.id] = [response];
163 } else if (typeof response['error'] != 'undefined') {
164 error[parent.id] = [response['error']];
166 for (var key in response) {
167 var value = response[key];
168 error[key] = jQuery.isArray(value) ? value : [value];
171 displayErrors(error);
173 complete: function() {
174 parent.removeData('ajax');
182 // END: Form validation and field operations
183 // ------------------------------------------------------------------
185 // ------------------------------------------------------------------
186 // User preferences allow/disallow UI
190 $('.userprefs-allow').click(function(e) {
191 if (this != e.target) {
194 var el = $(this).find('input');
195 if (el.prop('disabled')) {
198 el.prop('checked', !el.prop('checked'));
203 // END: User preferences allow/disallow UI
204 // ------------------------------------------------------------------