From 5f6fe641cee83158d1aad4b5531ee46b8c47ac6f Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Mon, 25 Sep 2023 16:06:56 -0500 Subject: [PATCH] wip --- static/script.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/static/script.js b/static/script.js index cdbc9eb..559ab3d 100644 --- a/static/script.js +++ b/static/script.js @@ -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; } }