variables.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. /**
  3. *
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. /**
  8. * Unbind all event handlers before tearing down a page
  9. */
  10. AJAX.registerTeardown('server/status/variables.js', function () {
  11. $('#filterAlert').off('change');
  12. $('#filterText').off('keyup');
  13. $('#filterCategory').off('change');
  14. $('#dontFormat').off('change');
  15. });
  16. AJAX.registerOnload('server/status/variables.js', function () {
  17. // Filters for status variables
  18. var textFilter = null;
  19. var alertFilter = $('#filterAlert').prop('checked');
  20. var categoryFilter = $('#filterCategory').find(':selected').val();
  21. var text = ''; // Holds filter text
  22. /* 3 Filtering functions */
  23. $('#filterAlert').on('change', function () {
  24. alertFilter = this.checked;
  25. filterVariables();
  26. });
  27. $('#filterCategory').on('change', function () {
  28. categoryFilter = $(this).val();
  29. filterVariables();
  30. });
  31. $('#dontFormat').on('change', function () {
  32. // Hiding the table while changing values speeds up the process a lot
  33. var serverStatusVariables = $('#serverStatusVariables');
  34. serverStatusVariables.hide();
  35. serverStatusVariables.find('td.value span.original').toggle(this.checked);
  36. serverStatusVariables.find('td.value span.formatted').toggle(!this.checked);
  37. serverStatusVariables.show();
  38. }).trigger('change');
  39. $('#filterText').on('keyup', function () {
  40. var word = $(this).val().replace(/_/g, ' ');
  41. if (word.length === 0) {
  42. textFilter = null;
  43. } else {
  44. try {
  45. textFilter = new RegExp('(^| )' + word, 'i');
  46. $(this).removeClass('error');
  47. } catch (e) {
  48. if (e instanceof SyntaxError) {
  49. $(this).addClass('error');
  50. textFilter = null;
  51. }
  52. }
  53. }
  54. text = word;
  55. filterVariables();
  56. }).trigger('keyup');
  57. /* Filters the status variables by name/category/alert in the variables tab */
  58. function filterVariables() {
  59. var usefulLinks = 0;
  60. var section = text;
  61. if (categoryFilter.length > 0) {
  62. section = categoryFilter;
  63. }
  64. if (section.length > 1) {
  65. $('#linkSuggestions').find('span').each(function () {
  66. if ($(this).attr('class').indexOf('status_' + section) !== -1) {
  67. usefulLinks++;
  68. $(this).css('display', '');
  69. } else {
  70. $(this).css('display', 'none');
  71. }
  72. });
  73. }
  74. if (usefulLinks > 0) {
  75. $('#linkSuggestions').css('display', '');
  76. } else {
  77. $('#linkSuggestions').css('display', 'none');
  78. }
  79. $('#serverStatusVariables').find('th.name').each(function () {
  80. if ((textFilter === null || textFilter.exec($(this).text())) && (!alertFilter || $(this).next().find('span.attention').length > 0) && (categoryFilter.length === 0 || $(this).parent().hasClass('s_' + categoryFilter))) {
  81. $(this).parent().css('display', '');
  82. } else {
  83. $(this).parent().css('display', 'none');
  84. }
  85. });
  86. }
  87. });