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.

173 lines
5.0 KiB

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