Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / setup / scripts.js
blobfe7f0e2fa82361c12d9cc3d522ac4cd9337b2a0f
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 });
38 // END: Messages
39 // ------------------------------------------------------------------
41 // ------------------------------------------------------------------
42 // Form validation and field operations
45 /**
46  * Automatic form submission on change.
47  */
48 $('.autosubmit').live('change', function(e) {
49     e.target.form.submit();
50 });
52 $.extend(true, validators, {
53     // field validators
54     _field: {
55         /**
56          * hide_db field
57          *
58          * @param {boolean} isKeyUp
59          */
60         hide_db: function(isKeyUp) {
61             if (!isKeyUp && this.value != '') {
62                 var data = {};
63                 data[this.id] = this.value;
64                 ajaxValidate(this, 'Servers/1/hide_db', data);
65             }
66             return true;
67         },
68         /**
69          * TrustedProxies field
70          *
71          * @param {boolean} isKeyUp
72          */
73         TrustedProxies: function(isKeyUp) {
74             if (!isKeyUp && this.value != '') {
75                 var data = {};
76                 data[this.id] = this.value;
77                 ajaxValidate(this, 'TrustedProxies', data);
78             }
79             return true;
80         }
81     },
82     // fieldset validators
83     _fieldset: {
84         /**
85          * Validates Server fieldset
86          *
87          * @param {boolean} isKeyUp
88          */
89         Server: function(isKeyUp) {
90             if (!isKeyUp) {
91                 ajaxValidate(this, 'Server', getAllValues());
92             }
93             return true;
94         },
95         /**
96          * Validates Server_login_options fieldset
97          *
98          * @param {boolean} isKeyUp
99          */
100         Server_login_options: function(isKeyUp) {
101             return validators._fieldset.Server.apply(this, [isKeyUp]);
102         },
103         /**
104          * Validates Server_pmadb fieldset
105          *
106          * @param {boolean} isKeyUp
107          */
108         Server_pmadb: function(isKeyUp) {
109             if (isKeyUp) {
110                 return true;
111             }
113             var prefix = getIdPrefix($(this).find('input'));
114             var pmadb_active = $('#' + prefix + 'pmadb').val() != '';
115             if (pmadb_active) {
116                 ajaxValidate(this, 'Server_pmadb', getAllValues());
117             }
119             return true;
120         }
121     }
125  * Calls server-side validation procedures
127  * @param {Element} parent  input field in <fieldset> or <fieldset>
128  * @param {String}  id      validator id
129  * @param {Object}  values  values hash {element1_id: value, ...}
130  */
131 function ajaxValidate(parent, id, values)
133     parent = $(parent);
134     // ensure that parent is a fieldset
135     if (parent.attr('tagName') != 'FIELDSET') {
136         parent = parent.closest('fieldset');
137         if (parent.length == 0) {
138             return false;
139         }
140     }
142     if (parent.data('ajax') != null) {
143         parent.data('ajax').abort();
144     }
146     parent.data('ajax', $.ajax({
147         url: 'validate.php',
148         cache: false,
149         type: 'POST',
150         data: {
151             token: parent.closest('form').find('input[name=token]').val(),
152             id: id,
153             values: $.toJSON(values)
154         },
155         success: function(response) {
156             if (response == null) {
157                 return;
158             }
160             var error = {};
161             if (typeof response != 'object') {
162                 error[parent.id] = [response];
163             } else if (typeof response['error'] != 'undefined') {
164                 error[parent.id] = [response['error']];
165             } else {
166                 for (var key in response) {
167                     var value = response[key];
168                     error[key] = jQuery.isArray(value) ? value : [value];
169                 }
170             }
171             displayErrors(error);
172         },
173         complete: function() {
174             parent.removeData('ajax');
175         }
176     }));
178     return true;
182 // END: Form validation and field operations
183 // ------------------------------------------------------------------
185 // ------------------------------------------------------------------
186 // User preferences allow/disallow UI
189 $(function() {
190    $('.userprefs-allow').click(function(e) {
191        if (this != e.target) {
192            return;
193        }
194        var el = $(this).find('input');
195        if (el.prop('disabled')) {
196            return;
197        }
198        el.prop('checked', !el.prop('checked'));
199    });
203 // END: User preferences allow/disallow UI
204 // ------------------------------------------------------------------