This commit is contained in:
Rudis Muiznieks 2023-09-25 16:06:56 -05:00
parent 6db5e4b23a
commit 5f6fe641ce
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
1 changed files with 25 additions and 3 deletions

View File

@ -12,7 +12,7 @@ function configureSummarizeButtons() {
e.preventDefault();
e.stopPropagation();
if (target.href) {
summarizeButtonClick(target.href, target);
summarizeButtonClick(button);
}
break;
}
@ -20,21 +20,43 @@ function configureSummarizeButtons() {
}, false);
}
function summarizeButtonClick(url, button) {
function summarizeButtonClick(button) {
var url = button.href;
var loadingMsg = button.dataset.loading;
var errorMsg = button.dataset.error;
var container = button.parentNode;
container.classList.add('alert');
container.classList.add('alert-warning');
container.innerHTML = loadingMsg;
var request = new XMLHttpRequest();
request.open('POST', url, true);
request.responseType = 'json';
request.onload = function(e) {
if (this.status != 200) {
return request.onerror(e);
}
var response = xmlHttpRequestJson(this);
if (!response) {
return request.onerror(e);
}
if (response.status !== 200) {
return request.onerror(e);
}
container.classList.remove('alert-warning');
container.classList.add('alert-success');
container.innerHTML = 'placeholder';
}
request.onerror = function(e) {
badAjax(this.status == 403);
container.classList.add('alert');
container.classList.remove('alert-warning');
container.classList.add('alert-error');
containter.innerHTML = errorMsg;
}
}