From ec1ac0aa7632f326ad2b906b5363643f983ff8ea Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 10 Apr 2020 10:13:07 +0500 Subject: [PATCH] Add confirmation --- app/helpers/contacts_helper.rb | 6 ++++++ app/views/settings/contacts/_table.html.erb | 5 +++++ config/locales/other/en.yml | 2 ++ config/locales/other/ru.yml | 2 ++ 4 files changed, 15 insertions(+) diff --git a/app/helpers/contacts_helper.rb b/app/helpers/contacts_helper.rb index ae812cf..baae148 100644 --- a/app/helpers/contacts_helper.rb +++ b/app/helpers/contacts_helper.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true module ContactsHelper + def contact_public_switch_confirmation(contact) + return if contact.show_in_public? + + translate :contact_public_switch_confirmation, value: contact.value + end + def contact_destroy_confirmation(contact) value = "#{Contact.model_name.human(count: 1)} \"#{contact.value}\"" diff --git a/app/views/settings/contacts/_table.html.erb b/app/views/settings/contacts/_table.html.erb index 0f3227c..86e967c 100644 --- a/app/views/settings/contacts/_table.html.erb +++ b/app/views/settings/contacts/_table.html.erb @@ -21,6 +21,7 @@ <% contacts.each do |contact| %> <%= contact.contact_network.name %> + <% if contact.link.nil? %> <%= truncate contact.value %> @@ -29,6 +30,7 @@ <% end %> + <% if policy([ :settings, @@ -42,6 +44,7 @@ <% end %> <% end %> + <% if policy([ :settings, @@ -50,11 +53,13 @@ <%= link_to( settings_contact_public_switch_path(contact), method: :post, + data: { confirm: contact_public_switch_confirmation(contact) }, ) do %> <%= bool_badge contact.show_in_public %> <% end %> <% end %> + <% if policy([:settings, contact]).destroy? %> <%= link_to( diff --git a/config/locales/other/en.yml b/config/locales/other/en.yml index 61009fa..2b87d5f 100644 --- a/config/locales/other/en.yml +++ b/config/locales/other/en.yml @@ -15,3 +15,5 @@ en: new_sign_in: New sign in to your account sidekiq: Sidekiq since: since + contact_public_switch_confirmation: > + Do you really want to make contact "%{value}" public? diff --git a/config/locales/other/ru.yml b/config/locales/other/ru.yml index 1e84936..468443e 100644 --- a/config/locales/other/ru.yml +++ b/config/locales/other/ru.yml @@ -15,3 +15,5 @@ ru: new_sign_in: Произведён вход в ваш аккаунт sidekiq: Sidekiq since: с + contact_public_switch_confirmation: > + Вы действительно хотите сделать контакт "%{value}" публичным?