From: Scott Worley Date: Sat, 19 Nov 2022 09:29:43 +0000 (-0800) Subject: Send votes X-Git-Tag: v0.2.0~7 X-Git-Url: http://git.scottworley.com/voter/commitdiff_plain/f724d95fdf704f2480581d7de85f0198a5c049e8?hp=9543206967816cd9427588a2c29468fff133a65e Send votes --- diff --git a/src/main.rs b/src/main.rs index 5c4ad90..920384e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,6 +97,18 @@ const HTML_HEADER: &str = " const spin = document.createElement('div') spin.appendChild(document.createTextNode('⏳')) cb.parentElement.insertBefore(spin, cb) + + const req = new XMLHttpRequest() + req.addEventListener('load', function(e) { + cb.parentElement.removeChild(cb.previousElementSibling) + if (req.status == 200) { + cb.style.display = '' + } else { + cb.parentElement.insertBefore(document.createTextNode('❗'), cb) + } + }) + req.open('PUT', window.location.href) + req.send((cb.checked ? 1 : 0) + ' ' + cb.parentElement.nextSibling.innerHTML) } })(cb)) cb.disabled = false