Update admin notifications translatable fields

The same way we did for banners.

We needed to add new translation keys so the labels are displayed in the
correct language. I've kept the original `title` and `body` attributes
so they can be used in other places.

While backporting, we also added the original translations because they
hadn't been backported yet.
This commit is contained in:
Javi Martín
2018-10-08 15:52:46 +02:00
parent 96b3a37222
commit a326bcb0a1
7 changed files with 30 additions and 11 deletions

View File

@@ -63,8 +63,7 @@ class Admin::AdminNotificationsController < Admin::BaseController
private private
def admin_notification_params def admin_notification_params
attributes = [:title, :body, :link, :segment_recipient, attributes = [:link, :segment_recipient, translation_params(AdminNotification)]
*translation_params(AdminNotification)]
params.require(:admin_notification).permit(attributes) params.require(:admin_notification).permit(attributes)
end end

View File

@@ -4,9 +4,13 @@ class AdminNotification < ActiveRecord::Base
translates :title, touch: true translates :title, touch: true
translates :body, touch: true translates :body, touch: true
globalize_accessors globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
translation_class.instance_eval do
validates :title, presence: true validates :title, presence: true
validates :body, presence: true validates :body, presence: true
end
validates :segment_recipient, presence: true validates :segment_recipient, presence: true
validate :validate_segment_recipient validate :validate_segment_recipient

View File

@@ -5,12 +5,12 @@
<%= f.select :segment_recipient, options_for_select(user_segments_options, <%= f.select :segment_recipient, options_for_select(user_segments_options,
@admin_notification[:segment_recipient]) %> @admin_notification[:segment_recipient]) %>
<%= f.translatable_text_field :title %>
<%= f.text_field :link %> <%= 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 %>
<div class="margin-top"> <div class="margin-top">
<%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"), <%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"),

View File

@@ -255,6 +255,14 @@ en:
subject: Subject subject: Subject
from: From from: From
body: Email content body: Email content
admin_notification:
segment_recipient: Recipients
title: Title
link: Link
body: Text
admin_notification/translation:
title: Title
body: Text
widget/card: widget/card:
label: Label (optional) label: Label (optional)
title: Title title: Title

View File

@@ -255,6 +255,14 @@ es:
subject: Asunto subject: Asunto
from: Enviado por from: Enviado por
body: Contenido del email 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: widget/card:
label: Etiqueta (opcional) label: Etiqueta (opcional)
title: Título title: Título

View File

@@ -185,7 +185,7 @@ feature "Admin Notifications" do
notification = create(:admin_notification) notification = create(:admin_notification)
visit edit_admin_admin_notification_path(notification) visit edit_admin_admin_notification_path(notification)
fill_in :admin_notification_title_en, with: '' fill_in "Title", with: ""
click_button "Update notification" click_button "Update notification"
expect(page).to have_content error_message expect(page).to have_content error_message

View File

@@ -43,8 +43,8 @@ module Notifications
def fill_in_admin_notification_form(options = {}) def fill_in_admin_notification_form(options = {})
select (options[:segment_recipient] || 'All users'), from: :admin_notification_segment_recipient 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 'Title', with: (options[:title] || 'This is the notification title')
fill_in :admin_notification_body_en, with: (options[:body] || 'This is the notification body') 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') fill_in :admin_notification_link, with: (options[:link] || 'https://www.decide.madrid.es/vota')
end end
end end