diff --git a/apcd_cms/src/apps/extension/templates/extension_submission_form/extension_submission_form.html b/apcd_cms/src/apps/extension/templates/extension_submission_form/extension_submission_form.html index d53b88af..55ff84ea 100644 --- a/apcd_cms/src/apps/extension/templates/extension_submission_form/extension_submission_form.html +++ b/apcd_cms/src/apps/extension/templates/extension_submission_form/extension_submission_form.html @@ -69,7 +69,7 @@
Submission Dates
name="extension-date-asterisk">* @@ -295,7 +295,7 @@
Submission Dates
name="extension-date-asterisk">* @@ -344,12 +344,31 @@
Submission Dates
}; 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', @@ -371,6 +390,11 @@
Submission Dates
$(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); @@ -390,6 +414,11 @@
Submission Dates
// 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(); diff --git a/apcd_cms/src/apps/extension/views.py b/apcd_cms/src/apps/extension/views.py index 4d49227c..b992cf35 100644 --- a/apcd_cms/src/apps/extension/views.py +++ b/apcd_cms/src/apps/extension/views.py @@ -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