From 554aa0a95d52603630f8c5e71f7e445c3eb28900 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Thu, 18 Mar 2010 17:57:26 +0800 Subject: [PATCH] Support i18n and select options user attributes, but admin edit is broken --- app/models/user_attribute.rb | 2 +- .../admin/user_attributes/_form.html.erb | 2 +- app/views/panel/users/_form.html.erb | 27 ++++++++++++++++--- lib/tasks/dev.rake | 9 ++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/models/user_attribute.rb b/app/models/user_attribute.rb index 005dfecf..481410fc 100644 --- a/app/models/user_attribute.rb +++ b/app/models/user_attribute.rb @@ -4,6 +4,6 @@ class UserAttribute key :key, String key_i18n :name, String - key_i18n :attrs, Array + key :attrs, Array end \ No newline at end of file diff --git a/app/views/admin/user_attributes/_form.html.erb b/app/views/admin/user_attributes/_form.html.erb index 05a03817..0c50f6f7 100644 --- a/app/views/admin/user_attributes/_form.html.erb +++ b/app/views/admin/user_attributes/_form.html.erb @@ -9,7 +9,7 @@ <%= hidden_field_tag "user_attribute[attrs][][key]", attr["key"] %> <%= 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"]) %> (remove)

<% end -%> diff --git a/app/views/panel/users/_form.html.erb b/app/views/panel/users/_form.html.erb index 0f14962b..f2b0f7cc 100644 --- a/app/views/panel/users/_form.html.erb +++ b/app/views/panel/users/_form.html.erb @@ -17,10 +17,29 @@

<%= ua.name %>

<% ua.attrs.each do |attr| %> -

- <%= f.label attr["name"] %> - <%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%> -

+ <% if attr["locale"] %> +

+ <%= f.label attr["name_#{I18n.locale}"] %> + <% 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 -%> +

+ <% else %> +

+ <%= 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 -%> +

+ <% end -%> <% end -%> <% end -%> diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 5069986c..74dcae48 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -6,10 +6,13 @@ namespace :dev do 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 } 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)