diff --git a/app/controllers/admin/admin_notifications_controller.rb b/app/controllers/admin/admin_notifications_controller.rb index 33e99f9ed..430e51f53 100644 --- a/app/controllers/admin/admin_notifications_controller.rb +++ b/app/controllers/admin/admin_notifications_controller.rb @@ -63,8 +63,7 @@ class Admin::AdminNotificationsController < Admin::BaseController private def admin_notification_params - attributes = [:title, :body, :link, :segment_recipient, - *translation_params(AdminNotification)] + attributes = [:link, :segment_recipient, translation_params(AdminNotification)] params.require(:admin_notification).permit(attributes) end diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index 4291206bc..e53150ace 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -4,9 +4,13 @@ class AdminNotification < ActiveRecord::Base translates :title, touch: true translates :body, touch: true globalize_accessors + accepts_nested_attributes_for :translations, allow_destroy: true + + translation_class.instance_eval do + validates :title, presence: true + validates :body, presence: true + end - validates :title, presence: true - validates :body, presence: true validates :segment_recipient, presence: true validate :validate_segment_recipient diff --git a/app/views/admin/admin_notifications/_form.html.erb b/app/views/admin/admin_notifications/_form.html.erb index ba9a77a79..081777ccb 100644 --- a/app/views/admin/admin_notifications/_form.html.erb +++ b/app/views/admin/admin_notifications/_form.html.erb @@ -5,12 +5,12 @@ <%= f.select :segment_recipient, options_for_select(user_segments_options, @admin_notification[:segment_recipient]) %> - - <%= f.translatable_text_field :title %> - <%= f.text_field :link %> - <%= f.translatable_text_area :body %> + <%= f.translatable_fields do |translations_form| %> + <%= translations_form.text_field :title %> + <%= translations_form.text_area :body %> + <% end %>
<%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"), diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 84dee7a77..d79b0a070 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -255,6 +255,14 @@ en: subject: Subject from: From body: Email content + admin_notification: + segment_recipient: Recipients + title: Title + link: Link + body: Text + admin_notification/translation: + title: Title + body: Text widget/card: label: Label (optional) title: Title diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index b450e735d..9d74308e4 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -255,6 +255,14 @@ es: subject: Asunto from: Enviado por body: Contenido del email + admin_notification: + segment_recipient: Destinatarios + title: Título + link: Enlace + body: Texto + admin_notification/translation: + title: Título + body: Texto widget/card: label: Etiqueta (opcional) title: Título diff --git a/spec/features/admin/admin_notifications_spec.rb b/spec/features/admin/admin_notifications_spec.rb index d72b8529f..a37790b63 100644 --- a/spec/features/admin/admin_notifications_spec.rb +++ b/spec/features/admin/admin_notifications_spec.rb @@ -185,7 +185,7 @@ feature "Admin Notifications" do notification = create(:admin_notification) visit edit_admin_admin_notification_path(notification) - fill_in :admin_notification_title_en, with: '' + fill_in "Title", with: "" click_button "Update notification" expect(page).to have_content error_message diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb index 8b7615b0a..4730ae42f 100644 --- a/spec/support/common_actions/notifications.rb +++ b/spec/support/common_actions/notifications.rb @@ -43,8 +43,8 @@ module Notifications def fill_in_admin_notification_form(options = {}) select (options[:segment_recipient] || 'All users'), from: :admin_notification_segment_recipient - fill_in :admin_notification_title_en, with: (options[:title] || 'This is the notification title') - fill_in :admin_notification_body_en, with: (options[:body] || 'This is the notification body') + fill_in 'Title', with: (options[:title] || 'This is the notification title') + fill_in 'Text', with: (options[:body] || 'This is the notification body') fill_in :admin_notification_link, with: (options[:link] || 'https://www.decide.madrid.es/vota') end end