Skip to content

Commit

Permalink
Merge pull request #713 from bitzesty/letters-of-support
Browse files Browse the repository at this point in the history
New letters of support question styling
  • Loading branch information
DaniBitZesty authored Aug 28, 2024
2 parents dff782e + 3c77bbe commit fab91b2
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = $('<p class="govuk-body support-letter-attachment-filename">' + filename + '</p>')

textContainer = parent.find('.support-letter-attachment-container')
textContainer.removeClass('govuk-!-display-none')
textContainer.find('.flex').prepend('<p class="govuk-body">' + filename + '</p>')
hiddenInput = $("<input class='js-support-letter-attachment-id' type='hidden' name='#{$el.attr("name")}' value='#{data.result['id']}' />")

parent.append(label)
parent.append(hiddenInput)
SupportLetters.autosave()
SupportLetters.submit(e)
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/frontend/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
25 changes: 22 additions & 3 deletions app/assets/stylesheets/frontend/views/award_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,34 @@
margin: 0.75em 0;
}

.support-letter-attachment-filename,
label > .visible-read-only,
.view-value {
margin-bottom: 10px;
font-weight: normal;
}

.support-letter-attachment-filename {
display: block;
.support-letter-attachment-container {
padding: 15px;
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-support-letter-attachment{
color: $govuk-red;
word-break: keep-all;
margin-top: 0 !important;
}

.non-js-remove-support-letter-attachment {
color: $govuk-red;
}
}

.view-only,
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/form/support_letter_attachments_controller.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions app/views/assessor/form_answers/_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
20 changes: 20 additions & 0 deletions app/views/form/support_letter_attachments/show.html.slim
Original file line number Diff line number Diff line change
@@ -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.
60 changes: 42 additions & 18 deletions app/views/form/support_letters/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
= 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.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
- 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"

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" }

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" }

= 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}.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|
- if fff.object.attachment.present?
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-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 }

- unless fff.object.id.present?
= fff.input :attachment, as: :file, label: false, input_html: { class: "form-control" }, wrapper_html: { style: "margin-bottom: -1rem;" }
15 changes: 3 additions & 12 deletions app/views/form/supporters/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
14 changes: 3 additions & 11 deletions app/views/qae_form/_question.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/views/qae_form/_question_ref.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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
Loading

0 comments on commit fab91b2

Please sign in to comment.