92
92
</ div >
93
93
</ form >
94
94
</ main >
95
+
95
96
< style >
96
97
# form-container {
97
98
max-width : 600px ;
103
104
}
104
105
</ style >
105
106
106
- < script >
107
- const setLoading = ( is_display ) => {
108
- if ( is_display ) {
109
- document . getElementById ( "commit" ) . classList . add ( "loading" ) ;
110
- } else {
111
- document . getElementById ( "commit" ) . classList . remove ( "loading" ) ;
112
- }
113
- } ;
114
-
115
- const setMsgbox = ( message , is_success ) => {
116
- if ( message ) {
117
- document . getElementById ( "msgbox" ) . style . display = "block" ;
118
- document . getElementById ( "status" ) . innerHTML = message ;
119
- document . getElementById ( 'msgbox' ) . classList . remove ( is_success ? "toast-error" : "toast-success" ) ;
120
- document . getElementById ( 'msgbox' ) . classList . add ( is_success ? "toast-success" : "toast-error" ) ;
121
- } else {
122
- document . getElementById ( "msgbox" ) . style . display = "none" ;
123
- document . getElementById ( "status" ) . innerHTML = "" ;
124
- }
125
- } ;
126
-
127
- const setSpec = ( cpu , ram , storage ) => {
128
- document . getElementById ( "cpu_cores" ) . value = cpu ;
129
- document . getElementById ( "ram_mb" ) . value = ram ;
130
- document . getElementById ( "storage_gb" ) . value = storage ;
131
- } ;
132
-
133
- const createMachine = ( ) => {
134
- setLoading ( true ) ;
135
-
136
- const url = '/v1/machine' ;
137
- const params = [ "name" , "cpu_cores" , "ram_mb" , "storage_gb" , "esxi_nodename" , "comment" ] ;
138
- const payloads = { } ;
139
- params . forEach ( param => {
140
- payloads [ param ] = document . getElementById ( param ) . value ;
141
- } ) ;
142
- // console.log(payloads);
143
-
144
- fetch ( url , {
145
- method : 'POST' ,
146
- body : JSON . stringify ( payloads ) , // data can be `string` or {object}!
147
- headers : {
148
- 'Content-Type' : 'application/json'
149
- }
150
- } ) . then ( res => res . json ( ) )
151
- . then ( response => {
152
- console . log ( 'Success:' , JSON . stringify ( response ) ) ;
153
- setMsgbox ( 'Success: ' + response [ 'message' ] , true ) ;
154
- setLoading ( false ) ;
155
- } )
156
- . catch ( error => {
157
- console . error ( 'Error:' , error )
158
- setMsgbox ( "Fail: " + error , false ) ;
159
- setLoading ( false ) ;
160
- } ) ;
161
- } ;
162
-
163
- const commitButton = document . getElementById ( 'commit' ) ;
164
- commitButton . addEventListener ( "click" , createMachine , false ) ;
165
-
166
- const closeButton = document . getElementById ( 'close' ) ;
167
- closeButton . addEventListener ( "click" , ( ) => {
168
- setMsgbox ( false ) ;
169
- } , false ) ;
170
-
171
- document . getElementById ( 'microButton' ) . addEventListener ( "click" , ( ) => {
172
- setSpec ( 1 , 512 , 30 ) ;
173
- } , false ) ;
174
-
175
- document . getElementById ( 'smallButton' ) . addEventListener ( "click" , ( ) => {
176
- setSpec ( 1 , 1024 , 30 ) ;
177
- } , false ) ;
178
-
179
- document . getElementById ( 'mediumButton' ) . addEventListener ( "click" , ( ) => {
180
- setSpec ( 2 , 2048 , 50 ) ;
181
- } , false ) ;
182
-
183
- document . getElementById ( 'largeButton' ) . addEventListener ( "click" , ( ) => {
184
- setSpec ( 4 , 4096 , 70 ) ;
185
- } , false ) ;
186
- </ script >
107
+ < script src ="/static/create.js "> </ script >
187
108
188
- {% include "_footer.html" %}
109
+ {% include "_footer.html" %}
0 commit comments