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.

187 lines
5.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. // 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. $("#log-status-text").on("click", "#resume-btn", function() {
  33. $("#resume-form").submit();
  34. return false;
  35. });
  36. $("#pause").click(function(e) {
  37. $("#pause-form").submit();
  38. return false;
  39. });
  40. $("#ping-now").click(function(e) {
  41. var button = this;
  42. $.post(this.dataset.url, function() {
  43. button.textContent = "Success!";
  44. });
  45. });
  46. $("#ping-now").mouseout(function(e) {
  47. setTimeout(function() {
  48. e.target.textContent = "Ping Now!";
  49. }, 300);
  50. });
  51. $("#details-integrations tr").click(function() {
  52. var isOn = $(this).toggleClass("on").hasClass("on");
  53. $(".label", this).text(isOn ? "ON" : "OFF");
  54. var token = $('input[name=csrfmiddlewaretoken]').val();
  55. $.ajax({
  56. url: this.dataset.url,
  57. type: "post",
  58. headers: {"X-CSRFToken": token},
  59. data: {"state": isOn ? "on" : "off"}
  60. });
  61. });
  62. var statusUrl = document.getElementById("edit-timeout").dataset.statusUrl;
  63. var lastStatusText = "";
  64. var lastUpdated = "";
  65. adaptiveSetInterval(function() {
  66. $.ajax({
  67. url: statusUrl + (lastUpdated ? "?u=" + lastUpdated : ""),
  68. dataType: "json",
  69. timeout: 2000,
  70. success: function(data) {
  71. if (data.status_text != lastStatusText) {
  72. lastStatusText = data.status_text;
  73. $("#log-status-icon").attr("class", "status icon-" + data.status);
  74. $("#log-status-text").html(data.status_text);
  75. $('#pause-btn').prop('disabled', data.status == "paused");
  76. }
  77. if (data.events) {
  78. lastUpdated = data.updated;
  79. $("#log-container").html(data.events);
  80. switchDateFormat(lastFormat);
  81. }
  82. if (data.downtimes) {
  83. $("#downtimes").html(data.downtimes);
  84. }
  85. if (document.title != data.title) {
  86. document.title = data.title;
  87. }
  88. }
  89. });
  90. }, true);
  91. // Copy to clipboard
  92. var clipboard = new Clipboard('button.copy-btn');
  93. $("button.copy-btn").mouseout(function(e) {
  94. setTimeout(function() {
  95. e.target.textContent = e.target.dataset.label;
  96. }, 300);
  97. });
  98. clipboard.on('success', function(e) {
  99. e.trigger.textContent = "Copied!";
  100. e.clearSelection();
  101. });
  102. clipboard.on('error', function(e) {
  103. var text = e.trigger.getAttribute("data-clipboard-text");
  104. prompt("Press Ctrl+C to select:", text)
  105. });
  106. $("#events").on("click", "tr.ok", function() {
  107. $("#ping-details-body").text("Updating...");
  108. $('#ping-details-modal').modal("show");
  109. $.get(this.dataset.url, function(data) {
  110. $("#ping-details-body").html(data);
  111. }
  112. );
  113. return false;
  114. });
  115. var lastFormat = "local";
  116. function switchDateFormat(format) {
  117. lastFormat = format;
  118. $("#log tr").each(function(index, row) {
  119. var dt = moment(row.getAttribute("data-dt"));
  120. format == "local" ? dt.local() : dt.tz(format);
  121. $(".date", row).text(dt.format("MMM D"));
  122. $(".time", row).text(dt.format("HH:mm"));
  123. })
  124. // The table is initially hidden to avoid flickering as we convert dates.
  125. // Once it's ready, set it to visible:
  126. $("#log").css("visibility", "visible");
  127. }
  128. $("#format-switcher").click(function(ev) {
  129. var format = ev.target.getAttribute("data-format");
  130. switchDateFormat(format);
  131. });
  132. var transferFormLoadStarted = false;
  133. $("#transfer-btn").on("mouseenter click", function() {
  134. if (transferFormLoadStarted)
  135. return;
  136. transferFormLoadStarted = true;
  137. $.get(this.dataset.url, function(data) {
  138. $("#transfer-modal" ).html(data);
  139. $("#target-project").selectpicker();
  140. });
  141. });
  142. // Enable the submit button in transfer form when user selects
  143. // the target project:
  144. $("#transfer-modal").on("change", "#target-project", function() {
  145. $("#transfer-confirm").prop("disabled", !this.value);
  146. });
  147. // Enable/disable fields in the "Filtering Rules" modal
  148. $("input[type=radio][name=filter_by_subject]").on("change", function() {
  149. var enableInputs = this.value == "yes";
  150. $(".filter-by-subject").prop("disabled", !enableInputs);
  151. });
  152. });