Skip to content

Commit

Permalink
Religious form preview (#7333)
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan authored Dec 11, 2024
1 parent 4144574 commit 4109243
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 176 deletions.
6 changes: 1 addition & 5 deletions app/controllers/concerns/publishers/wizardable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def start_date_params(params)
def applying_for_the_job_params(params)
if params[:publishers_job_listing_applying_for_the_job_form]
params.require(:publishers_job_listing_applying_for_the_job_form)
.permit(:enable_job_applications)
.permit(:application_form_type)
else
{}
end.merge(completed_steps: completed_steps, current_organisation: current_organisation)
Expand All @@ -104,10 +104,6 @@ def application_link_params(params)
.merge(completed_steps: completed_steps, current_organisation: current_organisation)
end

def religious_information_params(params)
params.require(:publishers_job_listing_religious_information_form).permit(:religion_type)
end

def school_visits_params(params)
if params[:publishers_job_listing_school_visits_form]
params.require(:publishers_job_listing_school_visits_form)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/publishers/vacancies/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Publishers::Vacancies::BuildController < Publishers::Vacancies::BaseContro
include OrganisationsHelper

steps :job_location, :job_title, :job_role, :education_phases, :key_stages, :subjects, :contract_type, :working_patterns,
:pay_package, :important_dates, :start_date, :applying_for_the_job, :how_to_receive_applications, :application_link, :religious_information,
:pay_package, :important_dates, :start_date, :applying_for_the_job, :how_to_receive_applications, :application_link,
:application_form, :school_visits, :visa_sponsorship, :contact_details, :about_the_role, :include_additional_documents, :documents

helper_method :form
Expand Down Expand Up @@ -43,7 +43,7 @@ def form_class
def form_attributes
case action_name
when "show"
vacancy.slice(*form_class.fields)
form_class.load_form(vacancy)
when "update"
form_params
end
Expand Down
7 changes: 3 additions & 4 deletions app/form_models/form_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ def not_validatable_steps
end

def validate_step(step_name)
step_form = File.join(@form_prefix, "#{step_name}_form").camelize.constantize
step_form_class = File.join(@form_prefix, "#{step_name}_form").camelize.constantize

params = @model
.slice(*step_form.fields)
params = step_form_class.load_form(@model)
.merge(current_organisation: @organisation)

step_form.new(params, @model).tap do |form|
step_form_class.new(params, @model).tap do |form|
form.valid?
@model.errors.merge!(
form.errors.tap do |errors|
Expand Down
36 changes: 25 additions & 11 deletions app/form_models/publishers/job_listing/applying_for_the_job_form.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
class Publishers::JobListing::ApplyingForTheJobForm < Publishers::JobListing::VacancyForm
before_validation :override_enable_job_applications!

validates :enable_job_applications, inclusion: { in: [true, false, "true", "false"] }
validates :application_form_type, presence: true

def self.fields
%i[enable_job_applications]
%i[application_form_type]
end
attr_accessor(*fields)

private
class << self
def load_form(model)
if model.enable_job_applications
{ application_form_type: model.religion_type || "no_religion" }
elsif model.enable_job_applications == false
{ application_form_type: "other" }
else
{}
end
end
end

def override_enable_job_applications!
# If a Publisher publishes a vacancy for a job role that does not allow enabling job applications
# but then changes the job role to one that does, enable_job_applications is nil, meaning the validation
# for this field does not pass. We want the validations for the enable_job_applications field to pass
# to prevent an error from being displayed on the review page in this situation when validate_all_steps is run.
self.enable_job_applications = false if vacancy&.listed? && enable_job_applications.blank?
def params_to_save
if application_form_type == "other"
{
religion_type: nil,
enable_job_applications: false,
}
else
{
religion_type: application_form_type,
enable_job_applications: true,
}
end
end
end
6 changes: 6 additions & 0 deletions app/form_models/publishers/job_listing/vacancy_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ def initialize(params = {}, vacancy = nil, current_publisher = nil)
def params_to_save
params.except(:current_organisation)
end

class << self
def load_form(model)
model.slice(*fields)
end
end
end
4 changes: 0 additions & 4 deletions app/helpers/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ module FormsHelper
def render_divs_for_fields(form_model)
safe_join(form_model.fields.map { |field| tag.div(id: field) })
end

def retrieve_fields_from_forms(form_models)
form_models.map(&:fields).flatten
end
end
37 changes: 33 additions & 4 deletions app/helpers/job_applications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,42 @@ def radio_button_legend_hint
end
end

def job_application_sample(vacancy)
JobApplication.new(job_application_attributes.merge(vacancy: vacancy))
end

def religious_job_application_sample(vacancy)
JobApplication.new(job_application_attributes.merge(
following_religion: true,
faith: "Anglican",
religious_reference_type: "referee",
religious_referee_name: Faker::Name.name,
religious_referee_address: Faker::Address.full_address,
ethos_and_aims: Faker::Lorem.paragraph(sentence_count: 2),
religious_referee_role: "Priest",
religious_referee_email: Faker::Internet.email,
religious_referee_phone: Faker::PhoneNumber.phone_number,
vacancy: vacancy.dup.tap { |v| v.assign_attributes(religion_type: "other_religion") },
))
end

def catholic_job_application_sample(vacancy)
JobApplication.new(job_application_attributes.merge(
following_religion: true,
faith: "Roman Catholic",
religious_reference_type: "baptism_date",
baptism_address: Faker::Address.full_address,
baptism_date: Faker::Date.between(from: Date.new(1990, 1, 1), to: Date.new(2004, 1, 1)),
vacancy: vacancy.dup.tap { |v| v.assign_attributes(religion_type: "catholic") },
))
end

# These are only used to generate example data
POSSIBLE_DEGREE_GRADES = %w[2.1 2.2 Honours].freeze
POSSIBLE_OTHER_GRADES = %w[Pass Merit Distinction].freeze

def job_application_sample(vacancy) # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
JobApplication.new(
def job_application_attributes # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
{
first_name: "Jane",
last_name: "Smith",
national_insurance_number: "QQ 12 34 56 C",
Expand Down Expand Up @@ -248,7 +278,6 @@ def job_application_sample(vacancy) # rubocop: disable Metrics/MethodLength, Met
end
end
end,
vacancy: vacancy,
)
}
end
end
8 changes: 5 additions & 3 deletions app/helpers/review_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module ReviewHelper
def section_begun?(model, section, step_process)
fields = retrieve_section_forms(section, step_process).then { retrieve_fields_from_forms(_1) }

model.slice(fields).values.any? { |value| !value.nil? }
retrieve_section_forms(section, step_process)
.map { |form_class| form_class.load_form(model) }
.map(&:values)
.flatten
.any? { |value| !value.nil? }
end

private
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/vacancies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ def humanize_array(items)
items.reject(&:blank?).map(&:humanize).join(", ")
end

def vacancy_form_type(vacancy)
if vacancy.enable_job_applications
case vacancy.religion_type
when "catholic"
t("publishers.vacancies.application_form_type.catholic")
when "other_religion"
t("publishers.vacancies.application_form_type.other_religion")
else
t("publishers.vacancies.application_form_type.no_religion")
end
else
t("publishers.vacancies.application_form_type.other")
end
end

def page_title_prefix(step_process, form_object)
page_heading = t("publishers.vacancies.steps.#{step_process.current_step}")
create_or_edit = step_process.vacancy.published? ? "edit" : "create"
Expand Down
2 changes: 0 additions & 2 deletions app/services/publishers/vacancies/vacancy_step_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def application_process_steps
steps = %i[school_visits visa_sponsorship contact_details]
steps.insert(0, :how_to_receive_applications) unless vacancy.enable_job_applications
steps.insert(1, application_method) if application_method.present?
elsif vacancy.organisations.any?(&:faith_school?) && vacancy.enable_job_applications
steps = %i[applying_for_the_job religious_information school_visits visa_sponsorship contact_details]
else
steps = %i[applying_for_the_job school_visits visa_sponsorship contact_details]
steps.insert(1, :how_to_receive_applications) unless vacancy.enable_job_applications
Expand Down
53 changes: 33 additions & 20 deletions app/views/publishers/vacancies/build/applying_for_the_job.html.slim
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
- content_for :page_title_prefix, page_title_prefix(step_process, form)

.govuk-grid-row
.govuk-grid-column-two-thirds
= form_for form, url: wizard_path(current_step), method: :patch do |f|
= f.govuk_error_summary
= form_for form, url: wizard_path(current_step), method: :patch do |f|
= f.govuk_error_summary

= vacancy_form_page_heading(vacancy, step_process, back_path: back_path, fieldset: false)
= vacancy_form_page_heading(vacancy, step_process, back_path: back_path, fieldset: false)

p.govuk-body = t(".using_application_form_html", link: govuk_link_to(t(".kcsie_guidance"), t(".kcsie_url"), target: "_blank", rel: "noreferrer noopener"))
- if vacancy.listed?
= f.hidden_field :application_form_type, :other
- else
= f.govuk_radio_buttons_fieldset :application_form_type, legend: nil do
p.govuk-body = t(".using_application_form")

p.govuk-body = t(".reason_for_our_form")
p.govuk-body = t(".reason_for_our_form")

= govuk_details(summary_text: "See what an application form looks like") do
= job_application_review(job_application_sample(vacancy), step_process: {}, show_tracks: false, show_sidebar: false, allow_edit: false) do |r|
- render "jobseekers/job_applications/job_application_review_sections", r: r, job_application: r.job_application
= f.govuk_radio_button :application_form_type, :no_religion,
label: -> { t("helpers.label.publishers_job_listing_applying_for_the_job_form.application_form_type_options.no_religion_html", tag: govuk_tag(text: t(".kcsie_compliant"), colour: "green")) },
link_errors: true
= govuk_details(summary_text: t(".preview_online_application_form")) do
= job_application_review(job_application_sample(vacancy), step_process: {}, show_tracks: false, show_sidebar: false, allow_edit: false) do |r|
- render "jobseekers/job_applications/job_application_review_sections", r: r, job_application: r.job_application

- if vacancy.listed?
= f.hidden_field :enable_job_applications
- else
= f.govuk_radio_buttons_fieldset :enable_job_applications, legend: { size: "m", tag: nil } do
= f.govuk_radio_button :enable_job_applications, true,
label: -> { safe_join([t("helpers.label.publishers_job_listing_applying_for_the_job_form.enable_job_applications_options.true"), govuk_tag(text: t(".kcsie_compliant"), colour: "green")]) },
hint: { text: vacancy.organisations.any?(&:faith_school?) ? t(".ask_about_religion") : t(".this_form_is_kept_up_to_date") },
link_errors: true
= f.govuk_radio_divider
= f.govuk_radio_button :enable_job_applications, "false"
- if vacancy.organisations.any?(&:faith_school?)
= f.govuk_radio_button :application_form_type, :other_religion,
label: -> { t("helpers.label.publishers_job_listing_applying_for_the_job_form.application_form_type_options.other_religion_html", tag: govuk_tag(text: t(".kcsie_compliant"), colour: "green")) }

= render "publishers/vacancies/vacancy_form_partials/submit", f: f
= govuk_details(summary_text: t(".preview_religious_application_form")) do
= job_application_review(religious_job_application_sample(vacancy), step_process: {}, show_tracks: false, show_sidebar: false, allow_edit: false) do |r|
- render "jobseekers/job_applications/job_application_review_sections", r: r, job_application: r.job_application

= f.govuk_radio_button :application_form_type, :catholic,
label: -> { t("helpers.label.publishers_job_listing_applying_for_the_job_form.application_form_type_options.catholic_html", tag: govuk_tag(text: t(".kcsie_compliant"), colour: "green")) }
= govuk_details(summary_text: t(".preview_catholic_application_form")) do
= job_application_review(catholic_job_application_sample(vacancy), step_process: {}, show_tracks: false, show_sidebar: false, allow_edit: false) do |r|
- render "jobseekers/job_applications/job_application_review_sections", r: r, job_application: r.job_application

= f.govuk_radio_divider

= f.govuk_radio_button :application_form_type, :other

= render "publishers/vacancies/vacancy_form_partials/submit", f: f

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ h2 class="govuk-heading-m govuk-!-margin-bottom-4"
- row.with_key
= t("jobs.enable_job_applications")
- row.with_value
= vacancy.enable_job_applications ? "Teaching Vacancies" : "Other"
= vacancy_form_type(vacancy)
- unless vacancy.published? || vacancy.legacy_draft?
- row.with_action text: t("buttons.change"),
href: organisation_job_build_path(vacancy.id, :applying_for_the_job, "back_to_#{action_name}": "true"),
Expand Down
2 changes: 2 additions & 0 deletions config/locales/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ en:
cannot_be_changed_once_listed: >-
You cannot change how you want candidates to apply now that your listing is published
inclusion: Select yes if you want candidates to use the application form
application_form_type:
blank: Select the type of application form you wish to use
how_to_receive_applications_errors: &how_to_receive_applications_errors
receive_applications:
inclusion: Select how you want to receive applications
Expand Down
21 changes: 0 additions & 21 deletions config/locales/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@ en:
application_link: For example, https://www.example.com
publishers_job_listing_application_form_form:
application_form: You can only upload a PDF or DOCX file under 10MB
publishers_job_listing_applying_for_the_job_form:
enable_job_applications_options:
"false": You'll need to provide additional details about how to apply.
publishers_job_listing_documents_form:
documents: You can only upload PDF or DOCX files under 10MB
publishers_job_listing_feedback_form:
Expand All @@ -280,9 +277,6 @@ en:
salary_types_options:
full_time: This is what the annual salary would be for someone working full time
part_time: This is the annual amount someone will take home
publishers_job_listing_religious_information_form:
religion_type_options:
catholic: This form has been approved by the Catholic Education Service.
publishers_job_listing_schools_form:
add_school: Add a school to your account
edit_schools_html: "Can't see the school you are looking for? %{link}"
Expand Down Expand Up @@ -749,12 +743,6 @@ en:
application_email_options:
other: Another email address
other_application_email: Email address
publishers_job_listing_applying_for_the_job_form:
quick_apply: Only show quick apply jobs
quick_apply_hint: Apply for jobs quickly using an online application form
enable_job_applications_options:
true: "Teaching Vacancies application form"
false: "Use other application form method"
publishers_job_listing_contract_type_form:
contract_type_options:
fixed_term: Fixed term (including maternity or parental leave cover)
Expand Down Expand Up @@ -908,11 +896,6 @@ en:
part_time: Actual salary
pay_scale: Pay scale
hourly_rate: Hourly rate of pay
publishers_job_listing_religious_information_form:
religion_type_options:
catholic: Their religion, place of worship and religious referee or baptism information
other_religion: If they have a religious denomination or faith, how they'll meet your school's ethos and aims, and if they want to provide an optional religious referee or place of worship
no_religion: Do not ask applicants about their religion
publishers_job_listing_school_visits_form:
school_visits_options:
false: "No"
Expand Down Expand Up @@ -1049,8 +1032,6 @@ en:
ect_status: Is this role suitable for an early career teacher (ECT)?
further_details_provided: Do you want to add further details about the role?
safeguarding_information_provided: Do you want to give information about your commitment to safeguarding?
publishers_job_listing_applying_for_the_job_form:
enable_job_applications: Select application form type
publishers_job_listing_application_form_form:
application_email: Email address to receive applications
publishers_job_listing_contract_type_form:
Expand Down Expand Up @@ -1113,8 +1094,6 @@ en:
publishers_job_listing_pay_package_form:
salary_types: Salary details
benefits: Do you want to include additional allowances?
publishers_job_listing_religious_information_form:
religion_type: What would you like to ask applicants about their religion?
publishers_job_listing_school_visits_form:
school_visits: Do you want to offer school visits?
publishers_job_listing_working_patterns_form:
Expand Down
Loading

0 comments on commit 4109243

Please sign in to comment.