forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
apply.js
61 lines (53 loc) · 1.89 KB
/
apply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Behaviour.specify(
"INPUT.apply-button,BUTTON.apply-button",
"apply",
0,
function (e) {
e.addEventListener("click", function (e) {
const f = e.target.closest("FORM");
// create a throw-away IFRAME to avoid back button from loading the POST result back
const id = "iframe" + iota++;
const target = document.createElement("iframe");
target.setAttribute("id", id);
target.setAttribute("name", id);
target.style.height = "100%";
target.style.width = "100%";
document.querySelector("body").appendChild(target);
f.target = target.id;
f.elements["core:apply"].value = "true";
f.dispatchEvent(new Event("jenkins:apply")); // give everyone a chance to write back to DOM
try {
buildFormTree(f);
f.submit();
} finally {
f.elements["core:apply"].value = null;
f.target = "_self";
}
target.addEventListener("load", () => {
if (
target.contentWindow &&
target.contentWindow.applyCompletionHandler
) {
// apply-aware server is expected to set this handler
target.contentWindow.applyCompletionHandler(window);
// Remove the iframe from the DOM
target.remove();
return;
}
// otherwise this is possibly an error from the server, so we need to render the whole content.
const doc = target.contentDocument || target.contentWindow.document;
let error = doc.getElementById("error-description");
if (!error) {
// Fallback if it's not a regular error dialog from oops.jelly: use the entire body
error = document.createElement("div");
error.appendChild(doc.querySelector("#page-body"));
}
dialog.modal(error, {
minWidth: "850px",
});
// Remove the iframe from the DOM
target.remove();
});
});
},
);