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 // ------------------------------------------------------------------
17 if (window.location.protocol === 'https:') {
18 $('#no_https').remove();
20 $('#no_https a').click(function () {
21 var old_location = window.location;
22 window.location.href = 'https:' + old_location.href.substring(old_location.protocol.length);
27 var hiddenmessages = $('.hiddenmessage');
29 if (hiddenmessages.length > 0) {
30 hiddenmessages.hide();
31 var link = $('#show_hidden_messages');
32 link.click(function (e) {
34 hiddenmessages.show();
37 link.html(link.html().replace('#MSG_COUNT', hiddenmessages.length));
43 $(document).ready(function(){
45 $('ul.tabs li').each(function(){
46 width += $(this).width() + 10;
48 var contentWidth = width;
50 $('body').css('min-width', width);
51 $('.tabs_contents').css('min-width', contentWidth);
56 // ------------------------------------------------------------------
58 // ------------------------------------------------------------------
59 // Form validation and field operations
63 * Calls server-side validation procedures
65 * @param {Element} parent input field in <fieldset> or <fieldset>
66 * @param {String} id validator id
67 * @param {Object} values values hash {element1_id: value, ...}
69 function ajaxValidate(parent, id, values)
72 // ensure that parent is a fieldset
73 if (parent.attr('tagName') != 'FIELDSET') {
74 parent = parent.closest('fieldset');
75 if (parent.length === 0) {
80 if (parent.data('ajax') !== null) {
81 parent.data('ajax').abort();
84 parent.data('ajax', $.ajax({
89 token: parent.closest('form').find('input[name=token]').val(),
91 values: JSON.stringify(values)
93 success: function (response) {
94 if (response === null) {
99 if (typeof response != 'object') {
100 error[parent.id] = [response];
101 } else if (typeof response.error != 'undefined') {
102 error[parent.id] = [response.error];
104 for (var key in response) {
105 var value = response[key];
106 error[key] = jQuery.isArray(value) ? value : [value];
109 displayErrors(error);
111 complete: function () {
112 parent.removeData('ajax');
120 * Automatic form submission on change.
122 $(document).on('change', '.autosubmit', function (e) {
123 e.target.form.submit();
126 $.extend(true, validators, {
132 * @param {boolean} isKeyUp
134 hide_db: function (isKeyUp) {
135 if (!isKeyUp && this.value !== '') {
137 data[this.id] = this.value;
138 ajaxValidate(this, 'Servers/1/hide_db', data);
143 * TrustedProxies field
145 * @param {boolean} isKeyUp
147 TrustedProxies: function (isKeyUp) {
148 if (!isKeyUp && this.value !== '') {
150 data[this.id] = this.value;
151 ajaxValidate(this, 'TrustedProxies', data);
156 // fieldset validators
159 * Validates Server fieldset
161 * @param {boolean} isKeyUp
163 Server: function (isKeyUp) {
165 ajaxValidate(this, 'Server', getAllValues());
170 * Validates Server_login_options fieldset
172 * @param {boolean} isKeyUp
174 Server_login_options: function (isKeyUp) {
175 return validators._fieldset.Server.apply(this, [isKeyUp]);
178 * Validates Server_pmadb fieldset
180 * @param {boolean} isKeyUp
182 Server_pmadb: function (isKeyUp) {
187 var prefix = getIdPrefix($(this).find('input'));
188 if ($('#' + prefix + 'pmadb').val() !== '') {
189 ajaxValidate(this, 'Server_pmadb', getAllValues());
198 // END: Form validation and field operations
199 // ------------------------------------------------------------------
201 // ------------------------------------------------------------------
202 // User preferences allow/disallow UI
206 $('.userprefs-allow').click(function (e) {
207 if (this != e.target) {
210 var el = $(this).find('input');
211 if (el.prop('disabled')) {
214 el.prop('checked', !el.prop('checked'));
219 // END: User preferences allow/disallow UI
220 // ------------------------------------------------------------------