Skip to content

Commit

Permalink
Merge pull request #645 from bitzesty/fix-letter-of-support-removal
Browse files Browse the repository at this point in the history
add ability to remove letter of support right after upload
  • Loading branch information
dreamfall authored Jan 31, 2024
2 parents b1424ff + eade8ed commit 5c7093a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ window.SupportLetters =
enable_item_fields_and_controls: (parent) ->
parent.find(".js-save-collection").removeClass("govuk-!-display-none")
parent.find(".visible-read-only").hide()
parent.find(".remove-link").removeClass("govuk-!-display-none")
fields = parent.find("input")
fields.removeClass("read-only")
parent.find(".govuk-error-message").html("")
Expand Down Expand Up @@ -124,6 +123,7 @@ window.SupportLetters =
SupportLetters.disable_item_fields_and_controls(parent)
window.FormValidation.validateStep()
SupportLetters.autosave()
SupportLetters.showRemoveLink(parent, data, response)

return
error: (response) ->
Expand Down Expand Up @@ -154,3 +154,9 @@ window.SupportLetters =
type: 'POST'
dataType: 'json'
})

showRemoveLink: (parent, data, response) ->
removeLink = $(".remove-supporter", parent)
removeLink.data("url", "/users/form_answers/#{response['form_answer_id']}/support_letters/#{response['id']}")
removeLink.attr("aria-label", "Delete support letter from #{data['support_letter']['first_name']} #{data['support_letter']['last_name']}")
removeLink.removeClass("govuk-!-display-none")
2 changes: 1 addition & 1 deletion app/controllers/users/support_letters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create
attachment.support_letter = support_letter
attachment.save!

render json: support_letter.id,
render json: { id: support_letter.id, form_answer_id: form_answer.id },
status: :created
else
render json: support_letter.errors.messages.to_json,
Expand Down
15 changes: 9 additions & 6 deletions app/views/qae_form/_supporter_fields.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ li.js-add-example class="#{'read-only js-support-letter-received' if persisted}"
button.govuk-button.js-save-collection class=(persisted ? "visuallyhidden" : "") data-save-collection-url=users_form_answer_support_letters_url(@form_answer)
| Submit letter of support

- if !admin_in_read_only_mode? && persisted
- if supporter["support_letter_id"].present? && @form_answer.support_letters.find_by_id(supporter["support_letter_id"])
- url = users_form_answer_support_letter_path(form_answer_id: @form_answer.id, id: supporter["support_letter_id"])
- if !admin_in_read_only_mode?
- if persisted
- if supporter["support_letter_id"].present? && @form_answer.support_letters.find_by_id(supporter["support_letter_id"])
- url = users_form_answer_support_letter_path(form_answer_id: @form_answer.id, id: supporter["support_letter_id"])
- else
- url = "#"
- if current_user || policy(:support_letter).can_remove?
= link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}"
- else
- url = "#"
- if current_user || policy(:support_letter).can_remove?
= link_to "Remove", url, class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link", data: { url: url }, 'aria-label' => "Delete support letter from #{supporter["first_name"]} #{supporter["last_name"]}"
= link_to "Remove", "#", class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link govuk-!-display-none", data: { url: "#" }, 'aria-label' => "#"
7 changes: 5 additions & 2 deletions app/views/qae_form/_supporter_fields_placeholder.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ li.js-add-example class="govuk-!-display-none"
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

button.govuk-button.button-alt.js-save-collection data-save-collection-url=users_form_answer_support_letters_url(@form_answer) disabled='disabled'
| Submit letter of support
p
button.govuk-button.button-alt.js-save-collection data-save-collection-url=users_form_answer_support_letters_url(@form_answer) disabled='disabled'
| Submit letter of support

= link_to "Remove", "#", class: "govuk-button govuk-button--warning remove-supporter remove-link js-remove-link govuk-!-display-none", data: { url: "#" }, 'aria-label' => "#"

0 comments on commit 5c7093a

Please sign in to comment.