Skip to content

Commit

Permalink
Bug: Duplicate applicable data periods in extensions form (#406)
Browse files Browse the repository at this point in the history
* Factor out applicable data periods to be queried per submitter

* List new data period options when user selects new submitter

* Implement options change for additional extension blocks + specify extensions block number to keep entries distinct
  • Loading branch information
edmondsgarrett authored Jan 13, 2025
1 parent 07e5298 commit 92627a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h6>Submission Dates</h6>
name="extension-date-asterisk"><span class="asterisk">*</span></label></label>
<select name='applicable-data-period_1' required='required' id='applicable-data-period_1'>
<option class="dropdown-text" value=''>-- Select period --</option>
{% for data_period in applicable_data_periods %}
{% for data_period in submitters.0.applicable_data_periods %}
<option class="dropdown-text" value={{data_period}}>{{data_period}}</option>
{% endfor %}
</select>
Expand Down Expand Up @@ -295,7 +295,7 @@ <h6>Submission Dates</h6>
name="extension-date-asterisk"><span class="asterisk">*</span></label></label>
<select name='applicable-data-period_${extensions}' required='required' id='applicable-data-period_${extensions}'>
<option class="dropdown-text" value=''>-- Select period --</option>
{% for data_period in applicable_data_periods %}
{% for data_period in submitters.0.applicable_data_periods %}
<option class="dropdown-text" value={{data_period}}>{{data_period}}</option>
{% endfor %}
</select>
Expand Down Expand Up @@ -344,12 +344,31 @@ <h6>Submission Dates</h6>
};
return extensions
};
// To populate applicable data periods dropdown on choosing submitter (only used when user has >1 submitter)
function setApplicablePeriods(submitter_id, extensions) {
let submitterList = JSON.parse("{{ submitters | safe }}".replaceAll(`'`, `\"`).replaceAll('None', null));
let dataPeriodsList = submitterList.find(submitter => submitter.submitter_id == submitter_id).applicable_data_periods;
let applicableDataDropdown = $(`#applicable-data-period_${extensions}`);
let expectedDate = $(`#current-expected-date_${extensions}`); // also need to clear out expected date
let hiddenDate = $(`#hidden-current-expected-date_${extensions}`);

applicableDataDropdown.find('option').not(':first').remove(); // remove all data period options, prep for repopulating
expectedDate.val('');
hiddenDate.val('');

for (var i = 0; i < dataPeriodsList.length; i++) {
var dataPeriod = dataPeriodsList[i];
var dataPeriodOption = new Option(dataPeriod, dataPeriod)
applicableDataDropdown.append(dataPeriodOption)
}
}

// To access previously hidden extension blocks and populate with info from AJAX call.
function setExpectedDate(applicable_data_period, extensions) {
let expectedDate = $(`#current-expected-date_${extensions}`);
let hiddenDate = $(`#hidden-current-expected-date_${extensions}`);
const submitter_id = $(`#business-name_${extensions}`).val();
// Gets submitter id from view context to pass to db call
const submitter_id = "{{ submitters.0.submitter_id}}"
$.ajax({
url: "{% url 'extension:get-expected-date' %}",
type: 'GET',
Expand All @@ -371,6 +390,11 @@ <h6>Submission Dates</h6>
$(document).ready(function() {
let extensions = 1;
btnStatus(extensions);
$('[id="business-name"]').change(function() {
let subId = $(this).val();
let extensionsNum = $(this).attr('id').slice(-1);
setApplicablePeriods(subId, extensionsNum);
});
$('[id^="requested-target-date"]').click(function() {
let field = $(this).attr('id');
restrictExpirationDate(field, extensions);
Expand All @@ -390,6 +414,11 @@ <h6>Submission Dates</h6>
// To track how many extension blocks there are for button logic
extensions = addExtension(extensions);
btnStatus(extensions);
$('[id^="business-name"]').change(function() {
let subId = $(this).val();
let extensionsNum = $(this).attr('id').slice(-1);
setApplicablePeriods(subId, extensionsNum);
});
// Gets applicable data period for additional added blocks
$('[id^="applicable-data-period"]').change(function() {
let appDataValue = $(this).val();
Expand Down
13 changes: 8 additions & 5 deletions apcd_cms/src/apps/extension/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@ def get_context_data(self, *args, **kwargs):

self.request.session['submitters'] = submitters

def _set_submitter(sub):
def _set_submitter(sub, applicable_data_periods):
return {
"submitter_id": sub[0],
"submitter_code": sub[1],
"payor_code": sub[2],
"user_name": sub[3],
"entity_name": title_case(sub[4])
"entity_name": title_case(sub[4]),
"applicable_data_periods": applicable_data_periods
}
context["submitters"] = []
context["applicable_data_periods"] = []

for submitter in submitters:
context['submitters'].append(_set_submitter(submitter))
for submitter in submitters:
applicable_data_periods = apcd_database.get_applicable_data_periods(submitter[0])
data_periods = []
for data_period_tuple in applicable_data_periods:
for data_period in data_period_tuple:
data_period = _get_applicable_data_period(data_period)
context['applicable_data_periods'].append(data_period)
data_periods.append(data_period)
data_periods = sorted(data_periods, reverse=True)
context['submitters'].append(_set_submitter(submitter, data_periods))

context['applicable_data_periods'] = sorted(context['applicable_data_periods'], reverse=True)
return context
Expand Down

0 comments on commit 92627a7

Please sign in to comment.