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 // ------------------------------------------------------------------
15 // stores hidden message ids
16 var hiddenMessages = [];
19 var hidden = hiddenMessages.length;
20 for (var i = 0; i < hidden; i++) {
21 $('#' + hiddenMessages[i]).css('display', 'none');
24 var link = $('#show_hidden_messages');
25 link.click(function (e) {
27 for (var i = 0; i < hidden; i++) {
28 $('#' + hiddenMessages[i]).show(500);
32 link.html(link.html().replace('#MSG_COUNT', hidden));
33 link.css('display', '');
39 // ------------------------------------------------------------------
41 // ------------------------------------------------------------------
42 // Form validation and field operations
46 * Calls server-side validation procedures
48 * @param {Element} parent input field in <fieldset> or <fieldset>
49 * @param {String} id validator id
50 * @param {Object} values values hash {element1_id: value, ...}
52 function ajaxValidate(parent, id, values)
55 // ensure that parent is a fieldset
56 if (parent.attr('tagName') != 'FIELDSET') {
57 parent = parent.closest('fieldset');
58 if (parent.length === 0) {
63 if (parent.data('ajax') !== null) {
64 parent.data('ajax').abort();
67 parent.data('ajax', $.ajax({
72 token: parent.closest('form').find('input[name=token]').val(),
74 values: $.toJSON(values)
76 success: function (response) {
77 if (response === null) {
82 if (typeof response != 'object') {
83 error[parent.id] = [response];
84 } else if (typeof response.error != 'undefined') {
85 error[parent.id] = [response.error];
87 for (var key in response) {
88 var value = response[key];
89 error[key] = jQuery.isArray(value) ? value : [value];
94 complete: function () {
95 parent.removeData('ajax');
103 * Automatic form submission on change.
105 $('.autosubmit').live('change', function (e) {
106 e.target.form.submit();
109 $.extend(true, validators, {
115 * @param {boolean} isKeyUp
117 hide_db: function (isKeyUp) {
118 if (!isKeyUp && this.value !== '') {
120 data[this.id] = this.value;
121 ajaxValidate(this, 'Servers/1/hide_db', data);
126 * TrustedProxies field
128 * @param {boolean} isKeyUp
130 TrustedProxies: function (isKeyUp) {
131 if (!isKeyUp && this.value !== '') {
133 data[this.id] = this.value;
134 ajaxValidate(this, 'TrustedProxies', data);
139 // fieldset validators
142 * Validates Server fieldset
144 * @param {boolean} isKeyUp
146 Server: function (isKeyUp) {
148 ajaxValidate(this, 'Server', getAllValues());
153 * Validates Server_login_options fieldset
155 * @param {boolean} isKeyUp
157 Server_login_options: function (isKeyUp) {
158 return validators._fieldset.Server.apply(this, [isKeyUp]);
161 * Validates Server_pmadb fieldset
163 * @param {boolean} isKeyUp
165 Server_pmadb: function (isKeyUp) {
170 var prefix = getIdPrefix($(this).find('input'));
171 if ($('#' + prefix + 'pmadb').val() !== '') {
172 ajaxValidate(this, 'Server_pmadb', getAllValues());
181 // END: Form validation and field operations
182 // ------------------------------------------------------------------
184 // ------------------------------------------------------------------
185 // User preferences allow/disallow UI
189 $('.userprefs-allow').click(function (e) {
190 if (this != e.target) {
193 var el = $(this).find('input');
194 if (el.prop('disabled')) {
197 el.prop('checked', !el.prop('checked'));
202 // END: User preferences allow/disallow UI
203 // ------------------------------------------------------------------