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