Edition of page part for multiple languages.
This commit is contained in:
parent
0969f6b6cc
commit
2522cde2f5
2
Gemfile
2
Gemfile
|
@ -12,6 +12,8 @@ gem 'mini_magick'
|
|||
|
||||
gem 'mongoid', '2.0.0'
|
||||
|
||||
gem 'rake', '0.8.7'
|
||||
|
||||
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
||||
# gem 'ruby-debug'
|
||||
# gem 'ruby-debug19'
|
||||
|
|
|
@ -36,7 +36,7 @@ GEM
|
|||
carrierwave (0.5.4)
|
||||
activesupport (~> 3.0)
|
||||
chronic (0.3.0)
|
||||
ckeditor (3.5.3)
|
||||
ckeditor (3.5.4)
|
||||
mime-types (>= 1.16)
|
||||
delorean (1.0.0)
|
||||
chronic
|
||||
|
@ -88,7 +88,7 @@ GEM
|
|||
activesupport (= 3.0.6)
|
||||
rake (>= 0.8.7)
|
||||
thor (~> 0.14.4)
|
||||
rake (0.9.0)
|
||||
rake (0.8.7)
|
||||
rcov (0.9.9)
|
||||
rspec (2.6.0)
|
||||
rspec-core (~> 2.6.0)
|
||||
|
@ -129,6 +129,7 @@ DEPENDENCIES
|
|||
mongoid (= 2.0.0)
|
||||
nokogiri
|
||||
rails (= 3.0.6)
|
||||
rake (= 0.8.7)
|
||||
rcov
|
||||
rspec (~> 2.0)
|
||||
rspec-rails (~> 2.0)
|
||||
|
|
|
@ -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)) %>");
|
|
@ -182,7 +182,7 @@ module Parser
|
|||
ret << "<div class='edit_link' style='display:none'>" if part
|
||||
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" if part
|
||||
ret << '</div>' if part
|
||||
ret << part.content rescue ''
|
||||
ret << part.i18n_variable[I18n.locale.to_s] rescue ''
|
||||
ret << tag.expand
|
||||
ret << '</div>'
|
||||
end
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace :dev do
|
|||
var_10 = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
|
||||
var_11 = I18nVariable.create!( :document_class => 'Page', :key => 'about', :en => 'About', :zh_tw => '關於我們' )
|
||||
var_12 = I18nVariable.create!( :document_class => 'Link', :key => 'google', :en => 'Google', :zh_tw => 'Google' )
|
||||
var_13 = I18nVariable.create!( :document_class => 'PagePart', :key => 'main_content', :en => 'This is the homepage', :zh_tw => '這是首頁', :parent_id => var_10.id )
|
||||
var_14 = I18nVariable.create!( :document_class => 'PagePart', :key => 'main_content', :en => 'This is about', :zh_tw => '這是關於', :parent_id => var_11.id )
|
||||
|
||||
|
||||
# TODO: modify for the new model
|
||||
|
@ -54,10 +56,10 @@ namespace :dev do
|
|||
layout.layout_parts.create!( :name => 'footer', :content => "<r:snippet name='footer' />" )
|
||||
|
||||
home = Page.create!( :i18n_variable_id => var_10.id, :layout_id => layout.id, :name => 'home', :is_published => true )
|
||||
home.page_parts.create!( :name => 'main_content', :content => "<r:locale en='This is the homepage' zh_tw='這是首頁' />" )
|
||||
home.page_parts.create!( :name => 'main_content', :content => "<r:locale en='This is the homepage' zh_tw='這是首頁' />", :kind => 'text', :i18n_variable_id => var_13.id )
|
||||
|
||||
about = Page.create!( :i18n_variable_id => var_11.id, :layout_id => layout.id, :name => 'about', :is_published => true, :parent_id => home.id )
|
||||
about.page_parts.create!( :name => 'main_content', :content => "This is about" )
|
||||
about.page_parts.create!( :name => 'main_content', :content => "<r:locale en='This is about' zh_tw='這是關於' />", :kind => 'text', :i18n_variable_id => var_14.id )
|
||||
|
||||
Link.create!( :i18n_variable_id => var_12.id, :name => 'google', :is_published => true, :parent_id => home.id, :url => 'www.google.com' )
|
||||
|
||||
|
|
|
@ -10,6 +10,14 @@ $(function () {
|
|||
}
|
||||
);
|
||||
|
||||
$('#main a.reload').live('click',
|
||||
function () {
|
||||
$.getScript(this.href);
|
||||
history.replaceState(null, document.title, this.href);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
$('.form').live('submit', function () {
|
||||
$.post(this.action, $(this).serialize(), null, 'script');
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue