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.

152 lines
4.4 KiB

  1. $(function () {
  2. $("#edit-name").click(function() {
  3. $('#update-name-modal').modal("show");
  4. $("#update-name-input").focus();
  5. return false;
  6. });
  7. $("#edit-desc").click(function() {
  8. $('#update-name-modal').modal("show");
  9. $("#update-desc-input").focus();
  10. return false;
  11. });
  12. $("#pause").click(function(e) {
  13. $("#pause-form").submit();
  14. return false;
  15. });
  16. $("#ping-now").click(function(e) {
  17. var button = this;
  18. $.get(this.dataset.url, function() {
  19. button.textContent = "Success!";
  20. });
  21. });
  22. $("#ping-now").mouseout(function(e) {
  23. setTimeout(function() {
  24. e.target.textContent = "Ping Now!";
  25. }, 300);
  26. });
  27. $("#details-integrations tr").click(function() {
  28. var isOn = $(this).toggleClass("on").hasClass("on");
  29. $(".label", this).text(isOn ? "ON" : "OFF");
  30. var token = $('input[name=csrfmiddlewaretoken]').val();
  31. $.ajax({
  32. url: this.dataset.url,
  33. type: "post",
  34. headers: {"X-CSRFToken": token},
  35. data: {"state": isOn ? "on" : "off"}
  36. });
  37. })
  38. var code = document.getElementById("edit-timeout").dataset.code;
  39. var statusUrl = "/checks/" + code + "/status/";
  40. var lastStatusText = "";
  41. var lastUpdated = "";
  42. adaptiveSetInterval(function() {
  43. $.ajax({
  44. url: statusUrl + (lastUpdated ? "?u=" + lastUpdated : ""),
  45. dataType: "json",
  46. timeout: 2000,
  47. success: function(data) {
  48. if (data.status_text != lastStatusText) {
  49. lastStatusText = data.status_text;
  50. $("#log-status-icon").attr("class", "status icon-" + data.status);
  51. $("#log-status-text").text(data.status_text);
  52. }
  53. if (data.events) {
  54. lastUpdated = data.updated;
  55. $("#log-container").html(data.events);
  56. switchDateFormat(lastFormat);
  57. }
  58. if (data.downtimes) {
  59. $("#downtimes").html(data.downtimes);
  60. }
  61. if (document.title != data.title) {
  62. document.title = data.title;
  63. }
  64. }
  65. });
  66. }, true);
  67. // Copy to clipboard
  68. var clipboard = new Clipboard('button.copy-btn');
  69. $("button.copy-btn").mouseout(function(e) {
  70. setTimeout(function() {
  71. e.target.textContent = e.target.dataset.label;
  72. }, 300);
  73. });
  74. clipboard.on('success', function(e) {
  75. e.trigger.textContent = "Copied!";
  76. e.clearSelection();
  77. });
  78. clipboard.on('error', function(e) {
  79. var text = e.trigger.getAttribute("data-clipboard-text");
  80. prompt("Press Ctrl+C to select:", text)
  81. });
  82. $("#events").on("click", "tr.ok", function() {
  83. $("#ping-details-body").text("Updating...");
  84. $('#ping-details-modal').modal("show");
  85. $.get(this.dataset.url, function(data) {
  86. $("#ping-details-body").html(data);
  87. }
  88. );
  89. return false;
  90. });
  91. var lastFormat = "local";
  92. function switchDateFormat(format) {
  93. lastFormat = format;
  94. $("#log tr").each(function(index, row) {
  95. var dt = moment(row.getAttribute("data-dt"));
  96. format == "local" ? dt.local() : dt.utc();
  97. $(".date", row).text(dt.format("MMM D"));
  98. $(".time", row).text(dt.format("HH:mm"));
  99. })
  100. // The table is initially hidden to avoid flickering as we convert dates.
  101. // Once it's ready, set it to visible:
  102. $("#log").css("visibility", "visible");
  103. }
  104. $("#format-switcher").click(function(ev) {
  105. var format = ev.target.getAttribute("data-format");
  106. switchDateFormat(format);
  107. });
  108. var transferFormLoadStarted = false;
  109. $("#transfer-btn").on("mouseenter click", function() {
  110. if (transferFormLoadStarted)
  111. return;
  112. transferFormLoadStarted = true;
  113. $.get(this.dataset.url, function(data) {
  114. $("#transfer-modal" ).html(data);
  115. $("#target-project").selectpicker();
  116. });
  117. });
  118. // Enable the submit button in transfer form when user selects
  119. // the target project:
  120. $("#transfer-modal").on("change", "#target-project", function() {
  121. $("#transfer-confirm").prop("disabled", !this.value);
  122. });
  123. });