-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nobn-js destroy action for support letter attachments
- Loading branch information
1 parent
1c4c572
commit 69dae12
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
app/controllers/form/support_letter_attachments_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters