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', '');
38 $(document).ready(function(){
40 $('ul.tabs li').each(function(){
41 width += $(this).width() + 10;
43 var contentWidth = width;
45 $('body').css('min-width', width);
46 $('.tabs_contents').css('min-width', contentWidth);
51 // ------------------------------------------------------------------
53 // ------------------------------------------------------------------
54 // Form validation and field operations
58 * Calls server-side validation procedures
60 * @param {Element} parent input field in <fieldset> or <fieldset>
61 * @param {String} id validator id
62 * @param {Object} values values hash {element1_id: value, ...}
64 function ajaxValidate(parent, id, values)
67 // ensure that parent is a fieldset
68 if (parent.attr('tagName') != 'FIELDSET') {
69 parent = parent.closest('fieldset');
70 if (parent.length === 0) {
75 if (parent.data('ajax') !== null) {
76 parent.data('ajax').abort();
79 parent.data('ajax', $.ajax({
84 token: parent.closest('form').find('input[name=token]').val(),
86 values: JSON.stringify(values)
88 success: function (response) {
89 if (response === null) {
94 if (typeof response != 'object') {
95 error[parent.id] = [response];
96 } else if (typeof response.error != 'undefined') {
97 error[parent.id] = [response.error];
99 for (var key in response) {
100 var value = response[key];
101 error[key] = jQuery.isArray(value) ? value : [value];
104 displayErrors(error);
106 complete: function () {
107 parent.removeData('ajax');
115 * Automatic form submission on change.
117 $(document).on('change', '.autosubmit', function (e) {
118 e.target.form.submit();
121 $.extend(true, validators, {
127 * @param {boolean} isKeyUp
129 hide_db: function (isKeyUp) {
130 if (!isKeyUp && this.value !== '') {
132 data[this.id] = this.value;
133 ajaxValidate(this, 'Servers/1/hide_db', data);
138 * TrustedProxies field
140 * @param {boolean} isKeyUp
142 TrustedProxies: function (isKeyUp) {
143 if (!isKeyUp && this.value !== '') {
145 data[this.id] = this.value;
146 ajaxValidate(this, 'TrustedProxies', data);
151 // fieldset validators
154 * Validates Server fieldset
156 * @param {boolean} isKeyUp
158 Server: function (isKeyUp) {
160 ajaxValidate(this, 'Server', getAllValues());
165 * Validates Server_login_options fieldset
167 * @param {boolean} isKeyUp
169 Server_login_options: function (isKeyUp) {
170 return validators._fieldset.Server.apply(this, [isKeyUp]);
173 * Validates Server_pmadb fieldset
175 * @param {boolean} isKeyUp
177 Server_pmadb: function (isKeyUp) {
182 var prefix = getIdPrefix($(this).find('input'));
183 if ($('#' + prefix + 'pmadb').val() !== '') {
184 ajaxValidate(this, 'Server_pmadb', getAllValues());
193 // END: Form validation and field operations
194 // ------------------------------------------------------------------
196 // ------------------------------------------------------------------
197 // User preferences allow/disallow UI
201 $('.userprefs-allow').click(function (e) {
202 if (this != e.target) {
205 var el = $(this).find('input');
206 if (el.prop('disabled')) {
209 el.prop('checked', !el.prop('checked'));
214 // END: User preferences allow/disallow UI
215 // ------------------------------------------------------------------