Update site customization pages translatable fields
This commit is contained in:
@@ -35,17 +35,10 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def page_params
|
def page_params
|
||||||
attributes = [:slug,
|
attributes = [:slug, :more_info_flag, :print_content_flag, :status, :locale]
|
||||||
:title,
|
|
||||||
:subtitle,
|
|
||||||
:content,
|
|
||||||
:more_info_flag,
|
|
||||||
:print_content_flag,
|
|
||||||
:status,
|
|
||||||
:locale]
|
|
||||||
|
|
||||||
params.require(:site_customization_page).permit(*attributes,
|
params.require(:site_customization_page).permit(*attributes,
|
||||||
*translation_params(SiteCustomization::Page)
|
translation_params(SiteCustomization::Page)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
class SiteCustomization::Page < ActiveRecord::Base
|
class SiteCustomization::Page < ActiveRecord::Base
|
||||||
VALID_STATUSES = %w(draft published)
|
VALID_STATUSES = %w(draft published)
|
||||||
|
|
||||||
validates :slug, presence: true,
|
|
||||||
uniqueness: { case_sensitive: false },
|
|
||||||
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
|
|
||||||
validates :title, presence: true
|
|
||||||
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
|
||||||
|
|
||||||
translates :title, touch: true
|
translates :title, touch: true
|
||||||
translates :subtitle, touch: true
|
translates :subtitle, touch: true
|
||||||
translates :content, touch: true
|
translates :content, touch: true
|
||||||
globalize_accessors
|
globalize_accessors
|
||||||
|
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||||
|
|
||||||
|
translation_class.instance_eval do
|
||||||
|
validates :title, presence: true
|
||||||
|
end
|
||||||
|
|
||||||
|
validates :slug, presence: true,
|
||||||
|
uniqueness: { case_sensitive: false },
|
||||||
|
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
|
||||||
|
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||||
|
|
||||||
scope :published, -> { where(status: 'published').order('id DESC') }
|
scope :published, -> { where(status: 'published').order('id DESC') }
|
||||||
scope :with_more_info_flag, -> { where(status: 'published', more_info_flag: true).order('id ASC') }
|
scope :with_more_info_flag, -> { where(status: 'published', more_info_flag: true).order('id ASC') }
|
||||||
|
|||||||
@@ -38,12 +38,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<hr>
|
<hr>
|
||||||
<%= f.translatable_text_field :title %>
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
<%= f.translatable_text_field :subtitle %>
|
<%= translations_form.text_field :title %>
|
||||||
<div class="ckeditor">
|
<%= translations_form.text_field :subtitle %>
|
||||||
<%= f.translatable_cktext_area :content,
|
<div class="ckeditor">
|
||||||
ckeditor: { language: I18n.locale, toolbar: "admin" } %>
|
<%= translations_form.cktext_area :content,
|
||||||
</div>
|
ckeditor: { language: I18n.locale, toolbar: "admin" } %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 medium-6 large-3 margin-top">
|
<div class="small-12 medium-6 large-3 margin-top">
|
||||||
<%= f.submit class: "button success expanded" %>
|
<%= f.submit class: "button success expanded" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -211,6 +211,10 @@ en:
|
|||||||
more_info_flag: Show in help page
|
more_info_flag: Show in help page
|
||||||
print_content_flag: Print content button
|
print_content_flag: Print content button
|
||||||
locale: Language
|
locale: Language
|
||||||
|
site_customization/page/translation:
|
||||||
|
title: Title
|
||||||
|
subtitle: Subtitle
|
||||||
|
content: Content
|
||||||
site_customization/image:
|
site_customization/image:
|
||||||
name: Name
|
name: Name
|
||||||
image: Image
|
image: Image
|
||||||
|
|||||||
@@ -211,6 +211,10 @@ es:
|
|||||||
more_info_flag: Mostrar en la página de ayuda
|
more_info_flag: Mostrar en la página de ayuda
|
||||||
print_content_flag: Botón de imprimir contenido
|
print_content_flag: Botón de imprimir contenido
|
||||||
locale: Idioma
|
locale: Idioma
|
||||||
|
site_customization/page/translation:
|
||||||
|
title: Título
|
||||||
|
subtitle: Subtítulo
|
||||||
|
content: Contenido
|
||||||
site_customization/image:
|
site_customization/image:
|
||||||
name: Nombre
|
name: Nombre
|
||||||
image: Imagen
|
image: Imagen
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ feature "Admin custom pages" do
|
|||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_behaves_like "translatable",
|
||||||
|
"site_customization_page",
|
||||||
|
"edit_admin_site_customization_page_path",
|
||||||
|
%w[title subtitle],
|
||||||
|
{ "content" => :ckeditor }
|
||||||
|
|
||||||
scenario "Index" do
|
scenario "Index" do
|
||||||
custom_page = create(:site_customization_page)
|
custom_page = create(:site_customization_page)
|
||||||
visit admin_site_customization_pages_path
|
visit admin_site_customization_pages_path
|
||||||
@@ -28,10 +34,10 @@ feature "Admin custom pages" do
|
|||||||
|
|
||||||
click_link "Create new page"
|
click_link "Create new page"
|
||||||
|
|
||||||
fill_in "site_customization_page_title_en", with: "An example custom page"
|
fill_in "Title", with: "An example custom page"
|
||||||
fill_in "site_customization_page_subtitle_en", with: "Page subtitle"
|
fill_in "Subtitle", with: "Page subtitle"
|
||||||
fill_in "site_customization_page_slug", with: "example-page"
|
fill_in "site_customization_page_slug", with: "example-page"
|
||||||
fill_in "site_customization_page_content_en", with: "This page is about..."
|
fill_in "Content", with: "This page is about..."
|
||||||
|
|
||||||
click_button "Create Custom page"
|
click_button "Create Custom page"
|
||||||
|
|
||||||
@@ -57,7 +63,7 @@ feature "Admin custom pages" do
|
|||||||
expect(page).to have_selector("h2", text: "An example custom page")
|
expect(page).to have_selector("h2", text: "An example custom page")
|
||||||
expect(page).to have_selector("input[value='custom-example-page']")
|
expect(page).to have_selector("input[value='custom-example-page']")
|
||||||
|
|
||||||
fill_in "site_customization_page_title_en", with: "Another example custom page"
|
fill_in "Title", with: "Another example custom page"
|
||||||
fill_in "site_customization_page_slug", with: "another-custom-example-page"
|
fill_in "site_customization_page_slug", with: "another-custom-example-page"
|
||||||
click_button "Update Custom page"
|
click_button "Update Custom page"
|
||||||
|
|
||||||
|
|||||||
@@ -137,123 +137,4 @@ feature "Custom Pages" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Translation" do
|
|
||||||
|
|
||||||
let(:custom_page) { create(:site_customization_page, :published,
|
|
||||||
slug: "example-page",
|
|
||||||
title_en: "Title in English",
|
|
||||||
title_es: "Titulo en Español",
|
|
||||||
subtitle_en: "Subtitle in English",
|
|
||||||
subtitle_es: "Subtitulo en Español",
|
|
||||||
content_en: "Content in English",
|
|
||||||
content_es: "Contenido en Español"
|
|
||||||
) }
|
|
||||||
|
|
||||||
background do
|
|
||||||
admin = create(:administrator)
|
|
||||||
login_as(admin.user)
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
@edit_page_url = edit_admin_site_customization_page_path(custom_page)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Add a translation in Português", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
select "Português brasileiro", from: "translation_locale"
|
|
||||||
fill_in 'site_customization_page_title_pt_br', with: 'Titulo em Português'
|
|
||||||
|
|
||||||
click_button 'Update Custom page'
|
|
||||||
expect(page).to have_content "Page updated successfully"
|
|
||||||
|
|
||||||
visit @edit_page_url
|
|
||||||
expect(page).to have_field('site_customization_page_title_en', with: 'Title in English')
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
expect(page).to have_field('site_customization_page_title_es', with: 'Titulo en Español')
|
|
||||||
|
|
||||||
click_link "Português brasileiro"
|
|
||||||
expect(page).to have_field('site_customization_page_title_pt_br', with: 'Titulo em Português')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update a translation", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
fill_in 'site_customization_page_title_es', with: 'Titulo correcta en Español'
|
|
||||||
|
|
||||||
click_button 'Update Custom page'
|
|
||||||
expect(page).to have_content "Page updated successfully"
|
|
||||||
|
|
||||||
visit custom_page.url
|
|
||||||
|
|
||||||
select('English', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(page).to have_content("Title in English")
|
|
||||||
|
|
||||||
select('Español', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(page).to have_content("Titulo correcta en Español")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Remove a translation", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
click_link "Remove language"
|
|
||||||
|
|
||||||
expect(page).not_to have_link "Español"
|
|
||||||
|
|
||||||
click_button "Update Custom page"
|
|
||||||
visit @edit_page_url
|
|
||||||
expect(page).not_to have_link "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "Globalize javascript interface" do
|
|
||||||
|
|
||||||
scenario "Highlight current locale", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
select('Español', from: 'locale-switcher')
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Highlight selected locale", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "English"
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show selected locale form", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
expect(page).to have_field('site_customization_page_title_en', with: 'Title in English')
|
|
||||||
|
|
||||||
click_link "Español"
|
|
||||||
|
|
||||||
expect(page).to have_field('site_customization_page_title_es', with: 'Titulo en Español')
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Select a locale and add it to the milestone form", :js do
|
|
||||||
visit @edit_page_url
|
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
|
||||||
|
|
||||||
expect(page).to have_link "Français"
|
|
||||||
|
|
||||||
click_link "Français"
|
|
||||||
|
|
||||||
expect(page).to have_field('site_customization_page_title_fr')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ def field_for(field, locale, visible: true)
|
|||||||
if translatable_class.name == "I18nContent"
|
if translatable_class.name == "I18nContent"
|
||||||
"contents_content_#{translatable.key}values_#{field}_#{locale}"
|
"contents_content_#{translatable.key}values_#{field}_#{locale}"
|
||||||
else
|
else
|
||||||
find("[data-locale='#{locale}'][id$='#{field}']", visible: visible)[:id]
|
find("[data-locale='#{locale}'][id$='_#{field}']", visible: visible)[:id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -296,6 +296,8 @@ def update_button_text
|
|||||||
"Update poll"
|
"Update poll"
|
||||||
when "Poll::Question", "Poll::Question::Answer"
|
when "Poll::Question", "Poll::Question::Answer"
|
||||||
"Save"
|
"Save"
|
||||||
|
when "SiteCustomization::Page"
|
||||||
|
"Update Custom page"
|
||||||
when "Widget::Card"
|
when "Widget::Card"
|
||||||
"Save card"
|
"Save card"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user