@@ -99,7 +99,13 @@ <h5>Plot / Export data</h5>
99
99
</ div >
100
100
</ section >
101
101
< 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
+ }
103
109
$ ( '#geographic_value' ) . select2 ( {
104
110
ajax : {
105
111
url : '{% url ' geography_units_api ' %}' ,
@@ -131,8 +137,12 @@ <h5>Plot / Export data</h5>
131
137
}
132
138
} ,
133
139
minimumInputLength : 0 ,
134
- maximumSelectionLength : 1 ,
140
+ maximumSelectionLength : maxSelectionLength ,
135
141
} ) ;
142
+ }
143
+
144
+ $ ( document ) . ready ( function ( ) {
145
+ initGeographicValueSelect ( 'epivis' ) ;
136
146
} ) ;
137
147
138
148
document . getElementById ( 'geographic_type' ) . addEventListener ( "change" , ( event ) => {
@@ -142,22 +152,23 @@ <h5>Plot / Export data</h5>
142
152
document . getElementsByName ( 'modes' ) . forEach ( ( el ) => {
143
153
el . addEventListener ( 'change' , ( event ) => {
144
154
$ ( '#geographic_value' ) . val ( null ) . trigger ( 'change' ) ;
155
+ //$('#geographic_value').select2('destroy');
145
156
if ( event . target . value === 'epivis' ) {
146
- $ ( '#geographic_value' ) . select2 ( 'destroy' ) ;
147
- $ ( '#geographic_value' ) . select2 ( { maximumSelectionLength : 1 } )
157
+ initGeographicValueSelect ( event . target . value ) ;
148
158
} else {
149
- $ ( '#geographic_value' ) . select2 ( 'destroy' ) ;
150
- $ ( '#geographic_value' ) . select2 ( { maximumSelectionLength : 5 } )
159
+ initGeographicValueSelect ( 'export' ) ;
151
160
}
152
- // handleModeChange(event.target);
161
+ handleModeChange ( event . target . value ) ;
153
162
} ) ;
154
163
} ) ;
155
164
156
165
var currentMode = 'epivis' ;
157
166
158
- function handleModeChange ( el ) {
167
+ function handleModeChange ( mode ) {
168
+ document . getElementById ( "epivis-form" ) . reset ( ) ;
169
+
159
170
var choose_dates = document . getElementsByName ( 'choose_date' ) ;
160
- if ( el . value === 'epivis' ) {
171
+ if ( mode === 'epivis' ) {
161
172
currentMode = 'epivis' ;
162
173
choose_dates . forEach ( ( el ) => {
163
174
el . style . display = 'none' ;
@@ -168,6 +179,11 @@ <h5>Plot / Export data</h5>
168
179
el . style . display = 'flex' ;
169
180
} ) ;
170
181
}
182
+ document . getElementsByName ( "modes" ) . forEach ( ( el ) => {
183
+ if ( currentMode === el . value ) {
184
+ el . checked = true ;
185
+ }
186
+ } ) ;
171
187
}
172
188
173
189
@@ -184,7 +200,7 @@ <h5>Plot / Export data</h5>
184
200
return ;
185
201
}
186
202
187
- /* if (currentMode === 'epivis') {
203
+ if ( currentMode === 'epivis' ) {
188
204
var epiVisUrl = "{{ epivis_url }}" ;
189
205
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 } "}}]}` ) ;
190
206
@@ -203,9 +219,7 @@ <h5>Plot / Export data</h5>
203
219
}
204
220
205
221
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
+ }
210
224
}
211
225
</ script >
0 commit comments