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.

156 lines
4.5 KiB

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