@@ -99,7 +99,13 @@ <h5>Plot / Export data</h5>
9999 </ div >
100100</ section >
101101< script >
102- $ ( document ) . ready ( function ( ) {
102+ function initGeographicValueSelect ( mode ) {
103+ var maxSelectionLength = 1 ;
104+ if ( mode === 'epivis' ) {
105+ maxSelectionLength = 1 ;
106+ } else {
107+ maxSelectionLength = 10 ;
108+ }
103109 $ ( '#geographic_value' ) . select2 ( {
104110 ajax : {
105111 url : '{% url ' geography_units_api ' %}' ,
@@ -131,8 +137,12 @@ <h5>Plot / Export data</h5>
131137 }
132138 } ,
133139 minimumInputLength : 0 ,
134- maximumSelectionLength : 1 ,
140+ maximumSelectionLength : maxSelectionLength ,
135141 } ) ;
142+ }
143+
144+ $ ( document ) . ready ( function ( ) {
145+ initGeographicValueSelect ( 'epivis' ) ;
136146 } ) ;
137147
138148 document . getElementById ( 'geographic_type' ) . addEventListener ( "change" , ( event ) => {
@@ -142,22 +152,23 @@ <h5>Plot / Export data</h5>
142152 document . getElementsByName ( 'modes' ) . forEach ( ( el ) => {
143153 el . addEventListener ( 'change' , ( event ) => {
144154 $ ( '#geographic_value' ) . val ( null ) . trigger ( 'change' ) ;
155+ //$('#geographic_value').select2('destroy');
145156 if ( event . target . value === 'epivis' ) {
146- $ ( '#geographic_value' ) . select2 ( 'destroy' ) ;
147- $ ( '#geographic_value' ) . select2 ( { maximumSelectionLength : 1 } )
157+ initGeographicValueSelect ( event . target . value ) ;
148158 } else {
149- $ ( '#geographic_value' ) . select2 ( 'destroy' ) ;
150- $ ( '#geographic_value' ) . select2 ( { maximumSelectionLength : 5 } )
159+ initGeographicValueSelect ( 'export' ) ;
151160 }
152- // handleModeChange(event.target);
161+ handleModeChange ( event . target . value ) ;
153162 } ) ;
154163 } ) ;
155164
156165 var currentMode = 'epivis' ;
157166
158- function handleModeChange ( el ) {
167+ function handleModeChange ( mode ) {
168+ document . getElementById ( "epivis-form" ) . reset ( ) ;
169+
159170 var choose_dates = document . getElementsByName ( 'choose_date' ) ;
160- if ( el . value === 'epivis' ) {
171+ if ( mode === 'epivis' ) {
161172 currentMode = 'epivis' ;
162173 choose_dates . forEach ( ( el ) => {
163174 el . style . display = 'none' ;
@@ -168,6 +179,11 @@ <h5>Plot / Export data</h5>
168179 el . style . display = 'flex' ;
169180 } ) ;
170181 }
182+ document . getElementsByName ( "modes" ) . forEach ( ( el ) => {
183+ if ( currentMode === el . value ) {
184+ el . checked = true ;
185+ }
186+ } ) ;
171187 }
172188
173189
@@ -184,7 +200,7 @@ <h5>Plot / Export data</h5>
184200 return ;
185201 }
186202
187- /* if (currentMode === 'epivis') {
203+ if ( currentMode === 'epivis' ) {
188204 var epiVisUrl = "{{ epivis_url }}" ;
189205 var urlParamsEncoded = btoa ( `{"datasets":[{"color":"#415742","title":"value","params":{"_endpoint":"covidcast","data_source":"${ dataSource } ","signal":"${ dataSignal } ","time_type":"day","geo_type":"${ geographicType } ","geo_value":"${ geographicValue } "}}]}` ) ;
190206
@@ -203,9 +219,7 @@ <h5>Plot / Export data</h5>
203219 }
204220
205221 dataExportUrl += `?signal=${ dataSource } :${ dataSignal } &start_day=${ startDate } &end_day=${ endDate } &geo_type=${ geographicType } &geo_values=${ geographicValue } ` ;
206-
207- }*/
208-
209-
222+ window . open ( dataExportUrl , '_blank' ) . focus ( ) ;
223+ }
210224 }
211225</ script >
0 commit comments