@@ -169,38 +169,19 @@ public void addMoreFilters(CustomLayout moreFiltersContainer) {
169169 facilityField .setEnabled (false );
170170 facilityField .setVisible (false );
171171
172- ComboBox typeOfPlaceField = getField (EventDto .TYPE_OF_PLACE );
173-
174- Arrays .asList (districtField , communityField , typeOfPlaceField ).forEach (field -> field .addValueChangeListener (e -> {
175- final UserDto user = UserProvider .getCurrent ().getUser ();
176- final CommunityReferenceDto community =
177- user .getCommunity () != null ? user .getCommunity () : (CommunityReferenceDto ) communityField .getValue ();
178- final DistrictReferenceDto district = user .getDistrict () != null ? user .getDistrict () : (DistrictReferenceDto ) districtField .getValue ();
179- boolean visible = (community != null || district != null ) && typeOfPlaceField .getValue () == TypeOfPlace .FACILITY ;
180- if (!visible ) {
181- facilityField .clear ();
182- facilityTypeField .clear ();
183- facilityTypeGroupField .clear ();
184- }
185- facilityField .setVisible (visible );
186- facilityTypeField .setVisible (visible );
187- facilityTypeGroupField .setVisible (visible );
188- }));
189-
190- facilityTypeGroupField .addValueChangeListener (e -> {
191- FieldHelper .updateEnumData (
172+ facilityTypeGroupField .addValueChangeListener (
173+ e -> FieldHelper .updateEnumData (
192174 facilityTypeField ,
193175 facilityTypeGroupField .getValue () != null
194176 ? FacilityType .getTypes ((FacilityTypeGroup ) facilityTypeGroupField .getValue ())
195- : Arrays .stream (FacilityType .values ()).collect (Collectors .toList ()));
196- });
177+ : Arrays .stream (FacilityType .values ()).collect (Collectors .toList ())));
197178
198179 facilityTypeField .addValueChangeListener (e -> {
199- if (facilityTypeField .getValue () != null ) {
180+ final FacilityType facilityType = (FacilityType ) facilityTypeField .getValue ();
181+ if (facilityType != null ) {
200182 final UserDto user = UserProvider .getCurrent ().getUser ();
201183 final CommunityReferenceDto community =
202184 user .getCommunity () != null ? user .getCommunity () : (CommunityReferenceDto ) communityField .getValue ();
203- final FacilityType facilityType = (FacilityType ) facilityTypeField .getValue ();
204185
205186 facilityField .setEnabled (true );
206187 if (community != null ) {
@@ -319,6 +300,7 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
319300 clearAndDisableFields (LocationDto .DISTRICT , LocationDto .COMMUNITY );
320301 }
321302 populateSurveillanceOfficersForRegion (region );
303+ applyFacilityFieldsDependencies ();
322304 break ;
323305 case LocationDto .DISTRICT :
324306 DistrictReferenceDto district = (DistrictReferenceDto ) event .getProperty ().getValue ();
@@ -328,6 +310,10 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
328310 clearAndDisableFields (LocationDto .COMMUNITY );
329311 }
330312 populateSurveillanceOfficersForDistrict (district );
313+ applyFacilityFieldsDependencies ();
314+ break ;
315+ case EventDto .TYPE_OF_PLACE :
316+ applyFacilityFieldsDependencies ();
331317 break ;
332318 }
333319 }
@@ -372,6 +358,8 @@ protected void applyDependenciesOnNewValue(EventCriteria criteria) {
372358 RegionReferenceDto region = criteria .getRegion ();
373359 DistrictReferenceDto district = criteria .getDistrict ();
374360 applyRegionAndDistrictFilterDependency (region , LocationDto .DISTRICT , district , LocationDto .COMMUNITY );
361+
362+ applyFacilityFieldsDependencies (criteria .getTypeOfPlace (), criteria .getDistrict (), criteria .getCommunity ());
375363 }
376364
377365 private void applyDateDependencyOnNewValue (String componentId , DateFilterOption dateFilterOption , Date dateFrom , Date dateTo ) {
@@ -417,6 +405,34 @@ private List<UserReferenceDto> fetchSurveillanceOfficersByRegion(RegionReference
417405 return FacadeProvider .getUserFacade ().getUsersByRegionAndRoles (regionReferenceDto , UserRole .SURVEILLANCE_OFFICER );
418406 }
419407
408+ private void applyFacilityFieldsDependencies () {
409+ applyFacilityFieldsDependencies (
410+ (TypeOfPlace ) getField (EventDto .TYPE_OF_PLACE ).getValue (),
411+ (DistrictReferenceDto ) getField (LocationDto .DISTRICT ).getValue (),
412+ (CommunityReferenceDto ) getField (LocationDto .COMMUNITY ).getValue ());
413+ }
414+
415+ private void applyFacilityFieldsDependencies (
416+ TypeOfPlace typeOfPlace ,
417+ DistrictReferenceDto districtReferenceDto ,
418+ CommunityReferenceDto communityReferenceDto ) {
419+
420+ final UserDto user = UserProvider .getCurrent ().getUser ();
421+ final boolean visible = typeOfPlace == TypeOfPlace .FACILITY
422+ && ((user .getCommunity () != null || communityReferenceDto != null ) || (user .getDistrict () != null || districtReferenceDto != null ));
423+ final ComboBox facilityField = getField (LocationDto .FACILITY );
424+ final ComboBox facilityTypeField = getField (LocationDto .FACILITY_TYPE );
425+ final ComboBox facilityTypeGroupField = (ComboBox ) getMoreFiltersContainer ().getComponent (FACILITY_TYPE_GROUP_FILTER );
426+ if (!visible ) {
427+ facilityField .clear ();
428+ facilityTypeField .clear ();
429+ facilityTypeGroupField .clear ();
430+ }
431+ facilityField .setVisible (visible );
432+ facilityTypeField .setVisible (visible );
433+ facilityTypeGroupField .setVisible (visible );
434+ }
435+
420436 @ Override
421437 protected String createMoreFiltersHtmlLayout () {
422438 return MORE_FILTERS_HTML_LAYOUT ;
0 commit comments