@@ -175,6 +175,29 @@ async function checkGeoCoverage(geoValue) {
175
175
}
176
176
}
177
177
178
+ function getAvailableGeos ( indicators ) {
179
+ var availableGeos = null ;
180
+
181
+ const csrftoken = Cookies . get ( "csrftoken" ) ;
182
+
183
+ const submitData = {
184
+ indicators : indicators
185
+ }
186
+
187
+ $ . ajax ( {
188
+ url : "get_available_geos/" ,
189
+ type : "POST" ,
190
+ async : false , // Synchronous request to ensure availableGeos is populated before returning
191
+ dataType : "json" ,
192
+ contentType : "application/json" ,
193
+ headers : { "X-CSRFToken" : csrftoken } ,
194
+ data : JSON . stringify ( submitData ) ,
195
+ } ) . done ( function ( data ) {
196
+ availableGeos = data . geographic_granularities ;
197
+ } ) ;
198
+ return availableGeos ;
199
+ }
200
+
178
201
$ ( "#geographic_value" ) . on ( "select2:select" , function ( e ) {
179
202
var geo = e . params . data ;
180
203
checkGeoCoverage ( geo . id ) . then ( ( notCoveredIndicators ) => {
@@ -187,6 +210,14 @@ $("#geographic_value").on("select2:select", function (e) {
187
210
188
211
$ ( "#showSelectedIndicatorsButton" ) . click ( function ( ) {
189
212
alertPlaceholder . innerHTML = "" ;
213
+ const availableGeos = getAvailableGeos ( checkedIndicatorMembers ) ;
214
+ const locationIds = $ ( "#location_search" ) . select2 ( "data" ) . map ( ( item ) => item . id ) ;
215
+ $ ( "#geographic_value" ) . select2 ( {
216
+ data : availableGeos ,
217
+ minimumInputLength : 0 ,
218
+ maximumSelectionLength : 5 ,
219
+ } ) ;
220
+ $ ( '#geographic_value' ) . val ( locationIds ) . trigger ( 'change' ) ;
190
221
if ( ! indicatorHandler . checkForCovidcastIndicators ( ) ) {
191
222
$ ( '#geographic_value' ) . val ( null ) . trigger ( 'change' ) ;
192
223
$ ( "#geographic_value" ) . prop ( "disabled" , true ) ;
@@ -200,11 +231,10 @@ $("#showSelectedIndicatorsButton").click(function () {
200
231
}
201
232
} )
202
233
} ) ;
203
- var otherEndpointLocationsWarning = `<div class="alert alert-info" data-mdb-alert-init role="alert">` +
204
- ` <div>Please, note that some indicator sets may require to select location(s) that is/are different from location(s) above.<br> `
205
234
nonCovidcastIndicatorSets = [ ...new Set ( checkedIndicatorMembers . filter ( indicator => indicator [ "_endpoint" ] != "covidcast" ) . map ( ( indicator ) => indicator [ "indicator_set" ] ) ) ] ;
206
- otherEndpointLocationsWarning += `Different location is required for following Indicator Set(s): ${ nonCovidcastIndicatorSets . join ( ", " ) } `
207
- otherEndpointLocationsWarning += `</div></div>`
235
+ var otherEndpointLocationsWarning = `<div class="alert alert-info" data-mdb-alert-init role="alert">`
236
+ otherEndpointLocationsWarning += `For Indicator Set(s): ${ nonCovidcastIndicatorSets . join ( ", " ) } , please use the Location menu below:`
237
+ otherEndpointLocationsWarning += `</div>`
208
238
if ( indicatorHandler . getFluviewIndicators ( ) . length > 0 ) {
209
239
$ ( "#differentLocationNote" ) . html ( otherEndpointLocationsWarning )
210
240
if ( document . getElementsByName ( "fluviewRegions" ) . length === 0 ) {
0 commit comments