added japanese language
[openemr.git] / phpmyadmin / setup / scripts.js
blob2aefdf03f68887390f1d92436875896601cecfe1
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         tabWidth = $(this).width() + 10;
42         width += tabWidth;
43      });
44      contentWidth = width;
45      width += 250;
46      $('body').css('min-width', width);
47      $('.tabs_contents').css('min-width', contentWidth);
48 });
51 // END: Messages
52 // ------------------------------------------------------------------
54 // ------------------------------------------------------------------
55 // Form validation and field operations
58 /**
59  * Calls server-side validation procedures
60  *
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, ...}
64  */
65 function ajaxValidate(parent, id, values)
67     parent = $(parent);
68     // ensure that parent is a fieldset
69     if (parent.attr('tagName') != 'FIELDSET') {
70         parent = parent.closest('fieldset');
71         if (parent.length === 0) {
72             return false;
73         }
74     }
76     if (parent.data('ajax') !== null) {
77         parent.data('ajax').abort();
78     }
80     parent.data('ajax', $.ajax({
81         url: 'validate.php',
82         cache: false,
83         type: 'POST',
84         data: {
85             token: parent.closest('form').find('input[name=token]').val(),
86             id: id,
87             values: JSON.stringify(values)
88         },
89         success: function (response) {
90             if (response === null) {
91                 return;
92             }
94             var error = {};
95             if (typeof response != 'object') {
96                 error[parent.id] = [response];
97             } else if (typeof response.error != 'undefined') {
98                 error[parent.id] = [response.error];
99             } else {
100                 for (var key in response) {
101                     var value = response[key];
102                     error[key] = jQuery.isArray(value) ? value : [value];
103                 }
104             }
105             displayErrors(error);
106         },
107         complete: function () {
108             parent.removeData('ajax');
109         }
110     }));
112     return true;
116  * Automatic form submission on change.
117  */
118 $('.autosubmit').live('change', function (e) {
119     e.target.form.submit();
122 $.extend(true, validators, {
123     // field validators
124     _field: {
125         /**
126          * hide_db field
127          *
128          * @param {boolean} isKeyUp
129          */
130         hide_db: function (isKeyUp) {
131             if (!isKeyUp && this.value !== '') {
132                 var data = {};
133                 data[this.id] = this.value;
134                 ajaxValidate(this, 'Servers/1/hide_db', data);
135             }
136             return true;
137         },
138         /**
139          * TrustedProxies field
140          *
141          * @param {boolean} isKeyUp
142          */
143         TrustedProxies: function (isKeyUp) {
144             if (!isKeyUp && this.value !== '') {
145                 var data = {};
146                 data[this.id] = this.value;
147                 ajaxValidate(this, 'TrustedProxies', data);
148             }
149             return true;
150         }
151     },
152     // fieldset validators
153     _fieldset: {
154         /**
155          * Validates Server fieldset
156          *
157          * @param {boolean} isKeyUp
158          */
159         Server: function (isKeyUp) {
160             if (!isKeyUp) {
161                 ajaxValidate(this, 'Server', getAllValues());
162             }
163             return true;
164         },
165         /**
166          * Validates Server_login_options fieldset
167          *
168          * @param {boolean} isKeyUp
169          */
170         Server_login_options: function (isKeyUp) {
171             return validators._fieldset.Server.apply(this, [isKeyUp]);
172         },
173         /**
174          * Validates Server_pmadb fieldset
175          *
176          * @param {boolean} isKeyUp
177          */
178         Server_pmadb: function (isKeyUp) {
179             if (isKeyUp) {
180                 return true;
181             }
183             var prefix = getIdPrefix($(this).find('input'));
184             if ($('#' + prefix + 'pmadb').val() !== '') {
185                 ajaxValidate(this, 'Server_pmadb', getAllValues());
186             }
188             return true;
189         }
190     }
194 // END: Form validation and field operations
195 // ------------------------------------------------------------------
197 // ------------------------------------------------------------------
198 // User preferences allow/disallow UI
201 $(function () {
202     $('.userprefs-allow').click(function (e) {
203         if (this != e.target) {
204             return;
205         }
206         var el = $(this).find('input');
207         if (el.prop('disabled')) {
208             return;
209         }
210         el.prop('checked', !el.prop('checked'));
211     });
215 // END: User preferences allow/disallow UI
216 // ------------------------------------------------------------------