Skip to content

Commit

Permalink
Replace Prototype.js with native JavaScript (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored May 31, 2023
1 parent 5db85ab commit 7922945
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
56 changes: 37 additions & 19 deletions ui/src/main/js/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ exports.execAsyncGET = function (resPathTokens, success, params) {
};

exports.jenkinsAjaxGET = function (path, success) {
new Ajax.Request(path, {
method : 'get',
cache: false, // Force caching off for IE (and anything else)
onSuccess: success
fetch(path, {
cache: 'no-cache', // Force caching off for IE (and anything else)
}).then((rsp) => {
if (rsp.ok) {
success();
}
});
};

Expand All @@ -52,30 +54,46 @@ exports.jenkinsAjaxPOST = function () {
var data = arguments[1];
var success = arguments[2];
if (typeof data !== 'string') {
data = Object.toJSON(data);
// TODO simplify when Prototype.js is removed
data = Object.toJSON ? Object.toJSON(data) : JSON.stringify(data);
}
new Ajax.Request(path, {
contentType: "application/json",
encoding: "UTF-8",
postBody: data,
onSuccess: success
fetch(path, {
method: 'post',
headers: crumb.wrap({
'Content-Type': 'application/json; charset=UTF-8'
}),
body: data,
}).then((rsp) => {
if (rsp.ok) {
success();
}
});
} else {
var success = arguments[1];
new Ajax.Request(path, {
contentType: "application/json",
method : 'post',
onSuccess: success
fetch(path, {
method: 'post',
headers: crumb.wrap({
'Content-Type': 'application/json'
}),
}).then((rsp) => {
if (rsp.ok) {
success();
}
});
}
};


exports.jenkinsAjaxPOSTURLEncoded = function (path, parameters, success) {
new Ajax.Request(path, {
method : 'post',
contentType: "application/x-www-form-urlencoded",
parameters: parameters,
onSuccess: success
fetch(path, {
method: 'post',
headers: crumb.wrap({
'Content-Type': 'application/x-www-form-urlencoded'
}),
body: new URLSearchParams(parameters),
}).then((rsp) => {
if (rsp.ok) {
success();
}
});
}
5 changes: 2 additions & 3 deletions ui/src/main/js/view/run-input-required.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ exports.render = function (inputRequiredModel, onElement) {

// Perform the POST. Needs to be encoded into a "json" parameter with an
// array object named "parameter" :)
// TODO simplify when Prototype.js is removed
var parameters = {
json: Object.toJSON({
parameter: inputNVPs
})
json: Object.toJSON ? Object.toJSON({ parameter: inputNVPs }) : JSON.stringify({ parameter: inputNVPs })
};
ajax.jenkinsAjaxPOSTURLEncoded(proceedUrl, parameters, function() {
popover.hide();
Expand Down

0 comments on commit 7922945

Please sign in to comment.