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.

189 lines
5.6 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 icon-" + 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. }
  114. );
  115. return false;
  116. });
  117. var lastFormat = "local";
  118. function switchDateFormat(format) {
  119. lastFormat = format;
  120. $("#log tr").each(function(index, row) {
  121. var dt = moment(row.getAttribute("data-dt"));
  122. format == "local" ? dt.local() : dt.tz(format);
  123. $(".date", row).text(dt.format("MMM D"));
  124. $(".time", row).text(dt.format("HH:mm"));
  125. })
  126. // The table is initially hidden to avoid flickering as we convert dates.
  127. // Once it's ready, set it to visible:
  128. $("#log").css("visibility", "visible");
  129. }
  130. $("#format-switcher").click(function(ev) {
  131. var format = ev.target.getAttribute("data-format");
  132. switchDateFormat(format);
  133. });
  134. var transferFormLoadStarted = false;
  135. $("#transfer-btn").on("mouseenter click", function() {
  136. if (transferFormLoadStarted)
  137. return;
  138. transferFormLoadStarted = true;
  139. $.get(this.dataset.url, function(data) {
  140. $("#transfer-modal" ).html(data);
  141. $("#target-project").selectpicker();
  142. });
  143. });
  144. // Enable the submit button in transfer form when user selects
  145. // the target project:
  146. $("#transfer-modal").on("change", "#target-project", function() {
  147. $("#transfer-confirm").prop("disabled", !this.value);
  148. });
  149. // Enable/disable fields in the "Filtering Rules" modal
  150. $("input[type=radio][name=filter_by_subject]").on("change", function() {
  151. var enableInputs = this.value == "yes";
  152. $(".filter-by-subject").prop("disabled", !enableInputs);
  153. });
  154. });