@@ -6,41 +6,38 @@ const API_MATCHES = ["/api/v1/events/matches/", /* season */ "/", /* event */ "/
66const API_WHOAMI = "/api/v1/whoami" ;
77const API_SUBMIT = "/api/v1/data/submit" ;
88var match_schedule ;
9+ function getEventCookie ( ) {
10+ var cookieString = RegExp ( "92bdcf1af0a0a23d" + "=[^;]+" ) . exec ( document . cookie ) ;
11+ return decodeURIComponent ( ! ! cookieString ? cookieString . toString ( ) . replace ( / ^ [ ^ = ] + ./ , "" ) : "" ) ;
12+ }
913async function init ( ) {
14+ if ( getEventCookie ( ) == "" ) {
15+ document . cookie = `92bdcf1af0a0a23d=CAFR; expires=Fri, 31 Dec 9999 23:59:59 GMT; Secure; SameSite=Lax` ;
16+ }
17+ document . getElementById ( "selected_event_code" ) . innerText = getEventCookie ( ) ;
1018 _get ( API_WHOAMI , null ) . then ( ( result ) => {
1119 console . info ( result ) ;
1220 } ) . catch ( ( error ) => {
1321 console . error ( error ) ;
1422 window . location . href = "/login" ;
1523 } ) ;
16- await load_data ( ) ;
17- document . getElementById ( "event_code" ) . addEventListener ( "change" , ( ) => {
18- load_matches ( document . getElementById ( "event_code" ) . value ) ;
19- } ) ;
24+ await load_matches ( getEventCookie ( ) ) ;
2025 document . getElementById ( "match_num_input" ) . addEventListener ( "change" , ( ) => {
2126 match_num_entry ( document . getElementById ( "match_num_input" ) . value ) ;
2227 } ) ;
2328}
24- async function load_data ( ) {
25- _get ( API_META , null ) . then ( ( result ) => {
26- result . events . forEach ( event_code => {
27- document . getElementById ( "event_code" ) . insertAdjacentHTML ( "beforeend" , `<option value="${ event_code } ">${ event_code } </option>` ) ;
28- } ) ;
29- document . getElementById ( "event_code" ) . value = "CAFR" ;
30- load_matches ( "CAFR" ) ;
31- } ) . catch ( ( error ) => {
32- alert ( `failed to load valid event codes. ${ error } ` ) ;
33- } ) ;
34- }
3529function load_matches ( event = "CAFR" ) {
36- _get ( API_MATCHES [ 0 ] + "2023" + API_MATCHES [ 1 ] + event + API_MATCHES [ 2 ] , null ) . then ( ( result ) => {
30+ document . getElementsByClassName ( "continue_button" ) [ 0 ] . disabled = true ;
31+ _get ( API_MATCHES [ 0 ] + "2024" + API_MATCHES [ 1 ] + event + API_MATCHES [ 2 ] , null ) . then ( ( result ) => {
3732 if ( result . Schedule . length != 0 ) {
3833 match_schedule = result . Schedule ;
3934 document . getElementById ( "match_num_input" ) . innerHTML = "" ;
4035 result . Schedule . forEach ( match => {
4136 document . getElementById ( "match_num_input" ) . insertAdjacentHTML ( "beforeend" , `<option value="${ match . matchNumber } ">${ match . matchNumber } </option>` ) ;
4237 } ) ;
4338 match_num_entry ( "1" ) ;
39+ document . getElementById ( "match_num_input" ) . value = "" ;
40+ document . getElementById ( "team_number" ) . value = "" ;
4441 }
4542 else {
4643 alert ( "match schedule is not yet posted" ) ;
@@ -55,6 +52,14 @@ function set_option(element, value) {
5552 element . innerText = value ;
5653 element . value = value ;
5754}
55+ document . getElementById ( "team_number" ) . onchange = ( ) => {
56+ if ( document . getElementById ( "team_number" ) . value == "" ) {
57+ document . getElementsByClassName ( "continue_button" ) [ 0 ] . disabled = true ;
58+ }
59+ else {
60+ document . getElementsByClassName ( "continue_button" ) [ 0 ] . disabled = false ;
61+ }
62+ } ;
5863function match_num_entry ( entry ) {
5964 let entry_num = Number ( entry ) ;
6065 let select_elements = document . getElementsByClassName ( "teamNumOption" ) ;
@@ -111,6 +116,20 @@ function end_cycle(type) {
111116}
112117cycle_buttons [ 0 ] . addEventListener ( "click" , ( ) => { end_cycle ( 0 ) ; } ) ;
113118cycle_buttons [ 1 ] . addEventListener ( "click" , ( ) => { end_cycle ( 1 ) ; } ) ;
119+ cycle_buttons [ 2 ] . addEventListener ( "click" , ( ) => { end_cycle ( 9 ) ; } ) ;
120+ document . querySelector ( "[name=defense]" ) . onchange = check_responses ;
121+ document . querySelector ( "[name=driving]" ) . onchange = check_responses ;
122+ document . querySelector ( "[name=overall]" ) . onchange = check_responses ;
123+ function check_responses ( ) {
124+ if ( document . querySelector ( "[name=defense]" ) . value . length > 0 &&
125+ document . querySelector ( "[name=driving]" ) . value . length > 0 &&
126+ document . querySelector ( "[name=overall]" ) . value . length > 0 ) {
127+ document . getElementsByClassName ( "continue_button" ) [ 2 ] . disabled = false ;
128+ }
129+ else {
130+ document . getElementsByClassName ( "continue_button" ) [ 2 ] . disabled = true ;
131+ }
132+ }
114133function submit ( ) {
115134 if ( document . querySelector ( "[name=defense]" ) . value
116135 . length == 0 ||
@@ -132,7 +151,7 @@ function submit() {
132151 cycle_data . push ( { id : cycle_data . length , score_type : 4 , intake : Number ( document . querySelector ( "[name=buddy_climb]" ) . checked ) , travel : Number ( document . querySelector ( "[name=buddy_climb]" ) . checked ) , outtake : Number ( document . querySelector ( "[name=buddy_climb]" ) . checked ) } ) ;
133152 const data = {
134153 season : 2024 ,
135- event : document . getElementById ( "event_code" ) . value ,
154+ event : getEventCookie ( ) ,
136155 match_num : Number ( document . getElementById ( "match_num_input" ) . value ) ,
137156 level : "Qualification" ,
138157 team : Number ( document . getElementById ( "team_number" ) . value ) ,
@@ -152,4 +171,35 @@ function submit() {
152171 submit_text . innerHTML = `Error!<br>${ error } ` ;
153172 } ) ;
154173}
155- document . getElementsByClassName ( "continue_button" ) [ 0 ] . addEventListener ( "click" , submit ) ;
174+ function reset ( ) {
175+ clearInterval ( timer_id [ 0 ] ) ;
176+ clearInterval ( timer_id [ 1 ] ) ;
177+ clearInterval ( timer_id [ 2 ] ) ;
178+ timer_id = [ 0 , 0 , 0 ] ;
179+ timer_times = [ 0 , 0 , 0 ] ;
180+ cycle_data = [ ] ;
181+ document . querySelector ( "[name=defense]" ) . value = "" ;
182+ document . querySelector ( "[name=driving]" ) . value = "" ;
183+ document . querySelector ( "[name=overall]" ) . value = "" ;
184+ document . getElementById ( "team_number" ) . value = "" ;
185+ document . querySelector ( "[name=trap_note]" ) . checked = false ;
186+ document . querySelector ( "[name=climb]" ) . checked = false ;
187+ document . querySelector ( "[name=buddy_climb]" ) . checked = false ;
188+ document . getElementById ( "submit_page" ) . style . display = "none" ;
189+ document . getElementById ( "form_content" ) . style . display = "block" ;
190+ let pages = Array . from ( document . getElementsByClassName ( "form_pages" ) ) ;
191+ document . getElementsByClassName ( "continue_button" ) [ 0 ] . disabled = true ;
192+ document . getElementsByClassName ( "continue_button" ) [ 2 ] . disabled = true ;
193+ pages [ 1 ] . style . display = "none" ;
194+ pages [ 2 ] . style . display = "none" ;
195+ pages [ 0 ] . style . display = "flex" ;
196+ }
197+ document . getElementById ( "scout_again" ) . onclick = reset ;
198+ document . getElementsByClassName ( "continue_button" ) [ 2 ] . addEventListener ( "click" , submit ) ;
199+ function advance_page ( current ) {
200+ let pages = Array . from ( document . getElementsByClassName ( "form_pages" ) ) ;
201+ pages [ current ] . style . display = "none" ;
202+ pages [ current + 1 ] . style . display = "flex" ;
203+ }
204+ document . getElementsByClassName ( "continue_button" ) [ 0 ] . addEventListener ( "click" , ( ) => { advance_page ( 0 ) ; } ) ;
205+ document . getElementsByClassName ( "continue_button" ) [ 1 ] . addEventListener ( "click" , ( ) => { advance_page ( 1 ) ; } ) ;
0 commit comments