update_status.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. (function($) {
  2. Drupal.behaviors.moduleFilterUpdateStatus = {
  3. attach: function(context) {
  4. $('#module-filter-update-status-form').once('update-status', function() {
  5. var filterInput = $('input[name="module_filter[name]"]', context);
  6. filterInput.moduleFilter('table.update > tbody > tr', {
  7. wrapper: $('table.update:first').parent(),
  8. delay: 300,
  9. childSelector: 'div.project a',
  10. rules: [
  11. function(moduleFilter, item) {
  12. switch (moduleFilter.options.show) {
  13. case 'all':
  14. return true;
  15. case 'updates':
  16. if (item.state == 'warning' || item.state == 'error') {
  17. return true;
  18. }
  19. break;
  20. case 'security':
  21. if (item.state == 'error') {
  22. return true;
  23. }
  24. break;
  25. case 'ignore':
  26. if (item.state == 'ignored') {
  27. return true;
  28. }
  29. break;
  30. case 'unknown':
  31. if (item.state == 'unknown') {
  32. return true;
  33. }
  34. break;
  35. }
  36. return false;
  37. }
  38. ],
  39. buildIndex: [
  40. function(moduleFilter, item) {
  41. if ($('.version-status', item.element).text() == Drupal.t('Ignored from settings')) {
  42. item.state = 'ignored';
  43. return item;
  44. }
  45. if (item.element.is('.ok')) {
  46. item.state = 'ok';
  47. }
  48. else if (item.element.is('.warning')) {
  49. item.state = 'warning';
  50. }
  51. else if (item.element.is('.error')) {
  52. item.state = 'error';
  53. }
  54. else if (item.element.is('.unknown')) {
  55. item.state = 'unknown';
  56. }
  57. return item;
  58. }
  59. ],
  60. show: $('#edit-module-filter-show input[name="module_filter[show]"]', context).val()
  61. });
  62. var moduleFilter = filterInput.data('moduleFilter');
  63. if (Drupal.settings.moduleFilter.rememberUpdateState) {
  64. var updateShow = Drupal.ModuleFilter.getState('updateShow');
  65. if (updateShow) {
  66. moduleFilter.options.show = updateShow;
  67. $('#edit-module-filter-show input[name="module_filter[show]"][value="' + updateShow + '"]', context).click();
  68. }
  69. }
  70. $('#edit-module-filter-show input[name="module_filter[show]"]', context).change(function() {
  71. moduleFilter.options.show = $(this).val();
  72. Drupal.ModuleFilter.setState('updateShow', moduleFilter.options.show);
  73. moduleFilter.applyFilter();
  74. });
  75. moduleFilter.element.bind('moduleFilter:start', function() {
  76. $('.overflow-fix').has('table.update').each(function() {
  77. $(this).show().prev('h3').show();
  78. });
  79. });
  80. moduleFilter.element.bind('moduleFilter:finish', function(e, data) {
  81. $('.overflow-fix').has('table.update').each(function() {
  82. var $table = $(this);
  83. if ($('tbody tr', $(this)).filter(':visible').length == 0) {
  84. $table.hide().prev('h3').hide();
  85. }
  86. });
  87. });
  88. moduleFilter.element.bind('moduleFilter:keyup', function() {
  89. if (moduleFilter.clearOffset == undefined) {
  90. moduleFilter.inputWidth = filterInput.width();
  91. moduleFilter.clearOffset = moduleFilter.element.parent().find('.module-filter-clear a').width();
  92. }
  93. if (moduleFilter.text) {
  94. filterInput.width(moduleFilter.inputWidth - moduleFilter.clearOffset - 5).parent().css('margin-right', moduleFilter.clearOffset + 5);
  95. }
  96. else {
  97. filterInput.width(moduleFilter.inputWidth).parent().css('margin-right', 0);
  98. }
  99. });
  100. moduleFilter.element.parent().find('.module-filter-clear a').click(function() {
  101. filterInput.width(moduleFilter.inputWidth).parent().css('margin-right', 0);
  102. });
  103. moduleFilter.applyFilter();
  104. });
  105. }
  106. };
  107. })(jQuery);