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 var tabWidth = $(this).width() + 10;
44 var contentWidth = width;
46 $('body').css('min-width', width);
47 $('.tabs_contents').css('min-width', contentWidth);
52 // ------------------------------------------------------------------
54 // ------------------------------------------------------------------
55 // Form validation and field operations
59 * Calls server-side validation procedures
61 * @param {Element} parent input field in <fieldset> or <fieldset>
62 * @param {String} id validator id
63 * @param {Object} values values hash {element1_id: value, ...}
65 function ajaxValidate(parent, id, values)
68 // ensure that parent is a fieldset
69 if (parent.attr('tagName') != 'FIELDSET') {
70 parent = parent.closest('fieldset');
71 if (parent.length === 0) {
76 if (parent.data('ajax') !== null) {
77 parent.data('ajax').abort();
80 parent.data('ajax', $.ajax({
85 token: parent.closest('form').find('input[name=token]').val(),
87 values: JSON.stringify(values)
89 success: function (response) {
90 if (response === null) {
95 if (typeof response != 'object') {
96 error[parent.id] = [response];
97 } else if (typeof response.error != 'undefined') {
98 error[parent.id] = [response.error];
100 for (var key in response) {
101 var value = response[key];
102 error[key] = jQuery.isArray(value) ? value : [value];
105 displayErrors(error);
107 complete: function () {
108 parent.removeData('ajax');
116 * Automatic form submission on change.
118 $(document).on('change', '.autosubmit', function (e) {
119 e.target.form.submit();
122 $.extend(true, validators, {
128 * @param {boolean} isKeyUp
130 hide_db: function (isKeyUp) {
131 if (!isKeyUp && this.value !== '') {
133 data[this.id] = this.value;
134 ajaxValidate(this, 'Servers/1/hide_db', data);
139 * TrustedProxies field
141 * @param {boolean} isKeyUp
143 TrustedProxies: function (isKeyUp) {
144 if (!isKeyUp && this.value !== '') {
146 data[this.id] = this.value;
147 ajaxValidate(this, 'TrustedProxies', data);
152 // fieldset validators
155 * Validates Server fieldset
157 * @param {boolean} isKeyUp
159 Server: function (isKeyUp) {
161 ajaxValidate(this, 'Server', getAllValues());
166 * Validates Server_login_options fieldset
168 * @param {boolean} isKeyUp
170 Server_login_options: function (isKeyUp) {
171 return validators._fieldset.Server.apply(this, [isKeyUp]);
174 * Validates Server_pmadb fieldset
176 * @param {boolean} isKeyUp
178 Server_pmadb: function (isKeyUp) {
183 var prefix = getIdPrefix($(this).find('input'));
184 if ($('#' + prefix + 'pmadb').val() !== '') {
185 ajaxValidate(this, 'Server_pmadb', getAllValues());
194 // END: Form validation and field operations
195 // ------------------------------------------------------------------
197 // ------------------------------------------------------------------
198 // User preferences allow/disallow UI
202 $('.userprefs-allow').click(function (e) {
203 if (this != e.target) {
206 var el = $(this).find('input');
207 if (el.prop('disabled')) {
210 el.prop('checked', !el.prop('checked'));
215 // END: User preferences allow/disallow UI
216 // ------------------------------------------------------------------