Translated using Weblate (Slovenian)
[phpmyadmin.git] / setup / scripts.js
blobe912bec005eb7b616eb54fce16dffc2c17b7d148
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * Functions used in Setup configuration forms
4  */
6 // show this window in top frame
7 if (top != self) {
8     window.top.location.href = location;
11 // ------------------------------------------------------------------
12 // Messages
15 // stores hidden message ids
16 var hiddenMessages = [];
18 $(function () {
19     var hidden = hiddenMessages.length;
20     for (var i = 0; i < hidden; i++) {
21         $('#' + hiddenMessages[i]).css('display', 'none');
22     }
23     if (hidden > 0) {
24         var link = $('#show_hidden_messages');
25         link.click(function (e) {
26             e.preventDefault();
27             for (var i = 0; i < hidden; i++) {
28                 $('#' + hiddenMessages[i]).show(500);
29             }
30             $(this).remove();
31         });
32         link.html(link.html().replace('#MSG_COUNT', hidden));
33         link.css('display', '');
34     }
35 });
37 //set document width
38 $(document).ready(function(){
39     width = 0;
40     $('ul.tabs li').each(function(){
41         width += $(this).width() + 10;
42     });
43     var contentWidth = width;
44     width += 250;
45     $('body').css('min-width', width);
46     $('.tabs_contents').css('min-width', contentWidth);
47 });
50 // END: Messages
51 // ------------------------------------------------------------------
53 // ------------------------------------------------------------------
54 // Form validation and field operations
57 /**
58  * Calls server-side validation procedures
59  *
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, ...}
63  */
64 function ajaxValidate(parent, id, values)
66     parent = $(parent);
67     // ensure that parent is a fieldset
68     if (parent.attr('tagName') != 'FIELDSET') {
69         parent = parent.closest('fieldset');
70         if (parent.length === 0) {
71             return false;
72         }
73     }
75     if (parent.data('ajax') !== null) {
76         parent.data('ajax').abort();
77     }
79     parent.data('ajax', $.ajax({
80         url: 'validate.php',
81         cache: false,
82         type: 'POST',
83         data: {
84             token: parent.closest('form').find('input[name=token]').val(),
85             id: id,
86             values: JSON.stringify(values)
87         },
88         success: function (response) {
89             if (response === null) {
90                 return;
91             }
93             var error = {};
94             if (typeof response != 'object') {
95                 error[parent.id] = [response];
96             } else if (typeof response.error != 'undefined') {
97                 error[parent.id] = [response.error];
98             } else {
99                 for (var key in response) {
100                     var value = response[key];
101                     error[key] = jQuery.isArray(value) ? value : [value];
102                 }
103             }
104             displayErrors(error);
105         },
106         complete: function () {
107             parent.removeData('ajax');
108         }
109     }));
111     return true;
115  * Automatic form submission on change.
116  */
117 $(document).on('change', '.autosubmit', function (e) {
118     e.target.form.submit();
121 $.extend(true, validators, {
122     // field validators
123     _field: {
124         /**
125          * hide_db field
126          *
127          * @param {boolean} isKeyUp
128          */
129         hide_db: function (isKeyUp) {
130             if (!isKeyUp && this.value !== '') {
131                 var data = {};
132                 data[this.id] = this.value;
133                 ajaxValidate(this, 'Servers/1/hide_db', data);
134             }
135             return true;
136         },
137         /**
138          * TrustedProxies field
139          *
140          * @param {boolean} isKeyUp
141          */
142         TrustedProxies: function (isKeyUp) {
143             if (!isKeyUp && this.value !== '') {
144                 var data = {};
145                 data[this.id] = this.value;
146                 ajaxValidate(this, 'TrustedProxies', data);
147             }
148             return true;
149         }
150     },
151     // fieldset validators
152     _fieldset: {
153         /**
154          * Validates Server fieldset
155          *
156          * @param {boolean} isKeyUp
157          */
158         Server: function (isKeyUp) {
159             if (!isKeyUp) {
160                 ajaxValidate(this, 'Server', getAllValues());
161             }
162             return true;
163         },
164         /**
165          * Validates Server_login_options fieldset
166          *
167          * @param {boolean} isKeyUp
168          */
169         Server_login_options: function (isKeyUp) {
170             return validators._fieldset.Server.apply(this, [isKeyUp]);
171         },
172         /**
173          * Validates Server_pmadb fieldset
174          *
175          * @param {boolean} isKeyUp
176          */
177         Server_pmadb: function (isKeyUp) {
178             if (isKeyUp) {
179                 return true;
180             }
182             var prefix = getIdPrefix($(this).find('input'));
183             if ($('#' + prefix + 'pmadb').val() !== '') {
184                 ajaxValidate(this, 'Server_pmadb', getAllValues());
185             }
187             return true;
188         }
189     }
193 // END: Form validation and field operations
194 // ------------------------------------------------------------------
196 // ------------------------------------------------------------------
197 // User preferences allow/disallow UI
200 $(function () {
201     $('.userprefs-allow').click(function (e) {
202         if (this != e.target) {
203             return;
204         }
205         var el = $(this).find('input');
206         if (el.prop('disabled')) {
207             return;
208         }
209         el.prop('checked', !el.prop('checked'));
210     });
214 // END: User preferences allow/disallow UI
215 // ------------------------------------------------------------------