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 // ------------------------------------------------------------------
16 if (window.location.protocol === 'https:') {
17 $('#no_https').remove();
19 $('#no_https a').click(function () {
20 var old_location = window.location;
21 window.location.href = 'https:' + old_location.href.substring(old_location.protocol.length);
26 var hiddenmessages = $('.hiddenmessage');
28 if (hiddenmessages.length > 0) {
29 hiddenmessages.hide();
30 var link = $('#show_hidden_messages');
31 link.click(function (e) {
33 hiddenmessages.show();
36 link.html(link.html().replace('#MSG_COUNT', hiddenmessages.length));
42 $(document).ready(function () {
44 $('ul.tabs li').each(function () {
45 width += $(this).width() + 10;
47 var contentWidth = width;
49 $('body').css('min-width', width);
50 $('.tabs_contents').css('min-width', contentWidth);
55 // ------------------------------------------------------------------
57 // ------------------------------------------------------------------
58 // Form validation and field operations
62 * Calls server-side validation procedures
64 * @param {Element} parent input field in <fieldset> or <fieldset>
65 * @param {String} id validator id
66 * @param {Object} values values hash {element1_id: value, ...}
68 function ajaxValidate (parent, id, values) {
70 // ensure that parent is a fieldset
71 if (parent.attr('tagName') !== 'FIELDSET') {
72 parent = parent.closest('fieldset');
73 if (parent.length === 0) {
78 if (parent.data('ajax') !== null) {
79 parent.data('ajax').abort();
82 parent.data('ajax', $.ajax({
87 token: parent.closest('form').find('input[name=token]').val(),
89 values: JSON.stringify(values)
91 success: function (response) {
92 if (response === null) {
97 if (typeof response !== 'object') {
98 error[parent.id] = [response];
99 } else if (typeof response.error !== 'undefined') {
100 error[parent.id] = [response.error];
102 for (var key in response) {
103 var value = response[key];
104 error[key] = jQuery.isArray(value) ? value : [value];
107 displayErrors(error);
109 complete: function () {
110 parent.removeData('ajax');
118 * Automatic form submission on change.
120 $(document).on('change', '.autosubmit', function (e) {
121 e.target.form.submit();
124 $.extend(true, validators, {
130 * @param {boolean} isKeyUp
132 hide_db: function (isKeyUp) {
133 if (!isKeyUp && this.value !== '') {
135 data[this.id] = this.value;
136 ajaxValidate(this, 'Servers/1/hide_db', data);
141 * TrustedProxies field
143 * @param {boolean} isKeyUp
145 TrustedProxies: function (isKeyUp) {
146 if (!isKeyUp && this.value !== '') {
148 data[this.id] = this.value;
149 ajaxValidate(this, 'TrustedProxies', data);
154 // fieldset validators
157 * Validates Server fieldset
159 * @param {boolean} isKeyUp
161 Server: function (isKeyUp) {
163 ajaxValidate(this, 'Server', getAllValues());
168 * Validates Server_login_options fieldset
170 * @param {boolean} isKeyUp
172 Server_login_options: function (isKeyUp) {
173 return validators._fieldset.Server.apply(this, [isKeyUp]);
176 * Validates Server_pmadb fieldset
178 * @param {boolean} isKeyUp
180 Server_pmadb: function (isKeyUp) {
185 var prefix = getIdPrefix($(this).find('input'));
186 if ($('#' + prefix + 'pmadb').val() !== '') {
187 ajaxValidate(this, 'Server_pmadb', getAllValues());
196 // END: Form validation and field operations
197 // ------------------------------------------------------------------
199 // ------------------------------------------------------------------
200 // User preferences allow/disallow UI
204 $('.userprefs-allow').click(function (e) {
205 if (this !== e.target) {
208 var el = $(this).find('input');
209 if (el.prop('disabled')) {
212 el.prop('checked', !el.prop('checked'));
217 // END: User preferences allow/disallow UI
218 // ------------------------------------------------------------------