wip
This commit is contained in:
parent
6db5e4b23a
commit
5f6fe641ce
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue