Edition of page part for multiple languages.
This commit is contained in:
1 parent
0969f6b6cc
commit
2522cde2f5
13 files changed
+70
-18
No files matched your search
@@ -22,6 +22,14 @@ class Admin::PagePartsController < ApplicationController
|
||||
|
||||
def edit
|
||||
@part = PagePart.find(params[:id])
|
||||
case @part.kind
|
||||
when 'text'
|
||||
@i18n_variable = @part.i18n_variable
|
||||
@partial = 'edit_text'
|
||||
@part_locale = params[:part_locale] || I18n.locale.to_s
|
||||
when 'module'
|
||||
when 'snippet'
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -6,7 +6,24 @@ class PagePart
|
||||
field :name
|
||||
field :content
|
||||
field :kind
|
||||
field :i18n_variable_id, :type => BSON::ObjectId
|
||||
|
||||
belongs_to :page
|
||||
|
||||
# Get the i18n_variable
|
||||
def i18n_variable
|
||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
||||
end
|
||||
|
||||
# Update or create the i18n_variable record
|
||||
def i18n_variable=(attr)
|
||||
if self.i18n_variable_id
|
||||
self.i18n_variable.update_attributes(attr)
|
||||
else
|
||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
|
||||
var.save
|
||||
self.i18n_variable_id = var.id
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,10 +0,0 @@
|
||||
<%= flash_messages %>
|
||||
|
||||
<%= form_for @part, :url => admin_page_part_path(@part), :html => { :class => 'form' } do |f| %>
|
||||
|
||||
<%= render :partial => "admin/page_parts/form", :locals => { :f => f } %>
|
||||
|
||||
<p>
|
||||
<%= f.submit t(:update) %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -0,0 +1,17 @@
|
||||
<%= flash_messages %>
|
||||
|
||||
<%= render 'language_bar' %>
|
||||
|
||||
|
||||
<%= form_for @part, :url => admin_page_part_path(@part), :html => { :class => 'form' } do |f| %>
|
||||
<%= fields_for "page_part[i18n_variable]", @i18n_variable, :index => nil do |f| %>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
<div class="ckeditor_locale" style="display:<%= @part_locale.eql?(locale) ? 'block' : 'none' %>">
|
||||
<%= render :partial => "admin/page_parts/form", :locals => { :f => f, :locale => locale } %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= f.submit t(:update) %> <%= link_back %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -1,3 +1,3 @@
|
||||
<%= f.error_messages %>
|
||||
|
||||
<%= f.cktext_area :content, :toolbar=>'Full', :width=>'700px', :height=>'200px' %>
|
||||
<%= f.cktext_area locale, :toolbar=>'Full', :width=>'700px', :height=>'200px'%>
|
||||
@@ -0,0 +1,7 @@
|
||||
<%= raw(VALID_LOCALES.map{ |locale|
|
||||
if @part_locale.to_s.eql?(locale)
|
||||
t(:_locale, :locale => locale)
|
||||
else
|
||||
link_to t(:_locale, :locale => locale), edit_admin_page_part_path(@part, :part_locale => locale), :class => 'reload'
|
||||
end
|
||||
}.join(' | ')) %>
|
||||
@@ -2,4 +2,4 @@
|
||||
<div id='sidebar'><%= render 'admin/items/site_map_left_bar' %></div>
|
||||
<% end -%>
|
||||
|
||||
<%= render 'edit' %>
|
||||
<%= render @partial %>
|
||||
@@ -1 +1 @@
|
||||
$('#main').html("<%= escape_javascript(render(:partial => 'edit')) %>");
|
||||
$('#main').html("<%= escape_javascript(render(:partial => @partial)) %>");
|
||||
Reference in new issue
Block a user