From 52a41bd5dd4fbff78f8d0c2503d06a88a170134a Mon Sep 17 00:00:00 2001 From: Lubos Hricak Date: Wed, 17 Jul 2024 15:34:02 +0200 Subject: [PATCH] Add support letter checkboxes into the form --- .../form/support_letters_controller.rb | 27 +++++------ app/controllers/form_controller.rb | 7 +-- app/javascript/packs/application.scss | 5 ++- .../questions/_supporters_question.html.slim | 4 -- .../form/support_letters/_form.html.slim | 45 +++++++++---------- app/views/form/supporters/index.html.slim | 14 +++++- .../qae_form/_supporter_fields.html.slim | 12 +++-- .../_supporter_fields_placeholder.html.slim | 12 +++-- forms/award_years/v2025/qavs/qavs_step3.rb | 18 ++++++++ 9 files changed, 85 insertions(+), 59 deletions(-) diff --git a/app/controllers/form/support_letters_controller.rb b/app/controllers/form/support_letters_controller.rb index 19e0f7dbc..fa581277a 100644 --- a/app/controllers/form/support_letters_controller.rb +++ b/app/controllers/form/support_letters_controller.rb @@ -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 diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 2316934c9..d9f16781f 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -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 diff --git a/app/javascript/packs/application.scss b/app/javascript/packs/application.scss index 9f3c03a8a..aef597acd 100644 --- a/app/javascript/packs/application.scss +++ b/app/javascript/packs/application.scss @@ -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 { diff --git a/app/views/assessor/form_answers/questions/_supporters_question.html.slim b/app/views/assessor/form_answers/questions/_supporters_question.html.slim index f8097888e..916785e16 100644 --- a/app/views/assessor/form_answers/questions/_supporters_question.html.slim +++ b/app/views/assessor/form_answers/questions/_supporters_question.html.slim @@ -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 diff --git a/app/views/form/support_letters/_form.html.slim b/app/views/form/support_letters/_form.html.slim index d16169c16..6e0f6eae1 100644 --- a/app/views/form/support_letters/_form.html.slim +++ b/app/views/form/support_letters/_form.html.slim @@ -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 } diff --git a/app/views/form/supporters/index.html.slim b/app/views/form/supporters/index.html.slim index 0d632d0ae..ad955ba7c 100644 --- a/app/views/form/supporters/index.html.slim +++ b/app/views/form/supporters/index.html.slim @@ -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 @@ -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" diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index b7819c025..aee0fad3b 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -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]) diff --git a/app/views/qae_form/_supporter_fields_placeholder.html.slim b/app/views/qae_form/_supporter_fields_placeholder.html.slim index b95578a8b..1eb001785 100644 --- a/app/views/qae_form/_supporter_fields_placeholder.html.slim +++ b/app/views/qae_form/_supporter_fields_placeholder.html.slim @@ -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 diff --git a/forms/award_years/v2025/qavs/qavs_step3.rb b/forms/award_years/v2025/qavs/qavs_step3.rb index 17dd3dfb3..f0308e6be 100644 --- a/forms/award_years/v2025/qavs/qavs_step3.rb +++ b/forms/award_years/v2025/qavs/qavs_step3.rb @@ -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