Skip to content

Commit

Permalink
move inline js out of html file and into external js file
Browse files Browse the repository at this point in the history
  • Loading branch information
bbodine1 committed Dec 24, 2024
1 parent 082192c commit 2126812
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 60 deletions.
63 changes: 63 additions & 0 deletions app/assets/javascripts/financial_assistance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Initialize the dependent person form
$(document).on('ajax:success', '#edit-dependent-person', function (event) {
$.inputMasks();

$('#applicant_same_with_primary').on('click', function () {
if ($(this).is(':checked')) {
$('#applicant-home-address-area').addClass('hidden');
} else {
$('#applicant-home-address-area').removeClass('hidden');
}
});

$(document).on('click', 'button#delete_applicant_button', function (e) {
e.preventDefault();
$('#destroyApplicant').modal();

$('#destroyApplicant .modal-cancel-button').on('click', function (e) {
console.log('cancel');
$('#destroyApplicant').modal('hidden');
});
$('.btn-confirmation').removeAttr('disabled');
});

function confirmDestoyApplicant(event, url) {
$('.btn-confirmation').prop('disabled', true);
event.preventDefault();
event.stopImmediatePropagation();
//
$('.modal-backdrop').removeClass('modal-backdrop');
$('.modal-open').removeClass('modal-open');

$.ajax({
url: url,
type: 'DELETE',
dataType: 'script',
contentType: false,
processData: false,
});
}

$(document).off('click', '#confirm_member');
$(document).on('click', '#confirm_member', function (e) {
if ($('input#applicant_same_with_primary').length) {
if ($('input#applicant_same_with_primary').is(':checked')) {
$(
'#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required'
).removeAttr('required');
} else {
$(
'#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required'
).attr('required', true);
}

$('.btn-confirmation').removeAttr('disabled');
}
$(this).addClass('disabled').attr('tabindex', -1).blur();
PersonValidations.manageRequiredValidations($('#confirm_member'));

if ($(this).closest('form')[0].checkValidity()) {
$(this).removeClass('disabled').attr('tabindex', 0);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -156,71 +156,13 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary btn-confirmation" onclick='confirmDestoyApplicant(event, "<%=application_applicant_path(@application, @applicant)%>"); return false;'>Confirm</button>
<button type="button" class="btn btn-primary btn-confirmation" id="blarfengar" data-url="<%=application_applicant_path(@application, @applicant)%>">Confirm</button>

</div>
</div>
</div>
</div>

<script>
$(document).ready(function() {
$.inputMasks();
});

$('#applicant_same_with_primary').click(function(){
if($(this).is(':checked')){
$('#applicant-home-address-area').addClass("hidden");
} else {
$('#applicant-home-address-area').removeClass("hidden");
}
});

$(document).on('click', 'button#delete_applicant_button', function(e) {
e.preventDefault();
$("#destroyApplicant").modal();

$("#destroyApplicant .modal-cancel-button").click(function(e) {
$("#destroyApplicant").modal('hidden');
});
$(".btn-confirmation").removeAttr('disabled');
});

function confirmDestoyApplicant(event, url){
$(".btn-confirmation").prop('disabled', true);
event.preventDefault();
event.stopImmediatePropagation();
//
$('.modal-backdrop').removeClass('modal-backdrop');
$('.modal-open').removeClass('modal-open');

$.ajax({
url: url,
type: "DELETE",
dataType: 'script',
contentType: false,
processData: false,
});
}

$(document).off('click', '#confirm_member');
$(document).on('click', '#confirm_member', function(e) {
if ($("input#applicant_same_with_primary").length) {
if($("input#applicant_same_with_primary").is(":checked")){
$("#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required").removeAttr('required');
} else {
$("#applicant-home-address-area input.required, #applicant-home-address-area select.required, #applicant-home-address-area .address_required").attr('required', true);
}

$(".btn-confirmation").removeAttr('disabled');
}
$(this).addClass("disabled").attr('tabindex', -1).blur();
PersonValidations.manageRequiredValidations($('#confirm_member'));

if ($(this).closest('form')[0].checkValidity()) {
$(this).removeClass("disabled").attr('tabindex', 0);
}
});
</script>

<% else %>
<%= form_for @applicant, url: application_applicant_path(@application, @applicant), method: :patch do |f|%>
Expand Down

0 comments on commit 2126812

Please sign in to comment.