Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

class Form::Page
attr_accessor :id, :header_partial, :description, :questions, :depends_on, :title_text,
:informative_text, :subsection, :hide_subsection_label, :next_unresolved_page_id,
:skip_text, :interruption_screen_question_ids, :submit_text
def initialize(id, hsh, subsection)
@id = id
@subsection = subsection
if hsh
@header = hsh["header"]
@header_partial = hsh["header_partial"]
@description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) }
@depends_on = hsh["depends_on"]
@title_text = hsh["title_text"]
@informative_text = hsh["informative_text"]
@hide_subsection_label = hsh["hide_subsection_label"]
@next_unresolved_page_id = hsh["next_unresolved_page_id"]
@skip_text = hsh["skip_text"]
@submit_text = hsh["submit_text"]
CLDC-2248 Improve soft validations (#1584) * Update interruption screen page * Update routing and add flash * Only display routed to affected questions * Add affected_question_ids to pregnancy check * lint * Add skip link and lint * Move affected_question_ids to page, because we reuse questions so they might have different affected_question_ids * typo * Fix button wording * Update action href links * Change how we route back to interruption screen * Update affected_question_ids for lettings * Update sales soft validations * Update title texts * Update styling * Update is_referrer_interruption_screen? check and naming * Add interuption screen helper specs * Add request test for fixing soft validation * Add tests for geting soft validation page * Extract interruption screen banner * Update action_href to be reusable * Extract questions out of check answers summary list * Reuse check_answers_summary_list for interruption screen * refactor string parse * Rename attribute * fix test * Add tests for sales paths * typo * Update validation message: void date, major repairs date * Update validation message: rent_value_check, 2022 * Update validation message: buyer live in * Update validation message: staircase * Update validation message: purchase price * Update validation message: income * Update validation message: savings * Update validation message: extra borrowing * Update validation message: extra borrowing * Update validation message: wheelchair * Update validation message: monthly charge * Update validation message: mortgage * Update validation message: old persons shared ownership * Update validation message: discount * Update validation: min retirement * Wording in tests and time test * Update missing question * Refactor is referrer methods * Update validation message: net income * Update validation message: deposit and savings * Update validation message: mortgage, discount and deposit * Fix test validation messages * Fix the retirement check showing on the card 8, fix tests * test * return the user back to the check_your_answers after fixing a validation from check_your_anwers * pr comments
2 years ago
@interruption_screen_question_ids = hsh["interruption_screen_question_ids"] || []
end
end
delegate :form, to: :subsection
def copy_key
@copy_key ||= "#{form.type}.#{subsection.copy_key}.#{questions[0].id}"
end
def header
@header ||= I18n.t("forms.#{form.start_date.year}.#{copy_key}.page_header", default: "")
end
def routed_to?(log, _current_user)
return true unless depends_on || subsection.depends_on
subsection.enabled?(log) && form.depends_on_met(depends_on, log)
end
def non_conditional_questions
@non_conditional_questions ||= questions.reject do |q|
conditional_question_ids.include?(q.id)
end
end
def has_unanswered_questions?(log)
questions.any? { |question| question.displayed_to_user?(log) && question.unanswered?(log) }
end
def interruption_screen?
questions.all? { |question| question.type == "interruption_screen" }
end
def skip_href(log = nil); end
private
def conditional_question_ids
@conditional_question_ids ||= questions.flat_map { |q|
next if q.conditional_for.blank?
# TODO: remove this condition once all conditional questions no longer need JS
q.conditional_for.keys if q.type == "radio"
}.compact
end
end