1 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Unbind all event handlers before tearing down a page
6 AJAX.registerTeardown('server_variables.js', function () {
7 $('#filterText').unbind('keyup');
8 $(document).off('click', 'a.editLink');
9 $('#serverVariables').find('.var-name').find('a img').remove();
12 AJAX.registerOnload('server_variables.js', function () {
13 var $editLink = $('a.editLink');
14 var $saveLink = $('a.saveLink');
15 var $cancelLink = $('a.cancelLink');
16 var $filterField = $('#filterText');
19 $('#serverVariables').find('.var-name').find('a').append(
20 $('#docImage').clone().show()
23 /* Launches the variable editor */
24 $(document).on('click', 'a.editLink', function (event) {
25 event.preventDefault();
29 /* Event handler for variables filter */
30 $filterField.keyup(function () {
31 var textFilter = null, val = $(this).val();
32 if (val.length !== 0) {
34 textFilter = new RegExp("(^| )" + val.replace(/_/g, ' '), 'i');
35 $(this).removeClass('error');
37 if (e instanceof SyntaxError) {
38 $(this).addClass('error');
43 filterVariables(textFilter);
46 /* Trigger filtering of the list based on incoming variable name */
47 if ($filterField.val()) {
48 $filterField.trigger('keyup').select();
51 /* Filters the rows by the user given regexp */
52 function filterVariables(textFilter) {
53 var mark_next = false, $row;
54 $('#serverVariables').find('.var-row').not('.var-header').each(function () {
56 if (mark_next || textFilter === null ||
57 textFilter.exec($row.find('.var-name').text())
59 // If current global value is different from session value
60 // (has class diffSession), then display that one too
61 mark_next = $row.hasClass('diffSession') && ! mark_next;
62 $row.css('display', '');
64 $row.css('display', 'none');
69 /* Allows the user to edit a server variable */
70 function editVariable(link) {
72 var $cell = $link.parent();
73 var $valueCell = $link.parents('.var-row').find('.var-value');
74 var varName = $link.data('variable');
75 var $mySaveLink = $saveLink.clone().show();
76 var $myCancelLink = $cancelLink.clone().show();
77 var $msgbox = PMA_ajaxShowMessage();
78 var $myEditLink = $cell.find('a.editLink');
80 $cell.addClass('edit'); // variable is being edited
81 $myEditLink.remove(); // remove edit link
83 $mySaveLink.click(function () {
84 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
85 $.post($(this).attr('href'), {
89 varValue: $valueCell.find('input').val(),
90 token: PMA_commonParams.get('token')
95 .data('content', data.variable);
96 PMA_ajaxRemoveMessage($msgbox);
98 if (data.error == '') {
99 PMA_ajaxShowMessage(PMA_messages.strRequestFailed, false);
101 PMA_ajaxShowMessage(data.error, false);
103 $valueCell.html($valueCell.data('content'));
105 $cell.removeClass('edit').html($myEditLink);
110 $myCancelLink.click(function () {
111 $valueCell.html($valueCell.data('content'));
112 $cell.removeClass('edit').html($myEditLink);
116 $.get($mySaveLink.attr('href'), {
121 if (typeof data !== 'undefined' && data.success === true) {
122 var $links = $('<div />')
123 .append($myCancelLink)
124 .append(' ')
125 .append($mySaveLink);
126 var $editor = $('<div />', {'class': 'serverVariableEditor'})
129 $('<input />', {type: 'text'}).val(data.message)
132 // Save and replace content
136 .data('content', $valueCell.html())
140 .keydown(function (event) { // Keyboard shortcuts
141 if (event.keyCode === 13) { // Enter key
142 $mySaveLink.trigger('click');
143 } else if (event.keyCode === 27) { // Escape key
144 $myCancelLink.trigger('click');
147 PMA_ajaxRemoveMessage($msgbox);
149 $cell.removeClass('edit').html($myEditLink);
150 PMA_ajaxShowMessage(data.error);