Support i18n and select options user attributes, but admin edit is broken
This commit is contained in:
parent
bebc51e8bb
commit
554aa0a95d
|
@ -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
|
|
@ -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 -%>
|
||||||
|
|
|
@ -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 -%>
|
||||||
|
|
|
@ -6,10 +6,13 @@ 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 },
|
||||||
|
{ :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}
|
||||||
|
])
|
||||||
|
|
||||||
UserAttribute.create!( :key => "staff", :name => "Staff", :attrs => [ { :name => "Name", :key => "name", :type => "text_field" }, { :name => "Duty", :key => "duty", :type => 'text_field' } ] )
|
|
||||||
|
|
||||||
[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,
|
||||||
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.layout.en").read)
|
:content_en => File.open("#{RAILS_ROOT}/lib/template/root.layout.en").read)
|
||||||
|
|
Reference in New Issue