Skip to content

Commit

Permalink
Merge branch 'epic_188588775_csp_enabled' into 188655901-sep-moving-f…
Browse files Browse the repository at this point in the history
…ields-onkeydown-refactor
  • Loading branch information
bbodine1 authored Dec 23, 2024
2 parents 901a06f + 027e119 commit 01755eb
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 87 deletions.
12 changes: 12 additions & 0 deletions app/assets/javascripts/inline_replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ $(document).on('click', '#priorSepModal .btn-confirmation', function() {
return false;
});

$(document).on('click', '.broker-staff-registration-container button.search', function() {
// components/benefit_sponsors/app/views/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/_new_staff_applicant.html.erb
brokerSearch();
return false
});

$(document).on('click', '.select-broker-agency', function(event) {
event.preventDefault();
selectBrokereAgency(this);
});
// components/benefit_sponsors/app/views/benefit_sponsors/profiles/broker_agencies/broker_agency_staff_roles/_search_broker_agency.html.erb:

function init_dependent_address_fields() {
// app/views/shared/_address_fields_for_dependent.html.erb
$(document).ready(function () {
Expand Down
86 changes: 53 additions & 33 deletions app/assets/javascripts/keyboard_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function handleRadioKeyDown(event, radioId) {
function handleCitizenKeyDown(event, radioIdBase) {
if (event.key === 'Enter') {
const personElement = document.getElementById(`person_${radioIdBase}`);
const dependentElement = document.getElementById(`dependent_${radioIdBase}`);
const dependentElement = document.getElementById(
`dependent_${radioIdBase}`
);

if (personElement) {
personElement.click();
Expand All @@ -32,11 +34,11 @@ function handleContactInfoKeyDown(event, radioId, modifyDiv) {
if (event.key === 'Enter') {
document.getElementById(radioId).click();
hidden_div = document.getElementById(modifyDiv);
if (hidden_div.style.display === "block") {
hidden_div.style.display = "none";
if (hidden_div.style.display === 'block') {
hidden_div.style.display = 'none';
} else {
hidden_div.style.opacity = "1";
hidden_div.style.display = "block";
hidden_div.style.opacity = '1';
hidden_div.style.display = 'block';
}
}
}
Expand All @@ -52,9 +54,12 @@ document.addEventListener('turbolinks:load', () => {
}

/*
* Trigger the click on the proxy element identified by the attribute.
*/
if (targetElement && event.key === 'Enter') {
* Trigger the click on the proxy element identified by the attribute.
*/
if (event.key === 'Enter' && keydownId) {
event.preventDefault();
event.stopImmediatePropagation();

const keydownId = targetElement.dataset.keydownId;
clickElementById(keydownId);
}
Expand Down Expand Up @@ -97,46 +102,61 @@ function handleCancelButtonKeyDown(event, buttonId, hideForm) {
}

function handleGlossaryFocus(glossaryId) {
$("#" + glossaryId).popover('show');
$('#' + glossaryId).popover('show');
}

function handleGlossaryBlur(glossaryId) {
$("#" + glossaryId).popover('hide');
$('#' + glossaryId).popover('hide');
}

function handleGlossaryKeydown(event, glossaryId) {
if (event.key === 'Tab' || event.key === 'Enter') {
$("#" + glossaryId).popover('show');
$('#' + glossaryId).popover('show');
} else {
$("#" + glossaryId).popover('hide');
$('#' + glossaryId).popover('hide');
}
}

window.addEventListener('keydown', function(event) {
if (event.keyIdentifier == 'U+000A' || event.keyIdentifier == 'Enter' || event.key === 'Enter') {
if (event.target.nodeName == 'INPUT' && event.target.type !== 'text' && event.target.type !== 'textarea') {
var form = event.target.closest('form');
var reqCheckboxLists = form.querySelectorAll('.req-checkbox-group');
var requiredChecklists = [...reqCheckboxLists];
var checkListFail = false;
requiredChecklists.forEach(function(reqCheckbox) {
if (reqCheckbox.querySelectorAll('input[type="checkbox"]:checked').length == 0) {
checkListFail = true
reqCheckbox.classList.add('invalid');
window.addEventListener(
'keydown',
function (event) {
if (
event.keyIdentifier == 'U+000A' ||
event.keyIdentifier == 'Enter' ||
event.key === 'Enter'
) {
if (
event.target.nodeName == 'INPUT' &&
event.target.type !== 'text' &&
event.target.type !== 'textarea'
) {
var form = event.target.closest('form');
var reqCheckboxLists = form.querySelectorAll('.req-checkbox-group');
var requiredChecklists = [...reqCheckboxLists];
var checkListFail = false;
requiredChecklists.forEach(function (reqCheckbox) {
if (
reqCheckbox.querySelectorAll('input[type="checkbox"]:checked')
.length == 0
) {
checkListFail = true;
reqCheckbox.classList.add('invalid');
} else {
reqCheckbox.classList.remove('invalid');
}
});
if (form.checkValidity() === false || checkListFail) {
event.preventDefault();
event.stopPropagation();
form.classList.add('was-validated');
} else {
reqCheckbox.classList.remove('invalid');
form.classList.remove('was-validated');
}
});
if (form.checkValidity() === false || checkListFail) {
event.preventDefault();
event.stopPropagation();
form.classList.add('was-validated');
} else {
form.classList.remove('was-validated');
}
}
}
}, true);
},
true
);

document.addEventListener('turbolinks:load', () => {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= f.hidden_field :is_broker_registration_page, value: true %>
<%= f.text_field :agency_search, placeholder: "#{l10n('broker_agencies.broker_roles.agency_name_placeholder')}", class: 'form-control w-50 rounded' %>
<div class="input-group-btn ml-2">
<button class="btn btn-select search short" href="#" onclick="brokerSearch(); return false" data-loading-text="Loading...">
<button class="btn btn-select search short" href="#" data-loading-text="Loading...">
<i class="fa fa-search"></i>
<%= l10n("search").to_s %>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<td class="col-6">
<span class="d-flex align-items-center justify-content-between">
<span><%= agency.primary_broker_role&.person&.full_name %></span>
<a href="javascript:void(0)" class='btn btn-primary select-broker-agency float-right' onclick="selectBrokereAgency(this);" data-broker_agency_profile_id="<%= agency._id %>"><%= l10n("select_this_broker_button") %></a>
<a href="#" class='btn btn-primary select-broker-agency float-right' data-broker_agency_profile_id="<%= agency._id %>"><%= l10n("select_this_broker_button") %></a>
</span>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ function startEditingDeduction(deduction_kind) {
$('.driver-question input, .instruction-row input, .deduction-kind:not(#' + deduction_kind + ') input:not(":input[type=submit]")').attr('disabled', true);
};

$(document).on('change', 'form[data-deduction-id] input[type="date"]', function () {
var form = $(this).parents('form');
if (form.data('income-and-deduction-date-warning-flag')) {
validateDateWarnings(form.data('deduction-id'))
}
});

function currentlyEditing() {
return $('.interaction-click-control-continue').hasClass('disabled') || $('#nav-buttons a').hasClass('disabled');
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function startEditingIncome(income_kind) {
}

function checkDate(income_id) {
var startDate = $('#start_on_' + income_id)
var endDate = $('#end_on_' + income_id)
var startDate = $('#start_on_' + income_id);
var endDate = $('#end_on_' + income_id);

if (endDate && new Date(endDate.val()) <= new Date(startDate.val())) {
alert('The end date must be after the start date.');
Expand All @@ -69,16 +69,20 @@ function checkDate(income_id) {
}
}

$(document).on('submit', 'form[data-income-id]', function() {
$(document).on('submit', 'form[data-income-id]', function () {
checkDate($(this).data('income-id'));
});

$(document).on('change', 'form[data-income-id] input[type="date"]', function () {
var form = $(this).parents('form');
if (form.data('income-and-deduction-date-warning-flag')) {
validateDateWarnings(form.data('income-id'))
$(document).on(
'change',
'form[data-income-id] input[type="date"]',
function () {
var form = $(this).parents('form');
if (form.data('income-and-deduction-date-warning-flag')) {
validateDateWarnings(form.data('income-id'));
}
}
});
);

function currentlyEditing() {
return (
Expand Down Expand Up @@ -169,7 +173,7 @@ document.addEventListener('turbolinks:load', function () {
var self = this;

$('#unsavedIncomeChangesWarning').modal('show');
$('button#leave').on('click', function() {
$('button#leave').on('click', function () {
// these two lines are necessary to prevent the modal from showing again
$('.interaction-click-control-continue').removeClass('disabled');
$('#nav-buttons a').removeClass('disabled');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ def state_options
%w[AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA PR RI SC SD TN TX UT VA VI VT WA WV WI WY]
end

def income_form_for(application, applicant, income, &block)
url = if income.new_record?
application_applicant_incomes_path(application, applicant)
def form_for_record(application, applicant, record, &block)
class_name = record.class.name.demodulize.underscore
url = if record.new_record?
send("application_applicant_#{class_name.pluralize}_path", application, applicant)
else
application_applicant_income_path(@application, @applicant, income)
send("application_applicant_#{class_name}_path", application, applicant, record)
end

form_for income, url: url, remote: true, data: {income_id: income.id.to_s, income_and_deduction_date_warning_flag: FinancialAssistanceRegistry[:income_and_deduction_date_warning].enabled?}, &block
form_for record, url: url, remote: true, data: {"#{class_name}_id".to_sym => record.id.to_s, income_and_deduction_date_warning_flag: FinancialAssistanceRegistry[:income_and_deduction_date_warning].enabled?}, &block
end

alias income_form_for form_for_record

def benefit_form_for(application, applicant, benefit)
url = if benefit.new_record?
application_applicant_benefits_path(application, applicant)
Expand All @@ -137,17 +140,7 @@ def benefit_form_for(application, applicant, benefit)
end
end

def deduction_form_for(application, applicant, deduction)
url = if deduction.new_record?
application_applicant_deductions_path(application, applicant)
else
application_applicant_deduction_path(@application, @applicant, deduction)
end

form_for deduction, url: url, remote: true do |f|
yield f
end
end
alias deduction_form_for form_for_record

def income_and_deductions_for(applicant)
applicant.incomes + applicant.deductions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<% end %>
<% if display_upload_for_evidence?(evidence) %>
<%= form_tag financial_assistance.application_applicant_verification_documents_upload_path(application, applicant), multipart: true, method: :post do %>
<span tabindex="0" onkeydown="handleButtonKeyDown(event, 'upload_evidence_<%= evidence.id %>')" class="btn btn-default btn-file text-nowrap sm-space">
<span tabindex="0" data-keydown-id="upload_evidence_<%= evidence.id %>" class="btn btn-default btn-file text-nowrap sm-space">
<i class="fa fa-upload" aria-hidden="true"></i>
<label>
<%= l10n('upload_documents') %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
</div>
</div>
<div class="d-flex mb-2">
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'income-deduction-delete-<%= dom_id deduction %>')" id="income-deduction-delete-<%= dom_id deduction %>" class="deduction-delete button outline error mr-2"><%= l10n("faa.edit.remove") %></a>
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'income-deduction-edit-<%= dom_id deduction %>')" id="income-deduction-edit-<%= dom_id deduction %>" class="deduction-edit button outline"><%=l10n("edit")%></a>
<a tabindex="0" data-keydown-id='income-deduction-delete-<%= dom_id deduction %>' id="income-deduction-delete-<%= dom_id deduction %>" class="deduction-delete button outline error mr-2"><%= l10n("faa.edit.remove") %></a>
<a tabindex="0" data-keydown-id='income-deduction-edit-<%= dom_id deduction %>' id="income-deduction-edit-<%= dom_id deduction %>" class="deduction-edit button outline"><%=l10n("edit")%></a>
</div>
</div>
<div class="edit-deduction-form hidden">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<% new_form = local_assigns[:new_form].present? ? local_assigns[:new_form] : false %>
<% deduction_id = deduction.id %>
<% dummy_deduction_id = "#{deduction_id}#{new_form ? 'dummy' : ''}" # needed to prevent Multiple Form Label accessibility error %>
<% onchange_date = FinancialAssistanceRegistry[:income_and_deduction_date_warning].enabled? ? (raw "validateDateWarnings('#{deduction_id}', true)") : "" %>
<div class="d-flex row p-0 m-0 mb-2">
<%= f.hidden_field :deduction_type, value: kind %>
<div class="mr-auto col-sm col-md-6 col-lg-3 p-0">
Expand All @@ -17,15 +16,15 @@
</div>
<div class="mr-auto col-sm col-md-6 col-lg-3 p-0 pr-4">
<%= f.label :start_on, l10n("start_date"), class: "required", for: "start_on_#{dummy_deduction_id}" %>
<%= f.date_field :start_on, required: true, id: "start_on_#{dummy_deduction_id}", min: 110.years.ago, max:"9999-12-31", onchange: onchange_date, class: "w-100" %>
<%= f.date_field :start_on, required: true, id: "start_on_#{dummy_deduction_id}", min: 110.years.ago, max:"9999-12-31", class: "w-100" %>
</div>
<div class="col-sm col-md-6 col-lg-3 p-0 pr-4">
<%= f.label :end_on, l10n("end_date"), for: "end_on_#{dummy_deduction_id}" %>
<%= f.date_field :end_on, id: "end_on_#{dummy_deduction_id}", min: 110.years.ago, max:"9999-12-31", onchange: onchange_date, class: "w-100" %>
<%= f.date_field :end_on, id: "end_on_#{dummy_deduction_id}", min: 110.years.ago, max:"9999-12-31", class: "w-100" %>
</div>
</div>
<div class="d-flex mb-2 align-items-center">
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'income-deduction-cancel-<%= deduction_id %>')" id="income-deduction-cancel-<%= deduction_id %>" class="btn outline deduction-cancel mr-2"><%= l10n("cancel") %></a>
<a tabindex="0" data-keydown-id='income-deduction-cancel-<%= deduction_id %>' id="income-deduction-cancel-<%= deduction_id %>" class="btn outline deduction-cancel mr-2"><%= l10n("cancel") %></a>
<%= f.submit l10n("faa.other_incomes.save"), disabled: new_form.present? && new_form ? "disabled" : nil, class: "button", :data => { :cuke => "income-adjustments-save-button" } %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<%= render partial: 'financial_assistance/deductions/deduction_form', locals: { deduction: FinancialAssistance::Deduction.new, kind: deduction_kind, new_form: true} %>
</div>
<div class="add-more-link mt-4 <%= 'hidden' unless @applicant.deductions.of_kind(deduction_kind).present? %>" id="add-more-link-<%=deduction_kind%>">
<button tabindex="0" onkeydown="handleButtonKeyDown(event, 'add_new_deduction_kind')" class="button add_new_deduction_kind">
<button tabindex="0" data-keydown-id='add_new_deduction_kind' id='add_new_deduction_kind' class="button add_new_deduction_kind">
<%= l10n("faa.other_incomes.add", kind: label).titleize %>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</div>
</div>
<div class="d-flex mb-2">
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'other-income-delete-<%= dom_id other_income %>')" id="other-income-delete-<%= dom_id other_income %>" class="other-income-delete button outline error mr-2"><%= l10n("faa.edit.remove") %></a>
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'other-income-edit-<%= dom_id other_income %>')" id="other-income-edit-<%= dom_id other_income %>" class="other-income-edit button outline"><%=l10n("edit")%></a>
<a tabindex="0" data-keydown-id='other-income-delete-<%= dom_id other_income %>' id="other-income-delete-<%= dom_id other_income %>" class="other-income-delete button outline error mr-2"><%= l10n("faa.edit.remove") %></a>
<a tabindex="0" data-keydown-id='other-income-edit-<%= dom_id other_income %>' id="other-income-edit-<%= dom_id other_income %>" class="other-income-edit button outline"><%=l10n("edit")%></a>
</div>
</div>
<div class="edit-other-income-form hidden">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<% income_id = other_income.id %>
<% new_form = local_assigns[:new_form].present? ? local_assigns[:new_form] : false %>
<% dummy_income_id = "#{income_id}#{new_form ? 'dummy' : ''}" # needed to prevent Multiple Form Label accessibility error %>
<% onchange_date = FinancialAssistanceRegistry[:income_and_deduction_date_warning].enabled? ? (raw "validateDateWarnings('#{income_id}', true)") : "" %>
<div class="my-4">
<div class="d-flex row income-form-row p-0 m-0 mb-2">
<%= f.hidden_field :kind, value: kind %>
Expand All @@ -31,15 +30,15 @@
</div>
<div class="mr-auto col-sm col-md-6 col-lg-3 p-0 pr-4">
<%= f.label :start_on, l10n("start_date"), class: "required", for: "start_on_#{dummy_income_id}" %>
<%= f.date_field :start_on, min: 110.years.ago, max:"9999-12-31", required: true, id: "start_on_#{dummy_income_id}", onchange: onchange_date, class: "w-100" %>
<%= f.date_field :start_on, min: 110.years.ago, max:"9999-12-31", required: true, id: "start_on_#{dummy_income_id}", class: "w-100" %>
</div>
<div class="col-sm col-md-6 col-lg-3 p-0 pr-4">
<%= f.label :start_on, l10n("end_date"), for: "end_on_#{dummy_income_id}" %>
<%= f.date_field :end_on, min: 110.years.ago, max:"9999-12-31", id: "end_on_#{dummy_income_id}", onchange: onchange_date, class: "w-100 #{'end-on-field' if FinancialAssistanceRegistry.feature_enabled?(:other_income_end_date_warning)}" %>
<%= f.date_field :end_on, min: 110.years.ago, max:"9999-12-31", id: "end_on_#{dummy_income_id}", class: "w-100 #{'end-on-field' if FinancialAssistanceRegistry.feature_enabled?(:other_income_end_date_warning)}" %>
</div>
</div>
<div class="d-flex mb-2">
<a tabindex="0" onkeydown="handleButtonKeyDown(event, 'other-income-cancel-<%= income_id %>', 'new-other-income-form')" id="other-income-cancel-<%= income_id %>" class="button outline other-income-cancel mr-2"><%= l10n("cancel") %></a>
<a tabindex="0" data-keydown-id='other-income-cancel-<%= income_id %>' id="other-income-cancel-<%= income_id %>" class="button outline other-income-cancel mr-2"><%= l10n("cancel") %></a>
<%= f.submit l10n("faa.other_incomes.save"), disabled: disabled.present? && disabled ? "disabled" : nil, class: "button", :data => { :cuke => "other-income-save-button" } %>
</div>
</div>
Expand Down
Loading

0 comments on commit 01755eb

Please sign in to comment.