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.

141 lines
4.1 KiB

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