diff --git a/app/components/admin/action_component.rb b/app/components/admin/action_component.rb index 08c5916b1..ab713b642 100644 --- a/app/components/admin/action_component.rb +++ b/app/components/admin/action_component.rb @@ -40,7 +40,11 @@ class Admin::ActionComponent < ApplicationComponent def confirmation_text if options[:confirm] == true - t("admin.actions.confirm") + if action == :destroy + t("admin.actions.confirm_delete", name: record_name) + else + t("admin.actions.confirm_action", action: text, name: record_name) + end else options[:confirm] end diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb index 7a57c9134..1fa38d32f 100644 --- a/app/components/admin/budgets/table_actions_component.html.erb +++ b/app/components/admin/budgets/table_actions_component.html.erb @@ -1,7 +1,4 @@ -<%= render Admin::TableActionsComponent.new(budget, - destroy_confirmation: t("admin.actions.confirm_delete", resource_name: t("admin.budgets.shared.resource_name"), - name: budget.name) - ) do |actions| %> +<%= render Admin::TableActionsComponent.new(budget) do |actions| %> <%= actions.action(:investments, text: t("admin.budgets.index.budget_investments"), path: admin_budget_budget_investments_path(budget_id: budget.id)) %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index bd7dac056..3284f41f9 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -5,7 +5,10 @@ en: actions: actions: Actions confirm: Are you sure? + confirm_action: "Are you sure? %{action} \"%{name}\"" + confirm_delete: "Are you sure? This action will delete \"%{name}\" and can't be undone." confirm_hide: Confirm moderation + delete: "Delete" hide: Hide hide_author: Hide author label: "%{action} %{name}" @@ -14,8 +17,6 @@ en: unmark_featured: Unmark featured edit: Edit configure: Configure - delete: Delete - confirm_delete: "Are you sure? This action will delete %{resource_name} '%{name}' and can't be undone." officing_booth: title: "You are officing the booth located at %{booth}. If this is not correct, do not continue and call the help phone number. Thank you." banners: @@ -148,8 +149,6 @@ en: calculate: Calculate Winner Investments calculated: Winners being calculated, it may take a minute. recalculate: Recalculate Winner Investments - shared: - resource_name: "the budget" budget_groups: name: "Name" headings_name: "Headings" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 36605d887..be84208a3 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -5,7 +5,10 @@ es: actions: actions: Acciones confirm: '¿Estás seguro?' + confirm_action: "¿Estás seguro? %{action} \"%{name}\"" + confirm_delete: "¿Estás seguro? Esta acción borrará \"%{name}\" y no se puede deshacer." confirm_hide: Confirmar moderación + delete: Borrar hide: Ocultar hide_author: Bloquear al autor label: "%{action} %{name}" @@ -14,8 +17,6 @@ es: unmark_featured: Quitar destacado edit: Editar configure: Configurar - confirm_delete: "¿Estás seguro? Esta acción borrará %{resource_name} '%{name}' y no se puede deshacer." - delete: Borrar officing_booth: title: "Estás ahora mismo en la mesa ubicada en %{booth}. Si esto no es correcto no sigas adelante y llama al teléfono de incidencias. Gracias." banners: @@ -148,8 +149,6 @@ es: calculate: Calcular proyectos ganadores calculated: Calculando ganadores, puede tardar un minuto. recalculate: Recalcular proyectos ganadores - shared: - resource_name: "el presupuesto" budget_groups: name: "Nombre" headings_name: "Partidas" diff --git a/spec/components/admin/action_component_spec.rb b/spec/components/admin/action_component_spec.rb index 521796671..e156b13da 100644 --- a/spec/components/admin/action_component_spec.rb +++ b/spec/components/admin/action_component_spec.rb @@ -60,4 +60,49 @@ describe Admin::ActionComponent do end end end + + describe "data-confirm attribute" do + it "is not rendered by default" do + render_inline Admin::ActionComponent.new(:edit, double, path: "/") + + expect(page).to have_link count: 1 + expect(page).not_to have_css "[data-confirm]" + end + + it "is not rendered when confirm is nil" do + render_inline Admin::ActionComponent.new(:edit, double, path: "/", confirm: nil) + + expect(page).to have_link count: 1 + expect(page).not_to have_css "[data-confirm]" + end + + it "renders with the given value" do + render_inline Admin::ActionComponent.new(:edit, double, path: "/", confirm: "Really?") + + expect(page).to have_link count: 1 + expect(page).to have_css "[data-confirm='Really?']" + end + + context "when confirm is true" do + it "uses the human name as default" do + record = double(human_name: "Everywhere and nowhere") + text = 'Are you sure? Edit "Everywhere and nowhere"' + + render_inline Admin::ActionComponent.new(:edit, record, path: "/", confirm: true) + + expect(page).to have_link count: 1 + expect(page).to have_css "[data-confirm='#{text}']" + end + + it "includes a more detailed message for the destroy action" do + record = double(human_name: "Participatory Budget 2015") + text = 'Are you sure? This action will delete "Participatory Budget 2015" and can\\\'t be undone.' + + render_inline Admin::ActionComponent.new(:destroy, record, path: "/", confirm: true) + + expect(page).to have_link count: 1 + expect(page).to have_css "[data-confirm='#{text}']" + end + end + end end diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index 3c710f3cc..7bc72c3c2 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -39,7 +39,7 @@ describe Admin::TableActionsComponent, controller: Admin::BaseController do end it "allows custom URLs" do - render_inline Admin::TableActionsComponent.new(nil, edit_path: "/myedit", destroy_path: "/mydestroy") + render_inline Admin::TableActionsComponent.new(record, edit_path: "/myedit", destroy_path: "/mydestroy") expect(page).to have_link "Edit", href: "/myedit" expect(page).to have_link "Delete", href: "/mydestroy" diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index ed4255094..1101f2287 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -99,7 +99,7 @@ describe "Admin budgets", :admin do visit admin_budgets_path within "tr", text: "To be deleted" do - message = "Are you sure? This action will delete the budget 'To be deleted' and can't be undone." + message = "Are you sure? This action will delete \"To be deleted\" and can't be undone." accept_confirm(message) { click_link "Delete" } end