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 $(document).off('click', 'a.editLink');
8 $('#serverVariables').find('.var-name').find('a img').remove();
11 AJAX.registerOnload('server_variables.js', function () {
12 var $editLink = $('a.editLink');
13 var $saveLink = $('a.saveLink');
14 var $cancelLink = $('a.cancelLink');
16 $('#serverVariables').find('.var-name').find('a').append(
17 $('#docImage').clone().css('display', 'inline-block')
20 /* Launches the variable editor */
21 $(document).on('click', 'a.editLink', function (event) {
22 event.preventDefault();
26 /* Allows the user to edit a server variable */
27 function editVariable (link) {
29 var $cell = $link.parent();
30 var $valueCell = $link.parents('.var-row').find('.var-value');
31 var varName = $link.data('variable');
33 var $mySaveLink = $saveLink.clone().css('display', 'inline-block');
34 var $myCancelLink = $cancelLink.clone().css('display', 'inline-block');
35 var $msgbox = PMA_ajaxShowMessage();
36 var $myEditLink = $cell.find('a.editLink');
37 $cell.addClass('edit'); // variable is being edited
38 $myEditLink.remove(); // remove edit link
40 $mySaveLink.click(function () {
41 var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
42 $.post($(this).attr('href'), {
46 varValue: $valueCell.find('input').val()
51 .data('content', data.variable);
52 PMA_ajaxRemoveMessage($msgbox);
54 if (data.error === '') {
55 PMA_ajaxShowMessage(PMA_messages.strRequestFailed, false);
57 PMA_ajaxShowMessage(data.error, false);
59 $valueCell.html($valueCell.data('content'));
61 $cell.removeClass('edit').html($myEditLink);
66 $myCancelLink.click(function () {
67 $valueCell.html($valueCell.data('content'));
68 $cell.removeClass('edit').html($myEditLink);
72 $.get($mySaveLink.attr('href'), {
77 if (typeof data !== 'undefined' && data.success === true) {
78 var $links = $('<div />')
79 .append($myCancelLink)
80 .append(' ')
82 var $editor = $('<div />', { 'class': 'serverVariableEditor' })
85 $('<input />', { type: 'text' }).val(data.message)
88 // Save and replace content
92 .css('display', 'flex');
94 .data('content', $valueCell.html())
98 .keydown(function (event) { // Keyboard shortcuts
99 if (event.keyCode === 13) { // Enter key
100 $mySaveLink.trigger('click');
101 } else if (event.keyCode === 27) { // Escape key
102 $myCancelLink.trigger('click');
105 PMA_ajaxRemoveMessage($msgbox);
107 $cell.removeClass('edit').html($myEditLink);
108 PMA_ajaxShowMessage(data.error);