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.

193 lines
5.6 KiB

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