munin_api.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file
  3. * Munin API for Drupal: settings UI eye candy
  4. *
  5. * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  6. *
  7. * Licensed under the General Public License version 2 or later.
  8. */
  9. /*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true,
  10. plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true,
  11. indent: 2 */
  12. /*global Drupal,$ */
  13. /**
  14. * Fade a selection in or out, depending on the parameters
  15. *
  16. * @param string selector
  17. * A jQuery selector
  18. * @param boolean visible
  19. * Set to true to fade in, to fase to fade out
  20. * @return void
  21. */
  22. function muninApiFade(selector, visible) {
  23. if (visible) {
  24. $(selector).fadeIn();
  25. }
  26. else {
  27. $(selector).fadeOut();
  28. }
  29. }
  30. /**
  31. * Ready handler to apply visibility to the path field on the settings form.
  32. *
  33. * Hide the manual path selector initially unless the current watchdog mode is
  34. * set to init.
  35. *
  36. * @return void
  37. */
  38. function onReadySettingsVisibility() {
  39. if ($('#edit-munin-api-watchdog-init').attr('checked') === false) {
  40. $('#edit-munin-api-init-path-wrapper').hide();
  41. }
  42. if ($('#edit-munin-api-next-report').attr('checked') === false) {
  43. $('.munin-api-report').hide();
  44. }
  45. $("input:radio[name='munin_api_watchdog']").click(function () {
  46. muninApiFade('#edit-munin-api-init-path-wrapper',
  47. $("input:radio[name='munin_api_watchdog']:checked").val() === 'init');
  48. });
  49. $('#edit-munin-api-next-report').click(function () {
  50. muninApiFade('.munin-api-report',
  51. $("#edit-munin-api-next-report").attr('checked'));
  52. });
  53. }
  54. /**
  55. * Assign ready handler
  56. */
  57. $(function () {
  58. onReadySettingsVisibility();
  59. });