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.

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