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 $('#serverVariables .var-row').unbind('hover');
8 $('#filterText').unbind('keyup');
9 $('a.editLink').die('click');
10 $('#serverVariables').find('.var-name').find('a img').remove();
13 AJAX.registerOnload('server_variables.js', function () {
14 var $editLink = $('a.editLink');
15 var $saveLink = $('a.saveLink');
16 var $cancelLink = $('a.cancelLink');
17 var $filterField = $('#filterText');
19 /* Show edit link on hover */
20 $('#serverVariables').delegate('.var-row', 'hover', function (event) {
21 if (event.type === 'mouseenter') {
22 var $elm = $(this).find('.var-value');
23 // Only add edit element if the element is not being edited
24 if ($elm.hasClass('editable') && ! $elm.hasClass('edit')) {
25 $elm.prepend($editLink.clone().show());
28 $(this).find('a.editLink').remove();
30 }).find('.var-name').find('a').append(
31 $('#docImage').clone().show()
34 /* Launches the variable editor */
35 $editLink.live('click', function (event) {
36 event.preventDefault();
40 /* Event handler for variables filter */
41 $filterField.keyup(function () {
42 var textFilter = null, val = $(this).val();
43 if (val.length !== 0) {
44 textFilter = new RegExp("(^| )" + val.replace(/_/g, ' '), 'i');
46 filterVariables(textFilter);
49 /* Trigger filtering of the list based on incoming variable name */
50 if ($filterField.val()) {
51 $filterField.trigger('keyup').select();
54 /* Filters the rows by the user given regexp */
55 function filterVariables(textFilter) {
56 var mark_next = false, $row, odd_row = false;
57 $('#serverVariables .var-row').not('.var-header').each(function () {
59 if (mark_next || textFilter === null ||
60 textFilter.exec($row.find('.var-name').text())
62 // If current global value is different from session value
63 // (has class diffSession), then display that one too
64 mark_next = $row.hasClass('diffSession') && ! mark_next;
67 $row.css('display', '');
69 $row.addClass('odd').removeClass('even');
71 $row.addClass('even').removeClass('odd');
74 $row.css('display', 'none');
79 /* Allows the user to edit a server variable */
80 function editVariable(link) {
81 var $cell = $(link).parent();
82 var varName = $cell.parent().find('.var-name').text().replace(/ /g, '_');
83 var $mySaveLink = $saveLink.clone().show();
84 var $myCancelLink = $cancelLink.clone().show();
85 var $msgbox = PMA_ajaxShowMessage();
88 .addClass('edit') // variable is being edited
90 .remove(); // remove edit link
92 $mySaveLink.click(function () {
93 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
94 $.get($(this).attr('href'), {
98 varValue: $cell.find('input').val()
103 .data('content', data.variable);
104 PMA_ajaxRemoveMessage($msgbox);
106 PMA_ajaxShowMessage(data.error, false);
107 $cell.html($cell.data('content'));
109 $cell.removeClass('edit');
114 $myCancelLink.click(function () {
116 .html($cell.data('content'))
117 .removeClass('edit');
121 $.get($mySaveLink.attr('href'), {
126 if (data.success === true) {
127 var $editor = $('<div />', {'class': 'serverVariableEditor'})
128 .append($myCancelLink)
134 $('<input />', {type: 'text'}).val(data.message)
137 // Save and replace content
139 .data('content', $cell.html())
143 .keydown(function (event) { // Keyboard shortcuts
144 if (event.keyCode === 13) { // Enter key
145 $mySaveLink.trigger('click');
146 } else if (event.keyCode === 27) { // Escape key
147 $myCancelLink.trigger('click');
150 PMA_ajaxRemoveMessage($msgbox);
152 $cell.removeClass('edit');
153 PMA_ajaxShowMessage(data.error);