Support i18n and select options user attributes, but admin edit is broken

This commit is contained in:
Wen-Tien Chang 2010-03-18 17:57:26 +08:00
parent bebc51e8bb
commit 554aa0a95d
4 changed files with 31 additions and 9 deletions

View File

@ -4,6 +4,6 @@ class UserAttribute
key :key, String key :key, String
key_i18n :name, String key_i18n :name, String
key_i18n :attrs, Array key :attrs, Array
end end

View File

@ -9,7 +9,7 @@
<label><%= attr["key"] %></label> <label><%= attr["key"] %></label>
<%= hidden_field_tag "user_attribute[attrs][][key]", attr["key"] %> <%= hidden_field_tag "user_attribute[attrs][][key]", attr["key"] %>
<%= text_field_tag "user_attribute[attrs][][name]", attr["name"] %> <%= text_field_tag "user_attribute[attrs][][name]", attr["name"] %>
<%= select_tag "user_attribute[attrs][][type]", options_for_select(["text_field"], attr["type"]) %> <%= select_tag "user_attribute[attrs][][type]", options_for_select(["text_field", "select"], attr["type"]) %>
<a href="#" class="remove">(remove)</a> <a href="#" class="remove">(remove)</a>
</p> </p>
<% end -%> <% end -%>

View File

@ -17,10 +17,29 @@
<h3><%= ua.name %></h3> <h3><%= ua.name %></h3>
<% ua.attrs.each do |attr| %> <% ua.attrs.each do |attr| %>
<p> <% if attr["locale"] %>
<%= f.label attr["name"] %> <p>
<%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%> <%= f.label attr["name_#{I18n.locale}"] %>
</p> <% if attr["type"] == "text_field" %>
<% VALID_LOCALES.each do |locale| %>
<%= f.text_field "#{ua.key}_#{attr["key"]}_#{locale}" %>(<%= locale %>)
<% end -%>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}_#{I18n.locale}", attr["options_#{I18n.locale}"].to_a %>
<% end -%>
</p>
<% else %>
<p>
<%= f.label attr["name"] %>
<% if attr["type"] == "text_field" %>
<%= f.text_field "#{ua.key}_#{attr["key"]}" %>
<% elsif attr["type"] == "select" %>
<%= f.select "#{ua.key}_#{attr["key"]}", attr["options"].to_a %>
<% end -%>
</p>
<% end -%>
<% end -%> <% end -%>
</div> </div>
<% end -%> <% end -%>

View File

@ -6,9 +6,12 @@ namespace :dev do
User.create!( :email => 'ihower@rulingcom.com', :password => 'password', :password_confirmation => 'password', :use_attributes => ["teacher"] ) User.create!( :email => 'ihower@rulingcom.com', :password => 'password', :password_confirmation => 'password', :use_attributes => ["teacher"] )
UserAttribute.create!( :key => "teacher", :name => "Teacher", :attrs => [ { :name => "Name", :key => "name", :type => "text_field" }, { :name => "Title", :key => "title", :type => 'text_field' } ] ) UserAttribute.create!( :key => "teacher", :name => "Teacher", :attrs => [
{ :name => "Name", :key => "name", :type => "text_field", :locale => false },
UserAttribute.create!( :key => "staff", :name => "Staff", :attrs => [ { :name => "Name", :key => "name", :type => "text_field" }, { :name => "Duty", :key => "duty", :type => 'text_field' } ] ) { :name => "Title", :key => "title", :type => 'select', :options => [ ["Professor","1"], ["Associate Professor","2"], ["Doctor","3"] ], :locale => false } ,
{ :name_en => "Discipline", :name_zh_tw => "授課領域", :key => "discipline", :type => "text_field", :locale => true },
{ :name_en => "Category", :name_zh_tw => "類別", :key => "category", :type => 'select', :options_en => [ ["Class1","1"], ["Class2","2"] ], :options_zh_tw => [ ["類別一","1"], ["類別二","2"] ], :locale => true}
])
[Announcement, Item, Snippet, Layout].each { |m| m.delete_all } [Announcement, Item, Snippet, Layout].each { |m| m.delete_all }
Layout.create!( :name => 'root', :description => 'root', :content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.layout.zh_tw").read, Layout.create!( :name => 'root', :description => 'root', :content_zh_tw => File.open("#{RAILS_ROOT}/lib/template/root.layout.zh_tw").read,