You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.9 KiB

10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
  1. $(function () {
  2. var secsToText = function(total) {
  3. total = Math.floor(total / 60);
  4. var m = total % 60; total = Math.floor(total / 60);
  5. var h = total % 24; total = Math.floor(total / 24);
  6. var d = total % 7; total = Math.floor(total / 7);
  7. var w = total;
  8. var result = "";
  9. if (w) result += w + (w === 1 ? " week " : " weeks ");
  10. if (d) result += d + (d === 1 ? " day " : " days ");
  11. if (h) result += h + (h === 1 ? " hour " : " hours ");
  12. if (m) result += m + (m === 1 ? " minute " : " minutes ");
  13. return result;
  14. }
  15. var periodSlider = document.getElementById("period-slider");
  16. noUiSlider.create(periodSlider, {
  17. start: [20],
  18. connect: "lower",
  19. range: {
  20. 'min': [60, 60],
  21. '30%': [3600, 3600],
  22. '82.80%': [86400, 86400],
  23. 'max': 604800
  24. },
  25. pips: {
  26. mode: 'values',
  27. values: [60, 1800, 3600, 43200, 86400, 604800],
  28. density: 5,
  29. format: {
  30. to: secsToText,
  31. from: function() {}
  32. }
  33. }
  34. });
  35. periodSlider.noUiSlider.on("update", function(a, b, value) {
  36. var rounded = Math.round(value);
  37. $("#period-slider-value").text(secsToText(rounded));
  38. $("#update-timeout-timeout").val(rounded);
  39. });
  40. var graceSlider = document.getElementById("grace-slider");
  41. noUiSlider.create(graceSlider, {
  42. start: [20],
  43. connect: "lower",
  44. range: {
  45. 'min': [60, 60],
  46. '30%': [3600, 3600],
  47. '82.80%': [86400, 86400],
  48. 'max': 604800
  49. },
  50. pips: {
  51. mode: 'values',
  52. values: [60, 1800, 3600, 43200, 86400, 604800],
  53. density: 5,
  54. format: {
  55. to: secsToText,
  56. from: function() {}
  57. }
  58. }
  59. });
  60. graceSlider.noUiSlider.on("update", function(a, b, value) {
  61. var rounded = Math.round(value);
  62. $("#grace-slider-value").text(secsToText(rounded));
  63. $("#update-timeout-grace").val(rounded);
  64. });
  65. $('[data-toggle="tooltip"]').tooltip();
  66. $(".my-checks-name").click(function() {
  67. var $this = $(this);
  68. $("#update-name-form").attr("action", $this.data("url"));
  69. $("#update-name-input").val($this.data("name"));
  70. $("#update-tags-input").val($this.data("tags"));
  71. $('#update-name-modal').modal("show");
  72. $("#update-name-input").focus();
  73. return false;
  74. });
  75. $(".timeout-grace").click(function() {
  76. var $this = $(this);
  77. $("#update-timeout-form").attr("action", $this.data("url"));
  78. periodSlider.noUiSlider.set($this.data("timeout"))
  79. graceSlider.noUiSlider.set($this.data("grace"))
  80. $('#update-timeout-modal').modal({"show":true, "backdrop":"static"});
  81. return false;
  82. });
  83. $(".check-menu-remove").click(function() {
  84. var $this = $(this);
  85. $("#remove-check-form").attr("action", $this.data("url"));
  86. $(".remove-check-name").text($this.data("name"));
  87. $('#remove-check-modal').modal("show");
  88. return false;
  89. });
  90. $("#show-urls").click(function() {
  91. $("#show-urls").addClass("active");
  92. $(".my-checks-url").removeClass("off");
  93. $("#show-emails").removeClass("active");
  94. $(".my-checks-email").addClass("off");
  95. });
  96. $("#show-emails").click(function() {
  97. $("#show-urls").removeClass("active");
  98. $(".my-checks-url").addClass("off");
  99. $("#show-emails").addClass("active");
  100. $(".my-checks-email").removeClass("off");
  101. });
  102. $(".selectable").click(function() {
  103. $(this).tooltip("hide");
  104. this.select();
  105. });
  106. $("#my-checks-tags button").click(function() {
  107. // .active has not been updated yet by bootstrap code,
  108. // so cannot use it
  109. $(this).toggleClass('checked');
  110. // Make a list of currently checked tags:
  111. var checked = [];
  112. $("#my-checks-tags button.checked").each(function(index, el) {
  113. checked.push(el.textContent);
  114. });
  115. // No checked tags: show all
  116. if (checked.length == 0) {
  117. $("#checks-table tr.checks-row").show();
  118. $("#checks-list > li").show();
  119. return;
  120. }
  121. function applyFilters(index, element) {
  122. var tags = $(".my-checks-name", element).data("tags").split(" ");
  123. for (var i=0, tag; tag=checked[i]; i++) {
  124. if (tags.indexOf(tag) == -1) {
  125. $(element).hide();
  126. return;
  127. }
  128. }
  129. $(element).show();
  130. }
  131. // Desktop: for each row, see if it needs to be shown or hidden
  132. $("#checks-table tr.checks-row").each(applyFilters);
  133. // Mobile: for each list item, see if it needs to be shown or hidden
  134. $("#checks-list > li").each(applyFilters);
  135. });
  136. });