10
10
Local Operators
11
11
</ title >
12
12
< link rel ="stylesheet " type ="text/css " href ="../../../../../root/webapp/main.css "/>
13
+ < script >
14
+ function prepareExport ( ) {
15
+ if ( exportButton . getAttribute ( "href" ) . length === 1 ) {
16
+ const ops = [ ] ;
17
+ for ( const r of data ) {
18
+ ops . push ( {
19
+ "username" :r [ 0 ] ,
20
+ "display_name" :r [ 1 ] ,
21
+ "password" :r [ 2 ] ,
22
+ "session_timeout" :Number ( r [ 3 ] ) ,
23
+ "auto_collapse" :Boolean ( r [ 4 ] )
24
+ } ) ;
25
+ }
26
+ exportButton . setAttribute ( "href" , "data:text/plain;charset=utf-8," + encodeURIComponent ( JSON . stringify ( ops , undefined , 2 ) ) ) ;
27
+ }
28
+ }
29
+ function uploadOperators ( ) {
30
+ if ( ! submittingFile && fileField . value . length > 0 ) {
31
+ if ( fileField . files [ 0 ] . size > 1048576 ) {
32
+ fileField . value = null ;
33
+ alert ( "Selected file size has exceeded the 1MB limit." ) ;
34
+ return ;
35
+ }
36
+ submittingFile = true ;
37
+ const formData = new FormData ( ) ;
38
+ formData . append ( "file" , fileField . files [ 0 ] ) ;
39
+ fileField . value = null ;
40
+ const req = new XMLHttpRequest ( ) ;
41
+ req . open ( "POST" , "__PREFIX__/LocalOperators?cmd=import" ) ;
42
+ req . onreadystatechange = function ( ) {
43
+ if ( this . readyState === 4 ) {
44
+ if ( this . status === 200 ) {
45
+ location . reload ( ) ;
46
+ } else if ( this . status == 0 ) {
47
+ alert ( "Request timed out." ) ;
48
+ } else {
49
+ alert ( "An error has occurred: " + this . status ) ;
50
+ }
51
+ submittingFile = false ;
52
+ }
53
+ } ;
54
+ req . send ( formData ) ;
55
+ }
56
+ }
57
+ </ script >
13
58
</ head >
14
59
< body >
15
60
< div style ="text-align:center ">
16
61
< h1 id ="mainTitle "> Local Operators</ h1 >
17
62
< br >
18
- < table >
19
- < thead > < tr >
20
- < th > Username</ th >
21
- < th > Display Name</ th >
22
- < th > Password</ th >
23
- < th > Session Timeout (seconds)</ th >
24
- < th > Auto-Collapse Trees</ th >
25
- </ tr > </ thead >
26
- < tbody id ="tableBody "> </ tbody >
27
- </ table >
63
+ < table >
64
+ < thead > < tr >
65
+ < th > Username</ th >
66
+ < th > Display Name</ th >
67
+ < th > Password</ th >
68
+ < th > Session Timeout (seconds)</ th >
69
+ < th > Auto-Collapse Trees</ th >
70
+ </ tr > </ thead >
71
+ < tbody id ="tableBody "> </ tbody >
72
+ </ table >
73
+ < br >
74
+ < a class ="e " id ="exportButton " href ="# " download ="operators.json " onclick ="prepareExport() "> Export</ a >
75
+ < button id ="importButton " class ="e " onclick ="fileField.click() "> Import</ button >
76
+ < input type ="file " id ="fileField " accept =".json " style ="display:none " oninput ="uploadOperators(); ">
28
77
< br > < br >
29
78
< a class ="e nav " href ="__PREFIX__/TableEditor?table=servers "> Server List</ a >
30
79
< a class ="e nav " href ="__PREFIX__/TableEditor?table=operator_whitelist "> Operator Whitelist</ a >
@@ -41,6 +90,7 @@ <h1 id="mainTitle">Local Operators</h1>
41
90
< a class ="e nav " href ="__DOCUMENTATION__ " target ="_blank "> Documentation</ a >
42
91
</ div >
43
92
< script >
93
+ var submittingFile = false ;
44
94
const data = __OPERATORS__ ;
45
95
const body = document . getElementById ( "tableBody" ) ;
46
96
for ( const r of data ) {
0 commit comments