Use buttons to destroy drafts and questions

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.
This commit is contained in:
Javi Martín
2024-03-06 04:53:15 +01:00
parent 20d3725709
commit ecad046a99
8 changed files with 21 additions and 16 deletions

View File

@@ -15,10 +15,12 @@
<h3 class="inline-block"><%= @draft_version.title %></h3>
<div class="float-right">
<%= link_to t("admin.legislation.draft_versions.index.delete"),
admin_legislation_process_draft_version_path(@process, @draft_version),
method: :delete,
class: "button hollow alert" %>
<%= render Admin::ActionComponent.new(
:destroy,
@draft_version,
method: :delete,
class: "button hollow alert"
) %>
</div>
</div>

View File

@@ -15,9 +15,12 @@
<h3 class="inline-block"><%= t("admin.legislation.questions.edit.title", question_title: @question.title) %></h3>
<div class="float-right">
<%= link_to t("admin.legislation.questions.index.delete"), admin_legislation_process_question_path(@process, @question),
method: :delete,
class: "button hollow alert" %>
<%= render Admin::ActionComponent.new(
:destroy,
@question,
method: :delete,
class: "button hollow alert"
) %>
</div>
</div>
</div>

View File

@@ -24,9 +24,9 @@ module ActionDispatch::Routing::UrlFor
end
def namespaced_polymorphic_path(namespace, resource, options = {})
if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer
Poll::Question Poll::Question::Answer Poll::Question::Answer::Video Poll::Shift
SDG::LocalTarget].include?(resource.class.name)
if %w[Budget::Group Budget::Heading Legislation::DraftVersion Legislation::Question
Poll::Booth Poll::BoothAssignment Poll::Officer Poll::Question Poll::Question::Answer
Poll::Question::Answer::Video Poll::Shift SDG::LocalTarget].include?(resource.class.name)
resolve = resolve_for(resource)
resolve_options = resolve.pop

View File

@@ -664,7 +664,6 @@ en:
index:
title: Draft versions
create: Create version
delete: Delete
preview: Preview
new:
back: Back
@@ -697,7 +696,6 @@ en:
back: Back
title: Questions associated to this process
create: Create question
delete: Delete
new:
back: Back
title: Create new question

View File

@@ -664,7 +664,6 @@ es:
index:
title: Versiones del borrador
create: Crear versión
delete: Borrar
preview: Previsualizar
new:
back: Volver
@@ -697,7 +696,6 @@ es:
back: Volver
title: Preguntas asociadas a este proceso
create: Crear pregunta
delete: Borrar
new:
back: Volver
title: Crear nueva pregunta

View File

@@ -346,3 +346,7 @@ end
resolve "Poll::Question::Answer::Video" do |video, options|
[:answer, :video, options.merge(answer_id: video.answer, id: video)]
end
resolve "Legislation::DraftVersion" do |version, options|
[version.process, :draft_version, options.merge(id: version)]
end

View File

@@ -78,7 +78,7 @@ describe "Admin legislation draft versions", :admin do
version = create(:legislation_draft_version, body: "Version 1")
visit edit_admin_legislation_process_draft_version_path(version.process, version)
click_link "Delete"
click_button "Delete"
expect(page).to have_content "Draft deleted successfully"
end

View File

@@ -75,7 +75,7 @@ describe "Admin legislation questions", :admin do
visit edit_admin_legislation_process_question_path(process, question)
click_link "Delete"
click_button "Delete"
expect(page).to have_content "Questions"
expect(page).to have_content "Question 1"