Skip to content

Commit

Permalink
Add support letter checkboxes into the form
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubosky committed Jul 17, 2024
1 parent 8cbf172 commit 52a41bd
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 59 deletions.
27 changes: 12 additions & 15 deletions app/controllers/form/support_letters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
class Form::SupportLettersController < Form::BaseController
include FormAnswerSubmissionMixin

def create
@form_answer.support_letters_attributes = permitted_params["support_letters_attributes"]
@form_answer.document = prepare_doc if params[:form].present?

if @form_answer.valid? && @form_answer.save
add_support_letters_to_document!

unless @form_answer.valid?
if params[:next_step_id]
redirect_to edit_form_url(@form_answer, step: params[:next_step_id])
else
redirect_to form_form_answer_supporters_path(@form_answer)
end
else
@step = @form.steps.detect { |s| s.opts[:id] == :letters_of_support_step }

render "form/supporters/index"
else
if @form_answer.save
add_support_letters_to_document!

if params[:next_step]
redirect_to edit_form_url(@form_answer, step: params[:next_step])
else
redirect_to form_form_answer_supporters_path(@form_answer)
end
else
@step = @form.steps.detect { |s| s.opts[:id] == :letters_of_support_step }

render "form/supporters/index"
end
end
end

Expand Down
7 changes: 2 additions & 5 deletions app/controllers/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,8 @@ def save
redirect_to edit_form_url(@form_answer, step: params[:next_step])
else
params[:step] = @form_answer.steps_with_errors.try(:first)
# avoid redirecting to supporters page
if !params[:step] || params[:step] == "letters-of-support"
params[:step] = @form.steps.first.title_to_param
end

params[:step] ||= @form.steps.first.title_to_param

render template: "qae_form/show"
end
end
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/packs/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ body.js-enabled {
}

.govuk-button {
color: inherit;
margin-bottom: 0 !important;
margin-top: 0 !important;
white-space: nowrap;
}

a.govuk-button {
color: inherit;
}
}

.previous {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
input name="form[#{question.key}][array]" value="true" type="hidden" disabled="disabled"
ul.list-add.supporters-list data-need-to-clear-example=true data-add-limit=question.limit data-attachments-url=(users_form_answer_support_letter_attachments_path(@form_answer)) data-example-has-file-field=true
- question.entities.each_with_index do |supporter, index|
= supporter
= render 'qae_form/supporter_fields', question: question, supporter: supporter, index: index

a.govuk-button.govuk-button--secondary.button-add.js-button-add href="#" disabled="disabled"
| Add another letter of support
45 changes: 20 additions & 25 deletions app/views/form/support_letters/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
= simple_form_for [:form, @form_answer], url: [:form, @form_answer, :support_letters], method: :post, data: { turbo: false }, html: { class: 'qae-form' } do |f|
= text_field_tag :next_step, @step.next.title_to_param, type: :hidden

ul.list-add.supporters-list
= f.simple_fields_for :support_letters do |ff|
- idx = ff.options[:child_index] + 1
li
.govuk-grid-row
.govuk-grid-column-one-half
label[class="govuk-label"]
span[class="govuk-body govuk-!-font-size-20 govuk-!-font-weight-bold govuk-!-display-block"]
= "Letter of Support #{idx}"
= ff.input :first_name, label: "First Name:", input_html: { class: "form-control" }
= ff.input :last_name, label: "Surname:", input_html: { class: "form-control" }
= ff.input :relationship_to_nominee, label: "Relationship to Group:", input_html: { class: "form-control" }
= f.simple_fields_for :support_letters do |ff|
- idx = ff.options[:child_index] + 1
li
.govuk-grid-row
.govuk-grid-column-one-half
label[class="govuk-label"]
span[class="govuk-body govuk-!-font-size-20 govuk-!-font-weight-bold govuk-!-display-block"]
= "Letter of Support #{idx}"
= ff.input :first_name, label: "First Name:", input_html: { class: "form-control" }
= ff.input :last_name, label: "Surname:", input_html: { class: "form-control" }
= ff.input :relationship_to_nominee, label: "Relationship to Group:", input_html: { class: "form-control" }

= ff.input :manual, as: :hidden, input_html: { value: true }
= ff.input :user_id, as: :hidden, input_html: { value: current_user.id }
= ff.input :manual, as: :hidden, input_html: { value: true }
= ff.input :user_id, as: :hidden, input_html: { value: current_user.id }

= ff.simple_fields_for :support_letter_attachment, (ff.object.support_letter_attachment || ff.object.build_support_letter_attachment) do |fff|
= fff.input :attachment, as: :file, label: "Upload Letter of Support #{idx}", input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" }
p.govuk-body.support-letter-attachment-filename
= render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment
= ff.simple_fields_for :support_letter_attachment, (ff.object.support_letter_attachment || ff.object.build_support_letter_attachment) do |fff|
= fff.input :attachment, as: :file, label: "Upload Letter of Support #{idx}", input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" }
p.govuk-body.support-letter-attachment-filename
= render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment

= fff.input :attachment_cache, as: :hidden
= fff.input :attachment_cache, as: :hidden

= fff.input :form_answer_id, as: :hidden, input_html: { value: @form_answer.id }
= fff.input :user_id, as: :hidden, input_html: { value: current_user.id }
= fff.input :form_answer_id, as: :hidden, input_html: { value: @form_answer.id }
= fff.input :user_id, as: :hidden, input_html: { value: current_user.id }

= render partial: "form/support_letters/footer", locals: { f: f, step: @step }
14 changes: 13 additions & 1 deletion app/views/form/supporters/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ h1.govuk-heading-xl
article.group role="article"
div
- letters_intro_question = @step.questions.detect { |q| q.key == :supporter_letters_list }
- checkbox_questions = @step.questions.select { |q| q.key.in?(%i(independent_individual not_nominator)) }

.question-block
label.govuk-label
Expand All @@ -36,6 +37,17 @@ h1.govuk-heading-xl
.govuk-details__text
== help.text

= render partial: "form/support_letters/form"
= simple_form_for [:form, @form_answer], url: [:form, @form_answer, :support_letters], method: :post, data: { turbo: false }, html: { class: 'qae-form' } do |f|
= hidden_field_tag :current_step_id, @step.title_to_param
= hidden_field_tag :next_step_id, @step.next.title_to_param

ul.list-add.supporters-list
= render partial: "form/support_letters/form", locals: { f: f }

- checkbox_questions.each do |question|
.govuk-form-group
= render partial: "qae_form/confirm_question", locals: { question: question }

= render partial: "form/support_letters/footer", locals: { f: f, step: @step }

= render "qae_form/steps_progress_bar", current_step: "letters-of-support"
12 changes: 8 additions & 4 deletions app/views/qae_form/_supporter_fields.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
- create_url = users_form_answer_support_letters_url(@form_answer)
- update_url = users_form_answer_support_letter_path(@form_answer, supporter["support_letter_id"]) if persisted
li[class=class_names("js-add-example", "js-support-letter-received" => persisted) data-create-url=create_url data-update-url=update_url]
label[class="govuk-label"]
span[class="govuk-body govuk-!-font-size-20 govuk-!-font-weight-bold govuk-!-display-block"]
= "Letter of Support #{index + 1}"

input.js-support-entry-id type="hidden" name="form[#{question.key}][#{index}][support_letter_id]" value=supporter["support_letter_id"] *possible_read_only_ops(question.step.opts[:id])
.js-system-tag data-new-hidden-input-name="form[#{question.key}][#{index}][support_letter_id]"

.govuk-form-group
label.govuk-label for="form[#{question.key}][#{index}][first_name]"
' First Name
' First Name:
span.govuk-error-message
input.js-support-letter-field.js-support-letter-first-name.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][#{index}][first_name]" id="form[#{question.key}][#{index}][first_name]" type="text" value=supporter["first_name"] *possible_read_only_ops(question.step.opts[:id])

.govuk-form-group
label.govuk-label for="form[#{question.key}][#{index}][last_name]"
' Surname
' Surname:
span.govuk-error-message
input.js-support-letter-field.js-support-letter-last-name.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][#{index}][last_name]" id="form[#{question.key}][#{index}][last_name]" type="text" value=supporter["last_name"] *possible_read_only_ops(question.step.opts[:id])

.govuk-form-group
label.govuk-label for="form[#{question.key}][#{index}][relationship_to_nominee]"
' Relationship to Nominee
' Relationship to Group:
span.govuk-error-message
input.js-support-letter-field.js-support-letter-relationship-to-nominee.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][#{index}][relationship_to_nominee]" id="form[#{question.key}][#{index}][relationship_to_nominee]" type="text" value=supporter["relationship_to_nominee"] *possible_read_only_ops(question.step.opts[:id])

.govuk-form-group
label.govuk-label for="form[#{question.key}][#{index}][letter_of_support]"
' Letter of Support
= "Upload Letter of Support #{index + 1}"
span.govuk-error-message

input class="js-support-letter-field js-trigger-autosave js-support-letter-attachment govuk-input medium" name="form[#{question.key}][#{index}][letter_of_support]" id="form[#{question.key}][#{index}][letter_of_support]" type='file' *possible_read_only_ops(question.step.opts[:id])
Expand Down
12 changes: 8 additions & 4 deletions app/views/qae_form/_supporter_fields_placeholder.html.slim
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
li.js-add-example class="govuk-!-display-none"
label[class="govuk-label"]
span[class="govuk-body govuk-!-font-size-20 govuk-!-font-weight-bold govuk-!-display-block"]
= "Letter of Support #{index + 1}"

input.js-support-entry-id type="hidden" name="form[#{question.key}][{index}][support_letter_id]" disabled=true
.js-system-tag data-new-hidden-input-name="form[#{question.key}][{index}][support_letter_id]"
.govuk-form-group
label.govuk-label for="form[#{question.key}][{index}][first_name]"
' First Name
' First Name:
span.govuk-error-message
input.js-support-letter-first-name.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][{index}][first_name]" id="form[#{question.key}][{index}][first_name]" type="text" disabled=true
p.govuk-body.visible-read-only

.govuk-form-group
label.govuk-label for="form[#{question.key}][{index}][last_name]"
' Surname
' Surname:
span.govuk-error-message
input.js-support-letter-last-name.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][{index}][last_name]" id="form[#{question.key}][{index}][last_name]" type="text" disabled=true
p.govuk-body.visible-read-only

.govuk-form-group
label.govuk-label for="form[#{question.key}][{index}][relationship_to_nominee]"
' Relationship to Nominee
' Relationship to Group:
span.govuk-error-message
input.js-support-letter-relationship-to-nominee.js-trigger-autosave.govuk-input autocomplete="off" class="js-trigger-autosave medium" name="form[#{question.key}][{index}][relationship_to_nominee]" id="form[#{question.key}][{index}][relationship_to_nominee]" type="text" disabled=true
p.govuk-body.visible-read-only

.govuk-form-group
label.govuk-label for="form[#{question.key}][{index}][letter_of_support]"
' Letter of Support
= "Upload Letter of Support #{index + 1}"
span.govuk-error-message
input class="js-trigger-autosave js-support-letter-attachment govuk-input medium" name="form[#{question.key}][{index}][letter_of_support]" id="form[#{question.key}][{index}][letter_of_support]" type='file' disabled=true

Expand Down
18 changes: 18 additions & 0 deletions forms/award_years/v2025/qavs/qavs_step3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ def qavs_step3
limit 2
default 2
end

confirm :independent_individual, "" do
required
text -> do
%(
I can confirm that these letters were written by individuals independent of the group.
)
end
end

confirm :not_nominator, "" do
required
text -> do
%(
I can confirm that these letters were not written by the nominator.
)
end
end
end
end
end
Expand Down

0 comments on commit 52a41bd

Please sign in to comment.