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.

148 lines
4.3 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 (document.title != data.title) {
  59. document.title = data.title;
  60. }
  61. }
  62. });
  63. }, true);
  64. // Copy to clipboard
  65. var clipboard = new Clipboard('button.copy-btn');
  66. $("button.copy-btn").mouseout(function(e) {
  67. setTimeout(function() {
  68. e.target.textContent = e.target.dataset.label;
  69. }, 300);
  70. });
  71. clipboard.on('success', function(e) {
  72. e.trigger.textContent = "Copied!";
  73. e.clearSelection();
  74. });
  75. clipboard.on('error', function(e) {
  76. var text = e.trigger.getAttribute("data-clipboard-text");
  77. prompt("Press Ctrl+C to select:", text)
  78. });
  79. $("#events").on("click", "tr.ok", function() {
  80. $("#ping-details-body").text("Updating...");
  81. $('#ping-details-modal').modal("show");
  82. $.get(this.dataset.url, function(data) {
  83. $("#ping-details-body").html(data);
  84. }
  85. );
  86. return false;
  87. });
  88. var lastFormat = "local";
  89. function switchDateFormat(format) {
  90. lastFormat = format;
  91. $("#log tr").each(function(index, row) {
  92. var dt = moment(row.getAttribute("data-dt"));
  93. format == "local" ? dt.local() : dt.utc();
  94. $(".date", row).text(dt.format("MMM D"));
  95. $(".time", row).text(dt.format("HH:mm"));
  96. })
  97. // The table is initially hidden to avoid flickering as we convert dates.
  98. // Once it's ready, set it to visible:
  99. $("#log").css("visibility", "visible");
  100. }
  101. $("#format-switcher").click(function(ev) {
  102. var format = ev.target.getAttribute("data-format");
  103. switchDateFormat(format);
  104. });
  105. var transferFormLoadStarted = false;
  106. $("#transfer-btn").on("mouseenter click", function() {
  107. if (transferFormLoadStarted)
  108. return;
  109. transferFormLoadStarted = true;
  110. $.get(this.dataset.url, function(data) {
  111. $("#transfer-modal" ).html(data);
  112. $("#target-project").selectpicker();
  113. });
  114. });
  115. // Enable the submit button in transfer form when user selects
  116. // the target project:
  117. $("#transfer-modal").on("change", "#target-project", function() {
  118. $("#transfer-confirm").prop("disabled", !this.value);
  119. });
  120. });