From 410a09736adf6154f3e533b12e6d3318403a7fab Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Thu, 22 Aug 2024 08:43:15 +0100 Subject: [PATCH 1/6] Modify support letter fields so each upload section is a new question --- app/assets/stylesheets/frontend/forms.scss | 5 ++ .../frontend/views/award_form.scss | 6 ++ app/views/qae_form/_question_ref.html.slim | 86 +++++++++++++++++++ .../qae_form/_supporter_fields.html.slim | 33 +++++-- .../qae_form/_supporters_question.html.slim | 1 - ...tachment_with_virus_check_status.html.slim | 2 +- .../support_letters/_attachment.html.slim | 8 +- forms/award_years/v2025/qavs/qavs_step3.rb | 37 ++++---- 8 files changed, 147 insertions(+), 31 deletions(-) create mode 100644 app/views/qae_form/_question_ref.html.slim diff --git a/app/assets/stylesheets/frontend/forms.scss b/app/assets/stylesheets/frontend/forms.scss index d17d03335..46a4363a9 100644 --- a/app/assets/stylesheets/frontend/forms.scss +++ b/app/assets/stylesheets/frontend/forms.scss @@ -660,6 +660,11 @@ input[type="file"] { padding: 20px !important; border: 2px solid #000 !important; + &.borderless { + border: 0 !important; + padding: 0 !important; + } + .lte-ie7 & { display: inline; width: 100%; diff --git a/app/assets/stylesheets/frontend/views/award_form.scss b/app/assets/stylesheets/frontend/views/award_form.scss index 0b32cc711..97163db5f 100644 --- a/app/assets/stylesheets/frontend/views/award_form.scss +++ b/app/assets/stylesheets/frontend/views/award_form.scss @@ -162,6 +162,12 @@ label > .visible-read-only, display: block; } +.support-letter-attachment-container { + padding: 15px; + display: flex; + background: $govuk-light-grey; +} + .view-only, .read-only { label { diff --git a/app/views/qae_form/_question_ref.html.slim b/app/views/qae_form/_question_ref.html.slim new file mode 100644 index 000000000..d916491bc --- /dev/null +++ b/app/views/qae_form/_question_ref.html.slim @@ -0,0 +1,86 @@ +- if question.header + h2.govuk-heading-l + = question.header +- if question.header_context + == question.header_context +fieldset class=question.fieldset_classes data=question.fieldset_data_hash + = condition_divs question do + .govuk-form-group class=(" govuk-form-group--error" if @form_answer.validator_errors && @form_answer.validator_errors[question.hash_key]) + - ref = question.ref ? question.ref : question.sub_ref + - if question.title != "" || question.show_ref_always.present? + - if question.label_as_legend? + legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" + - if question.ref || question.sub_ref + span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" + span.todo + = ref.to_s + - unless question.title.blank? + - font_size = question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) ? "govuk-!-font-size-36" : "govuk-!-font-size-24" + span class="govuk-body #{ font_size } govuk-!-font-weight-bold govuk-!-display-block" + == question.title + + = render "qae_form/question_sub_title", question: question + + - else + legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" + label.govuk-label for="q_#{question.key}" id="q_#{question.key}_label" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" + - if question.ref || question.sub_ref + span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" + span.todo + = ref.to_s + - unless question.title.blank? + span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" + == question.title + + = render "qae_form/question_sub_title", question: question + + - else + - if question.ref || question.sub_ref + .if-js-hide + label.govuk-label for="q_#{question.key}" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" + span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" + span.visuallyhidden + = ref.to_s + span.todo + = ref.to_s + + - if question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) + - if question.ref || question.sub_ref + span.question-context.question-debug.govuk-hint + = "Please note #{(question.ref || question.sub_ref).delete(" ")} is just a heading for the following sub-questions." + - if question.context + == question.context + - for help in question.help + == help.text + - else + - if question.context + span.question-context.question-debug.govuk-hint + == question.context + - if question.online_context + span.question-context.question-debug.govuk-hint + == question.online_context + - for help in question.help + span.question-context.question-debug.govuk-hint + == help.text + + - question.hint.each_with_index do |help, index| + details.govuk-details data-module='govuk-details' + - if help.title.present? + summary.govuk-details__summary + span.govuk-details__summary-text + = help.title.html_safe + .govuk-details__text + == help.text + + span.govuk-error-message + - if @form_answer.validator_errors && @form_answer.validator_errors[question.hash_key].present? && @form_answer.validator_errors[question.hash_key].is_a?(String) + span.govuk-visually-hidden + | Error: + =< @form_answer.validator_errors[question.hash_key] + - unless question.form_hint.blank? + span.govuk-hint = question.form_hint + = render partial: "qae_form/#{question.delegate_obj.class.name.demodulize.underscore}", object: question, as: 'question', locals: {answers: answers, attachments: attachments} + + / Conditional hints + - if question.can_have_conditional_hints? + = render "qae_form/conditional_hints/list", question: question diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index aee0fad3b..15fab752f 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -1,37 +1,54 @@ +- first_or_second = index == 0 ? "first" : "second" - persisted = supporter["support_letter_id"].present? || supporter["supporter_id"].present? - 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] +li.borderless[class=class_names("js-add-example", "js-support-letter-received" => persisted) data-create-url=create_url data-update-url=update_url] + legend.govuk-label + span class="steps" + span.todo C #{index + 1} label[class="govuk-label"] - span[class="govuk-body govuk-!-font-size-20 govuk-!-font-weight-bold govuk-!-display-block"] - = "Letter of Support #{index + 1}" + span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"] + = "The #{first_or_second} letter of support" 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]" + legend.govuk-label aria-label="C #{index + 1}.1: Name" + span class="steps" + span.todo C #{index + 1}.1 + span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" + ' Name of the person who wrote the #{first_or_second} letter of support .govuk-form-group label.govuk-label for="form[#{question.key}][#{index}][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: 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]) + legend.govuk-label aria-label="C #{index + 1}.2: Relationship to Group" + span class="steps" + span.todo C #{index + 1}.2 .govuk-form-group - label.govuk-label for="form[#{question.key}][#{index}][relationship_to_nominee]" - ' Relationship to Group: + label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][relationship_to_nominee]" + ' The person's who wrote the #{first_or_second} letter of support relationship to the group + span.question-context.question-debug.govuk-hint + ' For example, a beneficiary of the group, local resident or member of a partner charity. 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]) + legend.govuk-label aria-label="C #{index + 1}.3: Relationship to Group" + span class="steps" + span.todo C #{index + 1}.3 .govuk-form-group label.govuk-label for="form[#{question.key}][#{index}][letter_of_support]" - = "Upload Letter of Support #{index + 1}" + ' Upload the #{first_or_second} letter of support + span.question-context.question-debug.govuk-hint + ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will appear, allowing you to select the correct file. 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]) - if supporter['letter_of_support'].present? = render "support_letters/attachment", question: question, index: index, attachment_id: supporter['letter_of_support'] diff --git a/app/views/qae_form/_supporters_question.html.slim b/app/views/qae_form/_supporters_question.html.slim index 81ae6406f..95abd4c3a 100644 --- a/app/views/qae_form/_supporters_question.html.slim +++ b/app/views/qae_form/_supporters_question.html.slim @@ -2,4 +2,3 @@ input name="form[#{question.key}][array]" value="true" type="hidden" *possible_r 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| = render 'qae_form/supporter_fields', question: question, supporter: supporter, index: index - diff --git a/app/views/shared/_attachment_with_virus_check_status.html.slim b/app/views/shared/_attachment_with_virus_check_status.html.slim index bef7d0bb7..18420519e 100644 --- a/app/views/shared/_attachment_with_virus_check_status.html.slim +++ b/app/views/shared/_attachment_with_virus_check_status.html.slim @@ -7,7 +7,7 @@ class: 'govuk-link' - elsif scan_results == "scanning" || scan_results == "pending" = item.try(:original_filename) - | (scanning on viruses) + | (File uploaded and is being scanned for viruses. Preview available once the scan is complete.) - elsif scan_results == "infected" = item.try(:original_filename) | has been blocked (virus detected), please remove. diff --git a/app/views/support_letters/_attachment.html.slim b/app/views/support_letters/_attachment.html.slim index 611b93a17..3c2b1dead 100644 --- a/app/views/support_letters/_attachment.html.slim +++ b/app/views/support_letters/_attachment.html.slim @@ -1,5 +1,9 @@ - file = support_letter_attachments[attachment_id.to_i] -p.govuk-body.support-letter-attachment-filename - = render "shared/attachment_with_virus_check_status", item: file, mount_name: :attachment +.support-letter-attachment-container + div + p.govuk-body.support-letter-attachment-filename + = render "shared/attachment_with_virus_check_status", item: file, mount_name: :attachment + button.govuk-link.govuk-button--secondary data-module="govuk-button" type="button" onclick="removeAttachment(this)" + | Remove input.js-support-letter-attachment-id type="hidden" name="form[#{question.key}][#{index}][letter_of_support]" value=attachment_id *possible_read_only_ops diff --git a/forms/award_years/v2025/qavs/qavs_step3.rb b/forms/award_years/v2025/qavs/qavs_step3.rb index d8b99639f..da935217f 100644 --- a/forms/award_years/v2025/qavs/qavs_step3.rb +++ b/forms/award_years/v2025/qavs/qavs_step3.rb @@ -6,36 +6,35 @@ def qavs_step3

Please note your answers are being saved automatically in the background.

) - supporters :supporter_letters_list, "" do - ref "C 1" - context %( + header :supporter_letters_list_key_criteria, "" do + help "About this section", %(

Letters of support are an essential part of your nomination, as they help to clarify and explain the impact of the nominated group's work in the local community. You will need to provide 2 letters of support alongside your nomination.

For more information on what letters can cover, please see the Letters of Support page on our website.

-

Key criteria:

+

Key criteria:

    -
  1. letters must be written by individuals who are familiar with the group's work, for example: a beneficiary, local resident or member of a partner charity
  2. -
  3. letters must not be written by a volunteer, employee, trustee, or anyone involved in the running of the group
  4. -
  5. letters written by the nominator will be ineligible
  6. -
  7. each letter should be no more than 500 words
  8. -
  9. only 2 letters of support can be submitted
  10. +
  11. Letters must be written by individuals who are familiar with the group's work, for example: a beneficiary, local resident or member of a partner charity.
  12. +
  13. Letters must not be written by a volunteer, employee, trustee, or anyone involved in the running of the group.
  14. +
  15. Letters written by the nominator will be ineligible.
  16. +
  17. Each letter should be no more than 500 words.
  18. +
  19. Only 2 letters of support can be submitted.
-

For each letter uploaded below, please note the letter writer's relationship to the group, for example: a beneficiary of the group, local resident or member of a partner charity.

-

Once uploaded, all files are saved automatically. If you make a mistake and upload the wrong letter, please use the same button to upload the correct file as it will automatically replace the previous version.

) pdf_context_with_header_blocks [ [:normal, %(Letters of support are an essential part of your nomination, as they help to clarify and explain the impact of the nominated group's work in the local community. You will need to provide 2 letters of support alongside your nomination.)], [:normal, %(For more information on what letters can cover, please see the Letters of Support page on our website.)], - [:normal, %(Key criteria: + [:bold, %(Key criteria: - 1. letters must be written by individuals who are familiar with the group's work, for example: a beneficiary, local resident or member of a partner charity - 2. letters must not be written by a volunteer, employee, trustee, or anyone involved in the running of the group - 3. letters written by the nominator will be ineligible - 4. each letter should be no more than 500 words - 5. only 2 letters of support can be submitted + 1. Letters must be written by individuals who are familiar with the group's work, for example: a beneficiary, local resident or member of a partner charity. + 2. Letters must not be written by a volunteer, employee, trustee, or anyone involved in the running of the group. + 3. Letters written by the nominator will be ineligible. + 4. Each letter should be no more than 500 words. + 5. Only 2 letters of support can be submitted. )], - [:normal, %(For each letter uploaded below, please note the letter writer's relationship to the group, for example: a beneficiary of the group, local resident or member of a partner charity.)], - [:bold, %(Once uploaded, all files are saved automatically. If you make a mistake and upload the wrong letter, please use the same button to upload the correct file as it will automatically replace the previous version.)] ] + end + + supporters :supporter_letters_list, "" do + ref "C 1" classes "question-support-uploads" limit 2 default 2 From e4377e225a35a4b16bb2a2dd76dc4e5d288c11e1 Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Thu, 22 Aug 2024 08:53:35 +0100 Subject: [PATCH 2/6] Extract question ref code into partial so it only has to be mofified in one place --- .../frontend/views/award_form.scss | 20 +++-- .../assessor/form_answers/_question.html.slim | 14 +-- app/views/qae_form/_question.html.slim | 14 +-- app/views/qae_form/_question_ref.html.slim | 89 +------------------ .../qae_form/_supporter_fields.html.slim | 19 ++-- .../qae_form/_supporters_question.html.slim | 1 + ...tachment_with_virus_check_status.html.slim | 4 +- .../support_letters/_attachment.html.slim | 8 +- 8 files changed, 40 insertions(+), 129 deletions(-) diff --git a/app/assets/stylesheets/frontend/views/award_form.scss b/app/assets/stylesheets/frontend/views/award_form.scss index 97163db5f..e7a27600e 100644 --- a/app/assets/stylesheets/frontend/views/award_form.scss +++ b/app/assets/stylesheets/frontend/views/award_form.scss @@ -158,14 +158,24 @@ label > .visible-read-only, font-weight: normal; } -.support-letter-attachment-filename { - display: block; -} - .support-letter-attachment-container { - padding: 15px; + padding: 15px 15px 0; display: flex; + justify-content: space-between; + align-items: start; background: $govuk-light-grey; + + .flex { + display: flex; + justify-content: space-between; + align-items: start; + } + + .js-remove-attachment{ + color: $govuk-red; + word-break: keep-all; + margin-top: 0 !important; + } } .view-only, diff --git a/app/views/assessor/form_answers/_question.html.slim b/app/views/assessor/form_answers/_question.html.slim index 9078c0863..bb0f616dd 100644 --- a/app/views/assessor/form_answers/_question.html.slim +++ b/app/views/assessor/form_answers/_question.html.slim @@ -9,9 +9,7 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash - if question.label_as_legend? legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref - unless question.title.blank? - font_size = question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) ? "govuk-!-font-size-36" : "govuk-!-font-size-24" span class="govuk-body #{ font_size } govuk-!-font-weight-bold govuk-!-display-block" @@ -23,9 +21,7 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" label.govuk-label for="q_#{question.key}" id="q_#{question.key}_label" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref - unless question.title.blank? span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" == question.title @@ -36,10 +32,6 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash - if question.ref || question.sub_ref .if-js-hide label.govuk-label for="q_#{question.key}" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.visuallyhidden - = ref.to_s - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref = render "assessor/form_answers/questions/#{question.delegate_obj.class.name.demodulize.underscore}", question: question, answers: answers, attachments: attachments diff --git a/app/views/qae_form/_question.html.slim b/app/views/qae_form/_question.html.slim index d916491bc..dd0e9eb5d 100644 --- a/app/views/qae_form/_question.html.slim +++ b/app/views/qae_form/_question.html.slim @@ -11,9 +11,7 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash - if question.label_as_legend? legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref - unless question.title.blank? - font_size = question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) ? "govuk-!-font-size-36" : "govuk-!-font-size-24" span class="govuk-body #{ font_size } govuk-!-font-weight-bold govuk-!-display-block" @@ -25,9 +23,7 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" label.govuk-label for="q_#{question.key}" id="q_#{question.key}_label" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref - unless question.title.blank? span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" == question.title @@ -38,11 +34,7 @@ fieldset class=question.fieldset_classes data=question.fieldset_data_hash - if question.ref || question.sub_ref .if-js-hide label.govuk-label for="q_#{question.key}" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.visuallyhidden - = ref.to_s - span.todo - = ref.to_s + = render "qae_form/question_ref", question: question, ref: ref - if question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) - if question.ref || question.sub_ref diff --git a/app/views/qae_form/_question_ref.html.slim b/app/views/qae_form/_question_ref.html.slim index d916491bc..16b3acf99 100644 --- a/app/views/qae_form/_question_ref.html.slim +++ b/app/views/qae_form/_question_ref.html.slim @@ -1,86 +1,3 @@ -- if question.header - h2.govuk-heading-l - = question.header -- if question.header_context - == question.header_context -fieldset class=question.fieldset_classes data=question.fieldset_data_hash - = condition_divs question do - .govuk-form-group class=(" govuk-form-group--error" if @form_answer.validator_errors && @form_answer.validator_errors[question.hash_key]) - - ref = question.ref ? question.ref : question.sub_ref - - if question.title != "" || question.show_ref_always.present? - - if question.label_as_legend? - legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" - - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s - - unless question.title.blank? - - font_size = question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) ? "govuk-!-font-size-36" : "govuk-!-font-size-24" - span class="govuk-body #{ font_size } govuk-!-font-weight-bold govuk-!-display-block" - == question.title - - = render "qae_form/question_sub_title", question: question - - - else - legend.govuk-label aria-label="#{ref.to_s.gsub(' ', '-')} #{question.title.blank? ? '' : ':' + question.title}" - label.govuk-label for="q_#{question.key}" id="q_#{question.key}_label" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - - if question.ref || question.sub_ref - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.todo - = ref.to_s - - unless question.title.blank? - span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" - == question.title - - = render "qae_form/question_sub_title", question: question - - - else - - if question.ref || question.sub_ref - .if-js-hide - label.govuk-label for="q_#{question.key}" aria-label="#{ref.to_s.gsub(' ', '-')}: #{question.title}" - span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" - span.visuallyhidden - = ref.to_s - span.todo - = ref.to_s - - - if question.delegate_obj.is_a?(QaeFormBuilder::HeaderQuestion) - - if question.ref || question.sub_ref - span.question-context.question-debug.govuk-hint - = "Please note #{(question.ref || question.sub_ref).delete(" ")} is just a heading for the following sub-questions." - - if question.context - == question.context - - for help in question.help - == help.text - - else - - if question.context - span.question-context.question-debug.govuk-hint - == question.context - - if question.online_context - span.question-context.question-debug.govuk-hint - == question.online_context - - for help in question.help - span.question-context.question-debug.govuk-hint - == help.text - - - question.hint.each_with_index do |help, index| - details.govuk-details data-module='govuk-details' - - if help.title.present? - summary.govuk-details__summary - span.govuk-details__summary-text - = help.title.html_safe - .govuk-details__text - == help.text - - span.govuk-error-message - - if @form_answer.validator_errors && @form_answer.validator_errors[question.hash_key].present? && @form_answer.validator_errors[question.hash_key].is_a?(String) - span.govuk-visually-hidden - | Error: - =< @form_answer.validator_errors[question.hash_key] - - unless question.form_hint.blank? - span.govuk-hint = question.form_hint - = render partial: "qae_form/#{question.delegate_obj.class.name.demodulize.underscore}", object: question, as: 'question', locals: {answers: answers, attachments: attachments} - - / Conditional hints - - if question.can_have_conditional_hints? - = render "qae_form/conditional_hints/list", question: question +span class="steps step-#{ref.to_s.parameterize} #{'if-js-hide' if question.sub_ref && !question.display_sub_ref_on_js_form}" + span.todo + = ref.to_s diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index 15fab752f..cdf5b9f24 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -2,10 +2,10 @@ - persisted = supporter["support_letter_id"].present? || supporter["supporter_id"].present? - 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.borderless[class=class_names("js-add-example", "js-support-letter-received" => persisted) data-create-url=create_url data-update-url=update_url] legend.govuk-label - span class="steps" - span.todo C #{index + 1} + = render "qae_form/question_ref", question: question, ref: "C #{index + 1}" label[class="govuk-label"] span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"] = "The #{first_or_second} letter of support" @@ -14,8 +14,7 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = .js-system-tag data-new-hidden-input-name="form[#{question.key}][#{index}][support_letter_id]" legend.govuk-label aria-label="C #{index + 1}.1: Name" - span class="steps" - span.todo C #{index + 1}.1 + = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.1" span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" ' Name of the person who wrote the #{first_or_second} letter of support .govuk-form-group @@ -30,24 +29,22 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = 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]) legend.govuk-label aria-label="C #{index + 1}.2: Relationship to Group" - span class="steps" - span.todo C #{index + 1}.2 + = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.2" .govuk-form-group label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][relationship_to_nominee]" - ' The person's who wrote the #{first_or_second} letter of support relationship to the group + ' Relationship to group span.question-context.question-debug.govuk-hint ' For example, a beneficiary of the group, local resident or member of a partner charity. 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]) legend.govuk-label aria-label="C #{index + 1}.3: Relationship to Group" - span class="steps" - span.todo C #{index + 1}.3 + = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.2" .govuk-form-group - label.govuk-label for="form[#{question.key}][#{index}][letter_of_support]" + label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][letter_of_support]" ' Upload the #{first_or_second} letter of support span.question-context.question-debug.govuk-hint - ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will appear, allowing you to select the correct file. + ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file. 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]) - if supporter['letter_of_support'].present? diff --git a/app/views/qae_form/_supporters_question.html.slim b/app/views/qae_form/_supporters_question.html.slim index 95abd4c3a..81ae6406f 100644 --- a/app/views/qae_form/_supporters_question.html.slim +++ b/app/views/qae_form/_supporters_question.html.slim @@ -2,3 +2,4 @@ input name="form[#{question.key}][array]" value="true" type="hidden" *possible_r 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| = render 'qae_form/supporter_fields', question: question, supporter: supporter, index: index + diff --git a/app/views/shared/_attachment_with_virus_check_status.html.slim b/app/views/shared/_attachment_with_virus_check_status.html.slim index 18420519e..f4e624841 100644 --- a/app/views/shared/_attachment_with_virus_check_status.html.slim +++ b/app/views/shared/_attachment_with_virus_check_status.html.slim @@ -7,7 +7,9 @@ class: 'govuk-link' - elsif scan_results == "scanning" || scan_results == "pending" = item.try(:original_filename) - | (File uploaded and is being scanned for viruses. Preview available once the scan is complete.) + br + .govuk-hint + | (File uploaded and is being scanned for viruses. Preview available once the scan is complete.) - elsif scan_results == "infected" = item.try(:original_filename) | has been blocked (virus detected), please remove. diff --git a/app/views/support_letters/_attachment.html.slim b/app/views/support_letters/_attachment.html.slim index 3c2b1dead..b1162788d 100644 --- a/app/views/support_letters/_attachment.html.slim +++ b/app/views/support_letters/_attachment.html.slim @@ -1,9 +1,9 @@ - file = support_letter_attachments[attachment_id.to_i] .support-letter-attachment-container - div - p.govuk-body.support-letter-attachment-filename + .flex + .govuk-body.support-letter-attachment-filename = render "shared/attachment_with_virus_check_status", item: file, mount_name: :attachment - button.govuk-link.govuk-button--secondary data-module="govuk-button" type="button" onclick="removeAttachment(this)" - | Remove + button.govuk-link.js-remove-attachment data-module="govuk-button" type="button" + | Remove input.js-support-letter-attachment-id type="hidden" name="form[#{question.key}][#{index}][letter_of_support]" value=attachment_id *possible_read_only_ops From 6ff3e11d71cd8cd7448d37a35b2269164038bf2f Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:47:07 +0100 Subject: [PATCH 3/6] Update non-js views with new format for Letters of Support --- .../form/support_letters/_form.html.slim | 58 +++++++++++++------ app/views/form/supporters/index.html.slim | 15 +---- forms/award_years/v2025/qavs/qavs_step3.rb | 4 +- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/app/views/form/support_letters/_form.html.slim b/app/views/form/support_letters/_form.html.slim index 3d11283b7..1d6c3dfb6 100644 --- a/app/views/form/support_letters/_form.html.slim +++ b/app/views/form/support_letters/_form.html.slim @@ -1,26 +1,46 @@ = 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" } + - first_or_second = idx == 1 ? "first" : "second" + li.borderless + .question-block + label[class="govuk-label"] + legend.govuk-label + = render "qae_form/question_ref", question: question, ref: "C #{idx}" + span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"] + = "The #{first_or_second} letter of support" - = ff.input :manual, as: :hidden, input_html: { value: true } - = ff.input :user_id, as: :hidden, input_html: { value: current_user.id } + legend.govuk-label aria-label="C #{idx}.1: Name" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.1" + span[class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"] + = "Name of the person who wrote the #{first_or_second} letter of support" + = ff.input :first_name, label: "First Name:", input_html: { class: "form-control medium" } + = ff.input :last_name, label: "Surname:", input_html: { class: "form-control medium" } - = 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;" } - - if fff.object.attachment.present? - p.govuk-body.support-letter-attachment-filename - = render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment + legend.govuk-label aria-label="C #{idx}.2: Relationship to Group" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.2" + label for="form_answer_support_letters_attributes_#{ff.options[:child_index]}_relationship_to_nominee" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" + = "Relationship to group" + span.question-context.question-debug.govuk-hint + ' For example, a beneficiary of the group, local resident or member of a partner charity. + = ff.input :relationship_to_nominee, label: false, input_html: { class: "form-control medium" } - = fff.input :attachment_cache, as: :hidden + = ff.input :manual, as: :hidden, input_html: { value: true } + = ff.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 } + legend.govuk-label aria-label="C #{idx}.3: Upload Letter of Support" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.3" + label for="form_answer_support_letters_attributes_#{ff.options[:child_index]}_support_letter_attachment" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" + = "Upload the #{first_or_second} letter of support" + span.question-context.question-debug.govuk-hint + ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file. + = 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: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" } + - if fff.object.attachment.present? + 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 :form_answer_id, as: :hidden, input_html: { value: @form_answer.id } + = fff.input :user_id, as: :hidden, input_html: { value: current_user.id } diff --git a/app/views/form/supporters/index.html.slim b/app/views/form/supporters/index.html.slim index e5d73b67f..27f6e9caa 100644 --- a/app/views/form/supporters/index.html.slim +++ b/app/views/form/supporters/index.html.slim @@ -15,19 +15,10 @@ h1.govuk-heading-xl article.group role="article" div - letters_intro_question = @step.questions.detect { |q| q.key == :supporter_letters_list } + - letters_context = @step.questions.detect { |q| q.key == :supporter_letters_list_context} - checkbox_questions = @step.questions.select { |q| q.key.in?(%i(independent_individual not_nominator)) } - .question-block - label.govuk-label - span class="steps step-d-1" - span.visuallyhidden - ' C 1 - span.todo - ' C 1 - span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" - ' Upload your letters of support - - == letters_intro_question&.context + == letters_context&.context - for help in (letters_intro_question&.hint || []) details.govuk-details data-module="govuk-details" @@ -45,7 +36,7 @@ h1.govuk-heading-xl - f.object.support_letters.build unless f.object.support_letters[n].present? ul.list-add.supporters-list - = render partial: "form/support_letters/form", locals: { f: f } + = render partial: "form/support_letters/form", locals: { f: f, question: letters_intro_question } - checkbox_questions.each do |question| .govuk-form-group diff --git a/forms/award_years/v2025/qavs/qavs_step3.rb b/forms/award_years/v2025/qavs/qavs_step3.rb index da935217f..acfb87a1e 100644 --- a/forms/award_years/v2025/qavs/qavs_step3.rb +++ b/forms/award_years/v2025/qavs/qavs_step3.rb @@ -6,8 +6,8 @@ def qavs_step3

Please note your answers are being saved automatically in the background.

) - header :supporter_letters_list_key_criteria, "" do - help "About this section", %( + header :supporter_letters_list_context, "" do + context %(

Letters of support are an essential part of your nomination, as they help to clarify and explain the impact of the nominated group's work in the local community. You will need to provide 2 letters of support alongside your nomination.

For more information on what letters can cover, please see the Letters of Support page on our website.

Key criteria:

From 1c4c572cbc535886fc429c81ebfb43bc5d13ec8f Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:47:51 +0100 Subject: [PATCH 4/6] Update how index is written --- app/views/qae_form/_supporter_fields.html.slim | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index cdf5b9f24..762e75c6f 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -1,11 +1,12 @@ - first_or_second = index == 0 ? "first" : "second" +- idx = index + 1 - persisted = supporter["support_letter_id"].present? || supporter["supporter_id"].present? - 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.borderless[class=class_names("js-add-example", "js-support-letter-received" => persisted) data-create-url=create_url data-update-url=update_url] legend.govuk-label - = render "qae_form/question_ref", question: question, ref: "C #{index + 1}" + = render "qae_form/question_ref", question: question, ref: "C #{idx}" label[class="govuk-label"] span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"] = "The #{first_or_second} letter of support" @@ -14,7 +15,7 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = .js-system-tag data-new-hidden-input-name="form[#{question.key}][#{index}][support_letter_id]" legend.govuk-label aria-label="C #{index + 1}.1: Name" - = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.1" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.1" span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" ' Name of the person who wrote the #{first_or_second} letter of support .govuk-form-group @@ -28,8 +29,8 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = 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]) - legend.govuk-label aria-label="C #{index + 1}.2: Relationship to Group" - = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.2" + legend.govuk-label aria-label="C #{idx}.2: Relationship to Group" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.2" .govuk-form-group label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][relationship_to_nominee]" ' Relationship to group @@ -38,8 +39,8 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = 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]) - legend.govuk-label aria-label="C #{index + 1}.3: Relationship to Group" - = render "qae_form/question_ref", question: question, ref: "C #{index + 1}.2" + legend.govuk-label aria-label="C #{idx}.3: Relationship to Group" + = render "qae_form/question_ref", question: question, ref: "C #{idx}.3" .govuk-form-group label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][letter_of_support]" ' Upload the #{first_or_second} letter of support From b153dcf0543eb8d30bfbb8a9eac682496162c60e Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:35:26 +0100 Subject: [PATCH 5/6] Non-js destroy action for support letter attachments --- .../frontend/views/award_form.scss | 6 +++- .../support_letter_attachments_controller.rb | 29 +++++++++++++++++++ .../support_letter_attachments/show.html.slim | 20 +++++++++++++ .../form/support_letters/_form.html.slim | 16 ++++++---- ...tachment_with_virus_check_status.html.slim | 6 ++-- config/routes.rb | 4 ++- 6 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 app/controllers/form/support_letter_attachments_controller.rb create mode 100644 app/views/form/support_letter_attachments/show.html.slim diff --git a/app/assets/stylesheets/frontend/views/award_form.scss b/app/assets/stylesheets/frontend/views/award_form.scss index e7a27600e..bcd0b9ace 100644 --- a/app/assets/stylesheets/frontend/views/award_form.scss +++ b/app/assets/stylesheets/frontend/views/award_form.scss @@ -159,7 +159,7 @@ label > .visible-read-only, } .support-letter-attachment-container { - padding: 15px 15px 0; + padding: 15px; display: flex; justify-content: space-between; align-items: start; @@ -176,6 +176,10 @@ label > .visible-read-only, word-break: keep-all; margin-top: 0 !important; } + + .non-js-remove-attachment { + color: $govuk-red; + } } .view-only, diff --git a/app/controllers/form/support_letter_attachments_controller.rb b/app/controllers/form/support_letter_attachments_controller.rb new file mode 100644 index 000000000..1be939752 --- /dev/null +++ b/app/controllers/form/support_letter_attachments_controller.rb @@ -0,0 +1,29 @@ +class Form::SupportLetterAttachmentsController < Form::BaseController + include FormAnswerSubmissionMixin + before_action :set_support_letter + + def show; end + + def destroy + attachment = SupportLetterAttachment.find(params[:id]) + form_answer = attachment.form_answer + + if attachment.destroy + updated_list = form_answer.document['supporter_letters_list'].reject { |letter| letter['letter_of_support'] == attachment.id } + form_answer.update(document: form_answer.document.merge(supporter_letters_list: updated_list)) + + flash[:notice] = 'Attachment successfully deleted.' + else + flash[:alert] = 'Failed to delete attachment.' + end + + redirect_to form_form_answer_supporters_path(form_answer) + end + + private + + def set_support_letter + @support_letter = SupportLetter.find(params[:support_letter_id]) + @form_answer = @support_letter.form_answer + end +end diff --git a/app/views/form/support_letter_attachments/show.html.slim b/app/views/form/support_letter_attachments/show.html.slim new file mode 100644 index 000000000..10b3b01ac --- /dev/null +++ b/app/views/form/support_letter_attachments/show.html.slim @@ -0,0 +1,20 @@ +- content_for :page_title, "Support Letter Attachment" + +.govuk-grid-row + .govuk-grid-column-two-thirds + h1.govuk-heading-xl Support Letter Attachment + + - if @support_letter.support_letter_attachment.present? + .govuk-summary-list + .govuk-summary-list__row + dt.govuk-summary-list__key + | File Name + dd.govuk-summary-list__value + = @support_letter.support_letter_attachment.original_filename + + = button_to "Delete Attachment", + form_form_answer_support_letter_support_letter_attachment_path(@form_answer, @support_letter, @support_letter.support_letter_attachment), + method: :delete, + class: "govuk-button govuk-button--warning" + - else + p.govuk-body No attachment found for this support letter. diff --git a/app/views/form/support_letters/_form.html.slim b/app/views/form/support_letters/_form.html.slim index 1d6c3dfb6..b25715bd8 100644 --- a/app/views/form/support_letters/_form.html.slim +++ b/app/views/form/support_letters/_form.html.slim @@ -33,14 +33,18 @@ = "Upload the #{first_or_second} letter of support" span.question-context.question-debug.govuk-hint ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file. + = 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: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" } - if fff.object.attachment.present? - p.govuk-body.support-letter-attachment-filename + p.govuk-body.support-letter-attachment-container = render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment + - if ff.object.support_letter_attachment.id.present? + = link_to 'Remove', form_form_answer_support_letter_support_letter_attachment_path(@form_answer, ff.object, ff.object.support_letter_attachment), method: :delete, class: 'govuk-link non-js-remove-attachment' - = 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 :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 } + - puts "fff.object.attachment.id.present? #{fff.object.attachment.inspect}" + - unless fff.object.id.present? + = fff.input :attachment, as: :file, label: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" } diff --git a/app/views/shared/_attachment_with_virus_check_status.html.slim b/app/views/shared/_attachment_with_virus_check_status.html.slim index f4e624841..4b9bcb9e5 100644 --- a/app/views/shared/_attachment_with_virus_check_status.html.slim +++ b/app/views/shared/_attachment_with_virus_check_status.html.slim @@ -12,9 +12,9 @@ | (File uploaded and is being scanned for viruses. Preview available once the scan is complete.) - elsif scan_results == "infected" = item.try(:original_filename) - | has been blocked (virus detected), please remove. + | has been blocked (virus detected), please upload another file. - else - = item.try(:original_filename) - | didn't pass virus scanner check, please remove + = item.try(:original_filename) || "File" + | didn't pass virus scanner check, please upload another file. - else = item.try(:original_filename) diff --git a/config/routes.rb b/config/routes.rb index e9bb73c10..241a6acc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -104,7 +104,9 @@ namespace :form do resources :form_answers do resources :supporters, only: [:new, :create, :index, :destroy] - resources :support_letters, only: [:create] + resources :support_letters, only: [:create] do + resources :support_letter_attachments, only: [:show, :destroy] + end resources :form_attachments, only: [:index, :new, :create, :destroy] end end From 3c77bbefb30f718af1260a24dd70ded1900f6aa4 Mon Sep 17 00:00:00 2001 From: DaniBitZesty <84323332+DaniBitZesty@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:52:19 +0100 Subject: [PATCH 6/6] JS remove support letter attachment feature --- .../support_letters.js.coffee | 21 +++++++++++++++---- .../frontend/views/award_form.scss | 5 ++--- .../form/support_letters/_form.html.slim | 6 +++--- .../qae_form/_supporter_fields.html.slim | 4 ++-- .../support_letters/_attachment.html.slim | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/frontend/custom_questions/support_letters.js.coffee b/app/assets/javascripts/frontend/custom_questions/support_letters.js.coffee index af3e491b8..2dbca938b 100644 --- a/app/assets/javascripts/frontend/custom_questions/support_letters.js.coffee +++ b/app/assets/javascripts/frontend/custom_questions/support_letters.js.coffee @@ -5,6 +5,10 @@ window.SupportLetters = $(document).on 'change', '.js-trigger-autosave', debounce(SupportLetters.submit, 1000) + $(document).on 'click', '.js-remove-support-letter-attachment', (e) -> + e.preventDefault() + SupportLetters.removeFile($(this).closest('.govuk-form-group').find('input:first'), e) + new_item_init: (el) -> SupportLetters.clean_up_system_tags(el) SupportLetters.enable_item_fields_and_controls(el) @@ -25,11 +29,11 @@ window.SupportLetters = parent.find('.govuk-error-message').html('') parent.find('.govuk-error-message').closest('.govuk-form-group').removeClass('govuk-form-group--error') - - label = $('

' + filename + '

') + + textContainer = parent.find('.support-letter-attachment-container') + textContainer.removeClass('govuk-!-display-none') + textContainer.find('.flex').prepend('

' + filename + '

') hiddenInput = $("") - - parent.append(label) parent.append(hiddenInput) SupportLetters.autosave() SupportLetters.submit(e) @@ -61,6 +65,15 @@ window.SupportLetters = parent.find('input[type="hidden"]').remove() parent.find('.support-letter-attachment-filename').remove() + removeFile: (el, e) -> + $el = $(el) + $el.val('') + $el.siblings('.js-support-letter-attachment-id').first().val('') + $el.siblings('.support-letter-attachment-container').addClass('govuk-!-display-none') + $el.removeClass('govuk-!-display-none') + SupportLetters.autosave() + SupportLetters.submit(e) + enable_item_fields_and_controls: (parent) -> parent.find('.govuk-error-message').html('') prefixed = parent.find('.js-system-tag').data('new-hidden-input-name') diff --git a/app/assets/stylesheets/frontend/views/award_form.scss b/app/assets/stylesheets/frontend/views/award_form.scss index bcd0b9ace..8f7269b8d 100644 --- a/app/assets/stylesheets/frontend/views/award_form.scss +++ b/app/assets/stylesheets/frontend/views/award_form.scss @@ -151,7 +151,6 @@ margin: 0.75em 0; } -.support-letter-attachment-filename, label > .visible-read-only, .view-value { margin-bottom: 10px; @@ -171,13 +170,13 @@ label > .visible-read-only, align-items: start; } - .js-remove-attachment{ + .js-remove-support-letter-attachment{ color: $govuk-red; word-break: keep-all; margin-top: 0 !important; } - .non-js-remove-attachment { + .non-js-remove-support-letter-attachment { color: $govuk-red; } } diff --git a/app/views/form/support_letters/_form.html.slim b/app/views/form/support_letters/_form.html.slim index b25715bd8..f04e1db4f 100644 --- a/app/views/form/support_letters/_form.html.slim +++ b/app/views/form/support_letters/_form.html.slim @@ -36,15 +36,15 @@ = ff.simple_fields_for :support_letter_attachment, (ff.object.support_letter_attachment || ff.object.build_support_letter_attachment) do |fff| - if fff.object.attachment.present? - p.govuk-body.support-letter-attachment-container + p.govuk-body.support-letter-attachment-container class="govuk-!-font-size-19" = render "shared/attachment_with_virus_check_status", item: fff.object, mount_name: :attachment - if ff.object.support_letter_attachment.id.present? - = link_to 'Remove', form_form_answer_support_letter_support_letter_attachment_path(@form_answer, ff.object, ff.object.support_letter_attachment), method: :delete, class: 'govuk-link non-js-remove-attachment' + = link_to 'Remove', form_form_answer_support_letter_support_letter_attachment_path(@form_answer, ff.object, ff.object.support_letter_attachment), method: :delete, class: 'govuk-link non-js-remove-support-letter-attachment govuk-!-font-size-19' = 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 } - - puts "fff.object.attachment.id.present? #{fff.object.attachment.inspect}" + - unless fff.object.id.present? = fff.input :attachment, as: :file, label: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" } diff --git a/app/views/qae_form/_supporter_fields.html.slim b/app/views/qae_form/_supporter_fields.html.slim index 762e75c6f..b0580301c 100644 --- a/app/views/qae_form/_supporter_fields.html.slim +++ b/app/views/qae_form/_supporter_fields.html.slim @@ -47,6 +47,6 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" = span.question-context.question-debug.govuk-hint ' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file. 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]) + input class="js-support-letter-field js-trigger-autosave js-support-letter-attachment govuk-input medium #{'govuk-!-display-none' if supporter['letter_of_support'].present?}" 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]) - if supporter['letter_of_support'].present? - = render "support_letters/attachment", question: question, index: index, attachment_id: supporter['letter_of_support'] + = render "support_letters/attachment", question: question, index: index, supporter: supporter, attachment_id: supporter['letter_of_support'] diff --git a/app/views/support_letters/_attachment.html.slim b/app/views/support_letters/_attachment.html.slim index b1162788d..86406f38a 100644 --- a/app/views/support_letters/_attachment.html.slim +++ b/app/views/support_letters/_attachment.html.slim @@ -2,8 +2,8 @@ .support-letter-attachment-container .flex - .govuk-body.support-letter-attachment-filename + .support-letter-attachment-filename class="govuk-!-font-size-19" = render "shared/attachment_with_virus_check_status", item: file, mount_name: :attachment - button.govuk-link.js-remove-attachment data-module="govuk-button" type="button" + button.govuk-link.js-remove-support-letter-attachment class="govuk-!-font-size-19" data-module="govuk-button" type="button" | Remove input.js-support-letter-attachment-id type="hidden" name="form[#{question.key}][#{index}][letter_of_support]" value=attachment_id *possible_read_only_ops