Merge #15685 - Fix #15682 - Timestamp method not taking current time
[phpmyadmin.git] / js / server_variables.js
blob6b7f01faf1a7d893d3cd44283d8b4dfacb031a51
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4  * Unbind all event handlers before tearing down a page
5  */
6 AJAX.registerTeardown('server_variables.js', function () {
7     $(document).off('click', 'a.editLink');
8     $('#serverVariables').find('.var-name').find('a img').remove();
9 });
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')
18     );
20     /* Launches the variable editor */
21     $(document).on('click', 'a.editLink', function (event) {
22         event.preventDefault();
23         editVariable(this);
24     });
26     /* Allows the user to edit a server variable */
27     function editVariable (link) {
28         var $link = $(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'), {
43                 ajax_request: true,
44                 type: 'setval',
45                 varName: varName,
46                 varValue: $valueCell.find('input').val()
47             }, function (data) {
48                 if (data.success) {
49                     $valueCell
50                         .html(data.variable)
51                         .data('content', data.variable);
52                     PMA_ajaxRemoveMessage($msgbox);
53                 } else {
54                     if (data.error === '') {
55                         PMA_ajaxShowMessage(PMA_messages.strRequestFailed, false);
56                     } else {
57                         PMA_ajaxShowMessage(data.error, false);
58                     }
59                     $valueCell.html($valueCell.data('content'));
60                 }
61                 $cell.removeClass('edit').html($myEditLink);
62             });
63             return false;
64         });
66         $myCancelLink.click(function () {
67             $valueCell.html($valueCell.data('content'));
68             $cell.removeClass('edit').html($myEditLink);
69             return false;
70         });
72         $.get($mySaveLink.attr('href'), {
73             ajax_request: true,
74             type: 'getval',
75             varName: varName
76         }, function (data) {
77             if (typeof data !== 'undefined' && data.success === true) {
78                 var $links = $('<div />')
79                     .append($myCancelLink)
80                     .append('&nbsp;&nbsp;&nbsp;')
81                     .append($mySaveLink);
82                 var $editor = $('<div />', { 'class': 'serverVariableEditor' })
83                     .append(
84                         $('<div/>').append(
85                             $('<input />', { type: 'text' }).val(data.message)
86                         )
87                     );
88                     // Save and replace content
89                 $cell
90                     .html($links)
91                     .children()
92                     .css('display', 'flex');
93                 $valueCell
94                     .data('content', $valueCell.html())
95                     .html($editor)
96                     .find('input')
97                     .focus()
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');
103                         }
104                     });
105                 PMA_ajaxRemoveMessage($msgbox);
106             } else {
107                 $cell.removeClass('edit').html($myEditLink);
108                 PMA_ajaxShowMessage(data.error);
109             }
110         });
111     }