Skip to content

Commit

Permalink
Replace Prototype.js with native JavaScript (#185)
Browse files Browse the repository at this point in the history
Merging PR.
  • Loading branch information
basil authored May 11, 2023
1 parent 64bc340 commit ac09cb6
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function selectAllInvalid(anchor){
}

function _selectAllThat(anchor, selector){
var parent = anchor.up('.legacy-copy-artifact');
var parent = anchor.closest('.legacy-copy-artifact');
var allCheckBoxes = parent.querySelectorAll('.checkbox-line');
var concernedCheckBoxes = parent.querySelectorAll(selector);

Expand Down Expand Up @@ -76,7 +76,7 @@ function confirmAndMigrateAllSelected(button){
}

function confirmAndSendRequest(button){
var parent = button.up('.legacy-copy-artifact');
var parent = button.closest('.legacy-copy-artifact');
var allCheckBoxes = parent.querySelectorAll('.checkbox-line');
var allCheckedCheckBoxes = [];
for(var i = 0; i < allCheckBoxes.length ; i++){
Expand Down Expand Up @@ -104,13 +104,15 @@ function confirmAndSendRequest(button){
}

var params = {values: selectedValues}
new Ajax.Request(url, {
postBody: Object.toJSON(params),
contentType:"application/json",
encoding:"UTF-8",
onComplete: function(rsp) {
window.location.reload();
}
fetch(url, {
method: 'post',
headers: crumb.wrap({
'Content-Type': 'application/json; charset=UTF-8',
}),
// TODO simplify when Prototype.js is removed
body: Object.toJSON ? Object.toJSON(params) : JSON.stringify(params),
}).then((rsp) => {
window.location.reload();
});
}
}
Expand All @@ -128,11 +130,11 @@ function onLineClicked(event){
}

function onCheckChanged(checkBox){
var line = checkBox.up('tr');
var line = checkBox.closest('tr');
if(checkBox.checked){
line.addClassName('selected');
line.classList.add('selected');
}else{
line.removeClassName('selected');
line.classList.remove('selected');
}
}

Expand All @@ -141,7 +143,7 @@ function onCheckChanged(checkBox){
var allLines = document.querySelectorAll('.legacy-copy-artifact table tr');
for(var i = 0; i < allLines.length; i++){
var line = allLines[i];
if(!line.hasClassName('no-project-line')){
if(!line.classList.contains('no-project-line')){
line.onclick = onLineClicked;
}
}
Expand All @@ -162,15 +164,15 @@ function onCheckChanged(checkBox){

if (body.style.display != 'block') {
body.style.display = 'block';
new Ajax.Request(this.getAttribute('data-help-url'), {
method : 'get',
onSuccess : function(x) {
body.innerHTML = x.responseText;
},
onFailure : function(x) {
fetch(this.getAttribute('data-help-url')).then((rsp) => {
if (rsp.ok) {
rsp.text().then((responseText) => {
body.innerHTML = responseText;
});
} else {
body.innerHTML = (
'<b>ERROR</b>: Failed to load help file: '
+ x.statusText
+ rsp.statusText
);
}
});
Expand Down

0 comments on commit ac09cb6

Please sign in to comment.