|
20 | 20 |
|
21 | 21 | 'use strict'; |
22 | 22 |
|
23 | | -document.getElementById('groupform').onsubmit = function(e) { |
| 23 | +document.getElementById('groupform').onsubmit = async function(e) { |
24 | 24 | e.preventDefault(); |
25 | | - let group = document.getElementById('group').value.trim(); |
26 | | - if(group !== '') |
27 | | - location.href = '/group/' + group + '/'; |
| 25 | + clearError(); |
| 26 | + let groupinput = document.getElementById('group') |
| 27 | + let button = document.getElementById('submitbutton'); |
| 28 | + |
| 29 | + let group = groupinput.value.trim(); |
| 30 | + if(group === '') |
| 31 | + return; |
| 32 | + let url = '/group/' + group + '/'; |
| 33 | + |
| 34 | + try { |
| 35 | + groupinput.disabled = true; |
| 36 | + button.disabled = true; |
| 37 | + try { |
| 38 | + let resp = await fetch(url, { |
| 39 | + method: 'HEAD', |
| 40 | + }); |
| 41 | + if(!resp.ok) { |
| 42 | + if(resp.status === 404) |
| 43 | + displayError('No such group'); |
| 44 | + else |
| 45 | + displayError(`The server said: ${resp.status} ${resp.statusText}`); |
| 46 | + return; |
| 47 | + } |
| 48 | + } catch(e) { |
| 49 | + displayError(`Coudln't connect: ${e.toString()}`); |
| 50 | + return; |
| 51 | + } |
| 52 | + } finally { |
| 53 | + groupinput.disabled = false; |
| 54 | + button.disabled = false; |
| 55 | + } |
| 56 | + |
| 57 | + location.href = url; |
28 | 58 | }; |
29 | 59 |
|
| 60 | +var clearErrorTimeout = null; |
| 61 | + |
| 62 | +function displayError(message) { |
| 63 | + clearError(); |
| 64 | + let p = document.getElementById('errormessage'); |
| 65 | + p.textContent = message; |
| 66 | + clearErrorTimeout = setTimeout(() => { |
| 67 | + let p = document.getElementById('errormessage'); |
| 68 | + p.textContent = ''; |
| 69 | + clearErrorTimeout = null; |
| 70 | + }, 2500); |
| 71 | +} |
| 72 | + |
| 73 | +function clearError() { |
| 74 | + if(clearErrorTimeout != null) { |
| 75 | + clearTimeout(clearErrorTimeout); |
| 76 | + clearErrorTimeout = null; |
| 77 | + } |
| 78 | +} |
| 79 | + |
30 | 80 | async function listPublicGroups() { |
31 | 81 | let div = document.getElementById('public-groups'); |
32 | 82 | let table = document.getElementById('public-groups-table'); |
|
0 commit comments