File tree 3 files changed +48
-3
lines changed
3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ <h1 id="title" class="navbar-brand">Galène</h1>
20
20
< input id ="group " type ="text " name ="group " class ="form-control form-control-inline "/>
21
21
< input type ="submit " value ="Join " class ="btn btn-default btn-large "/> < br />
22
22
</ form >
23
+
24
+ < p id ="errormessage "> </ p >
23
25
24
26
< div id ="public-groups " class ="groups ">
25
27
< h2 > Public groups</ h2 >
Original file line number Diff line number Diff line change 4
4
flex-direction : column;
5
5
}
6
6
7
+ # errormessage {
8
+ color : red;
9
+ font-weight : bold;
10
+ height : 12px ;
11
+ }
12
+
7
13
.groups {
8
14
}
9
15
Original file line number Diff line number Diff line change 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
+ clearError ( ) ;
25
26
let group = document . getElementById ( 'group' ) . value . trim ( ) ;
26
- if ( group !== '' )
27
- location . href = '/group/' + group + '/' ;
27
+ if ( group === '' )
28
+ return ;
29
+ let url = '/group/' + group + '/' ;
30
+ try {
31
+ let resp = await fetch ( url , {
32
+ method : 'HEAD' ,
33
+ } ) ;
34
+ if ( ! resp . ok ) {
35
+ if ( resp . status === 404 )
36
+ displayError ( 'No such group' ) ;
37
+ else
38
+ displayError ( `The server said: ${ resp . status } ${ resp . statusText } ` ) ;
39
+ return ;
40
+ }
41
+ } catch ( e ) {
42
+ displayError ( `Coudln't connect: ${ e . toString ( ) } ` ) ;
43
+ }
44
+ location . href = url ;
28
45
} ;
29
46
47
+ var clearErrorTimeout = null ;
48
+
49
+ function displayError ( message ) {
50
+ clearError ( ) ;
51
+ let p = document . getElementById ( 'errormessage' ) ;
52
+ p . textContent = message ;
53
+ clearErrorTimeout = setTimeout ( ( ) => {
54
+ let p = document . getElementById ( 'errormessage' ) ;
55
+ p . textContent = '' ;
56
+ clearErrorTimeout = null ;
57
+ } , 2500 ) ;
58
+ }
59
+
60
+ function clearError ( ) {
61
+ if ( clearErrorTimeout != null ) {
62
+ clearTimeout ( clearErrorTimeout ) ;
63
+ clearErrorTimeout = null ;
64
+ }
65
+ }
66
+
30
67
async function listPublicGroups ( ) {
31
68
let div = document . getElementById ( 'public-groups' ) ;
32
69
let table = document . getElementById ( 'public-groups-table' ) ;
You can’t perform that action at this time.
0 commit comments