From 51bce018f195e601d6eda86b24784aeea198a63b Mon Sep 17 00:00:00 2001 From: Minha Date: Fri, 23 Aug 2024 15:40:23 -0400 Subject: [PATCH 1/4] Gray out/disable selected options from dropdown list --- corehq/apps/locations/static/locations/js/widgets.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/corehq/apps/locations/static/locations/js/widgets.js b/corehq/apps/locations/static/locations/js/widgets.js index 56025efb5d1d..261be27259be 100644 --- a/corehq/apps/locations/static/locations/js/widgets.js +++ b/corehq/apps/locations/static/locations/js/widgets.js @@ -76,6 +76,18 @@ hqDefine("locations/js/widgets", [ }, processResults: function (data, params) { var more = (params.page || 1) * 10 < data.total; + var selected_locations = $select[0].selectedOptions + if (selected_locations.length > 0) { + var loc_ids = [] + for (var i in selected_locations) { + loc_ids.push(selected_locations[i].value) + } + for (var i in data.results) { + if (loc_ids.indexOf(data.results[i].id) > -1) { + data.results[i].disabled = "disabled" + } + } + } return { results: data.results, pagination: { more: more }, From 3aa3f4a8e02df3ac15802b430c2095a79ddd8157 Mon Sep 17 00:00:00 2001 From: Minha Date: Fri, 23 Aug 2024 17:00:05 -0400 Subject: [PATCH 2/4] Lint fixes --- .../locations/static/locations/js/widgets.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/corehq/apps/locations/static/locations/js/widgets.js b/corehq/apps/locations/static/locations/js/widgets.js index 261be27259be..5fd722ec603d 100644 --- a/corehq/apps/locations/static/locations/js/widgets.js +++ b/corehq/apps/locations/static/locations/js/widgets.js @@ -76,15 +76,17 @@ hqDefine("locations/js/widgets", [ }, processResults: function (data, params) { var more = (params.page || 1) * 10 < data.total; - var selected_locations = $select[0].selectedOptions - if (selected_locations.length > 0) { - var loc_ids = [] - for (var i in selected_locations) { - loc_ids.push(selected_locations[i].value) + var selectedLocations = $select[0].selectedOptions; + if (selectedLocations.length > 0) { + var locIds = []; + for (var i in selectedLocations) { + if (selectedLocations[i].value) { + locIds.push(selectedLocations[i].value); + } } - for (var i in data.results) { - if (loc_ids.indexOf(data.results[i].id) > -1) { - data.results[i].disabled = "disabled" + for (var j in data.results) { + if (locIds.indexOf(data.results[j].id) > -1) { + data.results[j].disabled = "disabled"; } } } From dc51de8f7362caeaa08a1a5be39fd84415f6465a Mon Sep 17 00:00:00 2001 From: Minha Date: Tue, 27 Aug 2024 13:30:04 -0400 Subject: [PATCH 3/4] Apply suggested refactor --- .../locations/static/locations/js/widgets.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/corehq/apps/locations/static/locations/js/widgets.js b/corehq/apps/locations/static/locations/js/widgets.js index 5fd722ec603d..5ae7857ee4ae 100644 --- a/corehq/apps/locations/static/locations/js/widgets.js +++ b/corehq/apps/locations/static/locations/js/widgets.js @@ -76,19 +76,14 @@ hqDefine("locations/js/widgets", [ }, processResults: function (data, params) { var more = (params.page || 1) * 10 < data.total; - var selectedLocations = $select[0].selectedOptions; + let selectedLocations = Array.from($select[0].selectedOptions); if (selectedLocations.length > 0) { - var locIds = []; - for (var i in selectedLocations) { - if (selectedLocations[i].value) { - locIds.push(selectedLocations[i].value); + let locIds = selectedLocations.map(option => option.value); + data.results.forEach(result => { + if (locIds.includes(result.id)) { + result.disabled = true; } - } - for (var j in data.results) { - if (locIds.indexOf(data.results[j].id) > -1) { - data.results[j].disabled = "disabled"; - } - } + }); } return { results: data.results, From 574f505639417e385fa107cf49be0d155213949f Mon Sep 17 00:00:00 2001 From: Minha Date: Wed, 28 Aug 2024 14:42:44 -0400 Subject: [PATCH 4/4] Put changes behind general locations work feature flag --- .../locations/static/locations/js/widgets.js | 22 +++++++++++-------- corehq/toggles/__init__.py | 8 +++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/corehq/apps/locations/static/locations/js/widgets.js b/corehq/apps/locations/static/locations/js/widgets.js index 5ae7857ee4ae..15ab74a44c94 100644 --- a/corehq/apps/locations/static/locations/js/widgets.js +++ b/corehq/apps/locations/static/locations/js/widgets.js @@ -2,10 +2,12 @@ hqDefine("locations/js/widgets", [ 'jquery', 'underscore', + 'hqwebapp/js/toggles', 'select2/dist/js/select2.full.min', ], function ( $, - _ + _, + toggles ) { // Update the options available to one select2 to be // the selected values from another (multiselect) select2 @@ -76,14 +78,16 @@ hqDefine("locations/js/widgets", [ }, processResults: function (data, params) { var more = (params.page || 1) * 10 < data.total; - let selectedLocations = Array.from($select[0].selectedOptions); - if (selectedLocations.length > 0) { - let locIds = selectedLocations.map(option => option.value); - data.results.forEach(result => { - if (locIds.includes(result.id)) { - result.disabled = true; - } - }); + if (toggles.toggleEnabled('LOCATION_FIELD_USER_PROVISIONING')) { + let selectedLocations = Array.from($select[0].selectedOptions); + if (selectedLocations.length > 0) { + let locIds = selectedLocations.map(option => option.value); + data.results.forEach(result => { + if (locIds.includes(result.id)) { + result.disabled = true; + } + }); + } } return { results: data.results, diff --git a/corehq/toggles/__init__.py b/corehq/toggles/__init__.py index 08bdceb3c276..d6c77f84cf16 100644 --- a/corehq/toggles/__init__.py +++ b/corehq/toggles/__init__.py @@ -976,6 +976,14 @@ def _ensure_valid_randomness(randomness): owner='Jenny Schweers', ) +LOCATION_FIELD_USER_PROVISIONING = FeatureRelease( + 'location_field_user_provisioning', + 'USH: Holding feature flag for various works relating to the location field', + TAG_RELEASE, + namespaces=[NAMESPACE_DOMAIN], + owner='Minha Lee', +) + WEB_APPS_ANCHORED_SUBMIT = StaticToggle( 'web_apps_anchored_submit', 'USH: Keep submit button anchored at the bottom of screen for forms in Web Apps',