Use a button to destroy poll question answer images

As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST (or, in this case, DELETE) requests to
the server has a few issues.

Note that the AJAX response stopped working after replacing the link
with a button. Not sure about the reason, but, since this is one of the
very few places where we use AJAX calls to delete content, the easiest
solution is to stop using AJAX and be consistent with what we do in the
rest of the admin section.
This commit is contained in:
Javi Martín
2024-03-06 05:05:29 +01:00
parent 53d85d6431
commit d050c04bb0
6 changed files with 14 additions and 14 deletions

View File

@@ -25,9 +25,8 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
def destroy
@image.destroy!
respond_to do |format|
format.js { render layout: false }
end
redirect_to admin_answer_images_path(@image.imageable),
notice: t("flash.actions.destroy.poll_question_answer_image")
end
private

View File

@@ -1,3 +0,0 @@
$(".delete").on("ajax:success", function () {
$(this).closest("div").fadeOut();
});

View File

@@ -26,12 +26,14 @@
<%= render_image(image, :large, true) if image.present? %>
<% if can?(:destroy, image) %>
<%= link_to t("images.remove_image"),
admin_image_path(image),
class: "delete float-right",
method: :delete,
remote: true,
data: { confirm: t("admin.actions.confirm_action", action: t("images.remove_image"), name: image.title) } %>
<%= render Admin::ActionComponent.new(
:destroy,
image,
text: t("images.remove_image"),
method: :delete,
confirm: t("admin.actions.confirm_action", action: t("images.remove_image"), name: image.title),
class: "delete float-right"
) %>
<% end %>
</div>
<% end %>

View File

@@ -34,6 +34,7 @@ en:
destroy:
budget_investment: "Investment project deleted successfully."
topic: "Topic deleted successfully."
poll_question_answer_image: "Image deleted successfully."
poll_question_answer_video: "Answer video deleted successfully."
valuator_group: "Valuator group deleted successfully"
vote: "Vote deleted successfully"

View File

@@ -34,6 +34,7 @@ es:
destroy:
budget_investment: "Proyecto de gasto eliminado."
topic: "Tema eliminado."
poll_question_answer_image: "Imagen eliminada correctamente."
poll_question_answer_video: "Vídeo de respuesta eliminado."
valuator_group: "Grupo de evaluadores eliminado correctamente"
vote: "Voto eliminado correctamente"

View File

@@ -73,7 +73,7 @@ describe "Images", :admin do
expect(page).to have_content image.title
accept_confirm "Are you sure? Remove image \"#{image.title}\"" do
click_link "Remove image"
click_button "Remove image"
end
expect(page).not_to have_css "img[title='#{image.title}']"
@@ -88,7 +88,7 @@ describe "Images", :admin do
expect(page).to have_css "img[title='#{image.title}']"
expect(page).to have_content image.title
expect(page).not_to have_link "Remove image"
expect(page).not_to have_content "Remove image"
expect(page).to have_content "Once the poll has started it will not be possible to create, edit or"
end
end