Translation update done using Pootle.
[phpmyadmin/ammaryasir.git] / setup / scripts.js
blobf223e0436f1647a2989ad3d39f0801b83d3c981b
1 /**
2 * Functions used in Setup configuration forms
3 */
5 // show this window in top frame
6 if (top != self) {
7 window.top.location.href = location;
10 // ------------------------------------------------------------------
11 // Messages
14 // stores hidden message ids
15 var hiddenMessages = [];
17 $(function() {
18 var hidden = hiddenMessages.length;
19 for (var i = 0; i < hidden; i++) {
20 $('#'+hiddenMessages[i]).css('display', 'none');
22 if (hidden > 0) {
23 var link = $('#show_hidden_messages');
24 link.click(function(e) {
25 e.preventDefault();
26 for (var i = 0; i < hidden; i++) {
27 $('#'+hiddenMessages[i]).show(500);
29 $(this).remove();
30 });
31 link.html(link.html().replace('#MSG_COUNT', hidden));
32 link.css('display', '');
34 });
37 // END: Messages
38 // ------------------------------------------------------------------
40 // ------------------------------------------------------------------
41 // Form validation and field operations
44 $.extend(true, validators, {
45 // field validators
46 _field: {
47 /**
48 * hide_db field
50 * @param {boolean} isKeyUp
52 hide_db: function(isKeyUp) {
53 if (!isKeyUp && this.value != '') {
54 var data = {};
55 data[this.id] = this.value;
56 ajaxValidate(this, 'Servers/1/hide_db', data);
58 return true;
60 /**
61 * TrustedProxies field
63 * @param {boolean} isKeyUp
65 TrustedProxies: function(isKeyUp) {
66 if (!isKeyUp && this.value != '') {
67 var data = {};
68 data[this.id] = this.value;
69 ajaxValidate(this, 'TrustedProxies', data);
71 return true;
74 // fieldset validators
75 _fieldset: {
76 /**
77 * Validates Server fieldset
79 * @param {boolean} isKeyUp
81 Server: function(isKeyUp) {
82 if (!isKeyUp) {
83 ajaxValidate(this, 'Server', getAllValues());
85 return true;
87 /**
88 * Validates Server_login_options fieldset
90 * @param {boolean} isKeyUp
92 Server_login_options: function(isKeyUp) {
93 return validators._fieldset.Server.apply(this, [isKeyUp]);
95 /**
96 * Validates Server_pmadb fieldset
98 * @param {boolean} isKeyUp
100 Server_pmadb: function(isKeyUp) {
101 if (isKeyUp) {
102 return true;
105 var prefix = getIdPrefix($(this).find('input'));
106 var pmadb_active = $('#' + prefix + 'pmadb').val() != '';
107 if (pmadb_active) {
108 ajaxValidate(this, 'Server_pmadb', getAllValues());
111 return true;
117 * Calls server-side validation procedures
119 * @param {Element} parent input field in <fieldset> or <fieldset>
120 * @param {String} id validator id
121 * @param {Object} values values hash {element1_id: value, ...}
123 function ajaxValidate(parent, id, values) {
124 parent = $(parent);
125 // ensure that parent is a fieldset
126 if (parent.attr('tagName') != 'FIELDSET') {
127 parent = parent.closest('fieldset');
128 if (parent.length == 0) {
129 return false;
133 if (parent.data('ajax') != null) {
134 parent.data('ajax').abort();
137 parent.data('ajax', $.ajax({
138 url: 'validate.php',
139 cache: false,
140 type: 'POST',
141 data: {
142 token: parent.closest('form').find('input[name=token]').val(),
143 id: id,
144 values: $.toJSON(values)
146 success: function(response) {
147 if (response == null) {
148 return;
151 var error = {};
152 if (typeof response != 'object') {
153 error[parent.id] = [response];
154 } else if (typeof response['error'] != 'undefined') {
155 error[parent.id] = [response['error']];
156 } else {
157 for (var key in response) {
158 var value = response[key];
159 error[key] = jQuery.isArray(value) ? value : [value];
162 displayErrors(error);
164 complete: function() {
165 parent.removeData('ajax');
167 }));
169 return true;
173 // END: Form validation and field operations
174 // ------------------------------------------------------------------
176 // ------------------------------------------------------------------
177 // User preferences allow/disallow UI
180 $(function() {
181 $('.userprefs-allow').click(function(e) {
182 if (this != e.target) {
183 return;
185 var el = $(this).find('input');
186 if (el.attr('disabled')) {
187 return;
189 el.attr('checked', !el.attr('checked'));
194 // END: User preferences allow/disallow UI
195 // ------------------------------------------------------------------