Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Duplicate applicable data periods in extensions form #406

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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