diff --git a/app/assets/javascripts/components/subjects_taught.js b/app/assets/javascripts/components/subjects_taught.js deleted file mode 100644 index 26b66d23f2..0000000000 --- a/app/assets/javascripts/components/subjects_taught.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; - -document.addEventListener("DOMContentLoaded", function () { - var fieldset = document.querySelector("#claim_subjects_taught"); - - if (!fieldset) { - return; - } - - function toggleSubjectValues(event) { - var el = event.target; - var eligibleSubjectsClass = "subject"; - var notTeachingSubjectsName = "claim[eligibility_attributes][taught_eligible_subjects]"; - - if (!el) { - return; - } - - if (el.checked === false) { - return; - } - - if (el.classList.contains(eligibleSubjectsClass)) { - var radioButton = document.querySelector("input[type='radio'][name='" + notTeachingSubjectsName + "']"); - radioButton.checked = false; - } else if (el.name == notTeachingSubjectsName) { - var checkboxes = document.querySelectorAll("input." + eligibleSubjectsClass); - checkboxes.forEach(function (item, _index) { - item.checked = false; - }); - } - } - - fieldset.addEventListener("click", toggleSubjectValues, false); -}); diff --git a/app/controllers/claims_controller.rb b/app/controllers/claims_controller.rb index c3623548c2..b1c60110a7 100644 --- a/app/controllers/claims_controller.rb +++ b/app/controllers/claims_controller.rb @@ -39,8 +39,6 @@ def show if params[:slug] == "select-claim-school" update_session_with_tps_school(current_claim.tps_school_for_student_loan_in_previous_financial_year) - elsif params[:slug] == "subjects-taught" && page_sequence.in_sequence?("select-claim-school") - @backlink_path = claim_path(current_journey_routing_name, "select-claim-school") elsif params[:slug] == "postcode-search" && postcode redirect_to claim_path(current_journey_routing_name, "select-home-address", {"claim[postcode]": params[:claim][:postcode], "claim[address_line_1]": params[:claim][:address_line_1]}) and return unless invalid_postcode? elsif params[:slug] == "select-home-address" && postcode diff --git a/app/forms/journeys/teacher_student_loan_reimbursement/subjects_taught_form.rb b/app/forms/journeys/teacher_student_loan_reimbursement/subjects_taught_form.rb new file mode 100644 index 0000000000..4288e110cb --- /dev/null +++ b/app/forms/journeys/teacher_student_loan_reimbursement/subjects_taught_form.rb @@ -0,0 +1,73 @@ +module Journeys + module TeacherStudentLoanReimbursement + class SubjectsTaughtForm < Form + attr_accessor :subjects_taught + + attribute :taught_eligible_subjects, :boolean + attribute :biology_taught, :boolean + attribute :chemistry_taught, :boolean + attribute :physics_taught, :boolean + attribute :computing_taught, :boolean + attribute :languages_taught, :boolean + + validate :one_subject_must_be_selected + + before_validation :determine_dependant_attributes + + def save + return false unless valid? + + update!(eligibility_attributes: attributes) + end + + def claim_school_name + @claim_school_name ||= claim.eligibility.claim_school_name + end + + def subject_attributes + Policies::StudentLoans::Eligibility::SUBJECT_ATTRIBUTES + end + + def subject_taught_selected?(subject) + public_send(subject) == true if respond_to?(subject) + end + + private + + def determine_dependant_attributes + subject_attributes.each(&method(:update_subject_taught_attribute)) + assign_attributes(taught_eligible_subjects: selected_subjects.empty? ? nil : !no_subject_taught_selected?) + end + + def update_subject_taught_attribute(subject) + assign_attributes(subject => subject.to_s.in?(selected_subjects)) + end + + def no_subject_taught_selected? + "none_taught".in?(selected_subjects) + end + + def selected_subjects + permitted_params.fetch(:subjects_taught, []) + end + + def permitted_params + @permitted_params ||= params.fetch(:claim, {}).permit(subjects_taught: []) + end + + def any_subjects_taught_selected? + subject_attributes.any?(&method(:subject_taught_selected?)) + end + + def not_taught_eligible_subjects? + taught_eligible_subjects == false + end + + def one_subject_must_be_selected + return if not_taught_eligible_subjects? || any_subjects_taught_selected? + + errors.add(:subjects_taught, i18n_errors_path(:select_subject)) + end + end + end +end diff --git a/app/helpers/student_loans_helper.rb b/app/helpers/student_loans_helper.rb index 06a2886c31..9dd013afb5 100644 --- a/app/helpers/student_loans_helper.rb +++ b/app/helpers/student_loans_helper.rb @@ -20,7 +20,7 @@ def claim_school_question(additional_school: false) # Accepts a `school_name` named parameter that is the school that the claimant # was teaching at during the financial year. def subjects_taught_question(school_name:) - translate("student_loans.questions.subjects_taught", school: school_name, financial_year: Policies::StudentLoans.current_financial_year) + translate("student_loans.forms.subjects_taught.questions.subjects_taught", school: school_name, financial_year: Policies::StudentLoans.current_financial_year) end # Returns the question for the leadership-position question in the Student diff --git a/app/models/journeys/teacher_student_loan_reimbursement.rb b/app/models/journeys/teacher_student_loan_reimbursement.rb index df85b9f69d..7c0ab9537c 100644 --- a/app/models/journeys/teacher_student_loan_reimbursement.rb +++ b/app/models/journeys/teacher_student_loan_reimbursement.rb @@ -14,6 +14,7 @@ module TeacherStudentLoanReimbursement "claim-school" => ClaimSchoolForm, "qualification-details" => QualificationDetailsForm, "qts-year" => QtsYearForm, + "subjects-taught" => SubjectsTaughtForm, "leadership-position" => LeadershipPositionForm, "mostly-performed-leadership-duties" => MostlyPerformedLeadershipDutiesForm } diff --git a/app/models/policies/student_loans/eligibility.rb b/app/models/policies/student_loans/eligibility.rb index 3a4d3ead60..9b9de515d2 100644 --- a/app/models/policies/student_loans/eligibility.rb +++ b/app/models/policies/student_loans/eligibility.rb @@ -50,7 +50,6 @@ class Eligibility < ApplicationRecord validates :claim_school, on: [:"select-claim-school"], presence: {message: ->(object, _data) { object.select_claim_school_presence_error_message }}, unless: :claim_school_somewhere_else? validates :employment_status, on: [:"still-teaching", :submit], presence: {message: ->(object, _data) { "Select if you still work at #{object.claim_school_name}, another school or no longer teach in England" }} - validate :one_subject_must_be_selected, on: [:"subjects-taught", :submit], unless: :not_taught_eligible_subjects? validates :had_leadership_position, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you were employed in a leadership position"} validates :mostly_performed_leadership_duties, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you spent more than half your working hours on leadership duties"}, if: :had_leadership_position? validates_numericality_of :student_loan_repayment_amount, message: "Enter a valid monetary amount", allow_nil: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 99999 @@ -136,10 +135,6 @@ def made_zero_repayments? claim.present? && claim.has_student_loan == true && student_loan_repayment_amount == 0 end - def one_subject_must_be_selected - errors.add(:subjects_taught, "Select if you taught Biology, Chemistry, Physics, Computing, Languages or you did not teach any of these subjects") if subjects_taught.empty? - end - def ineligible_current_school? current_school.present? && !current_school.eligible_for_student_loans_as_current_school? end diff --git a/app/models/policies/student_loans/presenter_methods.rb b/app/models/policies/student_loans/presenter_methods.rb index a39dfeadb8..cdb30564c7 100644 --- a/app/models/policies/student_loans/presenter_methods.rb +++ b/app/models/policies/student_loans/presenter_methods.rb @@ -12,7 +12,7 @@ def qts_award_year_answer(eligibility) def subject_list(subjects) connector = " and " - translated_subjects = subjects.map { |subject| I18n.t("student_loans.questions.eligible_subjects.#{subject}") } + translated_subjects = subjects.map { |subject| I18n.t("student_loans.forms.subjects_taught.answers.#{subject}") } translated_subjects.sort.to_sentence( last_word_connector: connector, two_words_connector: connector diff --git a/app/views/additional_payments/claims/disciplinary_action.html.erb b/app/views/additional_payments/claims/disciplinary_action.html.erb deleted file mode 100644 index cffd43e217..0000000000 --- a/app/views/additional_payments/claims/disciplinary_action.html.erb +++ /dev/null @@ -1,46 +0,0 @@ -<% content_for(:page_title, page_title(t("additional_payments.questions.disciplinary_action"), journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %> -<% path_for_form = current_claim.persisted? ? claim_path(current_journey_routing_name) : claims_path(current_journey_routing_name) %> - -