From 1ce7f00084a8143714f8277a0ce2248288ce00ce Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 12 Oct 2012 18:09:02 +0800 Subject: [PATCH] new code for attribute fields and values for new member interface --- app/assets/stylesheets/member.css | 3 + app/assets/stylesheets/site-map.css | 4 +- app/controllers/admin/infos_controller.rb | 1 + .../admin/users_new_interface_controller.rb | 1 - app/helpers/application_helper.rb | 10 + app/helpers/attribute_field_helper.rb | 204 +++++++++++------- app/models/user/attribute_field.rb | 39 +++- app/models/user/attribute_value.rb | 14 +- .../attributes/_attribute_field.html.erb | 16 +- .../admin/users_new_interface/_info.html.erb | 2 - .../_temp_profile.html.erb | 2 - .../users_new_interface/_user_role.html.erb | 2 +- .../admin/users_new_interface/show.html.erb | 1 - app/views/layouts/admin.html.erb | 2 +- config/application.rb | 2 + config/list.yml | 35 ++- config/locales/zh_tw.yml | 6 +- 17 files changed, 226 insertions(+), 118 deletions(-) diff --git a/app/assets/stylesheets/member.css b/app/assets/stylesheets/member.css index 1fe9350d..d342e54b 100644 --- a/app/assets/stylesheets/member.css +++ b/app/assets/stylesheets/member.css @@ -309,4 +309,7 @@ } .user-role .staff h4 .gender { border-color: #139E2F transparent transparent #139E2F; +} +.user-role .tab-content, .user-role .tabs-right > .nav-tabs { + float: left; } \ No newline at end of file diff --git a/app/assets/stylesheets/site-map.css b/app/assets/stylesheets/site-map.css index 3e5fb511..711b10e2 100644 --- a/app/assets/stylesheets/site-map.css +++ b/app/assets/stylesheets/site-map.css @@ -12,12 +12,12 @@ border-radius: 4px; margin-bottom: 10px; } -.site-map .map-block ul { +.site-map .map-block > ul { margin: 0px; list-style: none; width: 220px \9; } -.site-map .map-block li { +.site-map .map-block li.clear { background-color: #F7F7F7; padding: 5px 15px; border-top: 1px solid #FFF; diff --git a/app/controllers/admin/infos_controller.rb b/app/controllers/admin/infos_controller.rb index 21306c6e..5ffa6a06 100644 --- a/app/controllers/admin/infos_controller.rb +++ b/app/controllers/admin/infos_controller.rb @@ -32,6 +32,7 @@ class Admin::InfosController < ApplicationController def update @attribute = Info.find(params[:id]) + # binding.pry @attribute.update_attributes(params[:info]) respond_to do |format| format.html { redirect_to :action => :index } diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 9fe40933..a2d2265c 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -47,7 +47,6 @@ class Admin::UsersNewInterfaceController < ApplicationController @staff_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="staff_data"rescue false } - # binding.pry # @user.attribute_values.each{|att_val| # @teacher_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]}) # } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7be0e2d7..718fbbc5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,6 +2,16 @@ module ApplicationHelper FLASH_NOTICE_KEYS = [:error, :notice, :warning] + def show_attribute_value(value) + if value.kind_of? Hash + result = [] + value.each{|t| result.push(t.last)} + result.join "," + else + value + end + end + def create_guest_user u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(99)}@example.com") u.admin = false diff --git a/app/helpers/attribute_field_helper.rb b/app/helpers/attribute_field_helper.rb index 9d0999da..9723241f 100644 --- a/app/helpers/attribute_field_helper.rb +++ b/app/helpers/attribute_field_helper.rb @@ -1,3 +1,4 @@ +#encoding: utf-8 # require ActionView::Helpers::FormTagHelper module AttributeFieldHelper @@ -5,6 +6,7 @@ module AttributeFieldHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::DateHelper include ActionView::Helpers::TagHelper + include ActionView::Helpers::RenderingHelper def block_helper(user,index) @index = index @@ -16,114 +18,124 @@ module AttributeFieldHelper return instance_eval("render_#{markup}") #rescue "" end - def render_text_area - result = "" - result << label - if self.locale? - @prefiled_value.each do |key,value| - result << controls_wrapper{text_area_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} - end - else - value = @prefiled_value - result << controls_wrapper{text_area_tag(get_field_name_base, value, {})} - end - result << end_block - result.html_safe + def lang_tab(str,lang) + content_tag(:div,str,:class=>"tab-pane fade",:id=>(get_field_name_base+"tab_#{lang}")) end - def render_radio_button - result = "" - result << label - markup_value.each do |key,value| - result << controls_wrapper{label_tag(key,radio_button_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],:class=>"control-label")} + def render_address + control_group_wrapper do |key,value| + result = '
'.html_safe + + if(add_more and value.is_a?(Array)) + values = value + result << values.each_with_index.collect do |value,index| + text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options) + end.join.html_safe + else + result << text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options) + end + + result << ('').html_safe + result << ''.html_safe + result << '
'.html_safe + result << gen_modal_dialog end - result << end_block - result.html_safe end def render_checkbox - # label+ "" + end_block - # check_box_tag(name, value = "1", checked = false, options = {}) - - result = "" - result << label - markup_value.each do |key,value| - result << controls_wrapper{label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],:class=>"control-label")} - end - result << end_block - result.html_safe - - end - - def render_date_durnation control_group_wrapper do - if @new_attribute - @prefiled_value = {} - end - label+controls_wrapper{date_select(get_field_name_base+"[value][from]",@prefiled_value["from"]) +date_select(get_field_name_base+"[value][end]",@prefiled_value["end"])} + end_block + markup_value.collect do |key,value| + label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label")) + end.join rescue "" end end - def render_text_field_ext - result = "" - result << label - if self.locale? - @prefiled_value.each do |key,value| - result << controls_wrapper{text_field_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} - end - else - value = @prefiled_value - result << controls_wrapper{text_field_tag(get_field_name_base, value, {})} + def render_date + control_group_wrapper{date_select(get_field_name_base+"[value]",@prefiled_value,markup_options,:class=>"input-small")} + end + + def render_date_durnation #Need re-write low priority + + end + + def render_radio_button + control_group_wrapper do + markup_value.collect do |key,value| + label_tag(key,radio_button_tag(get_field_name_base, value[I18n.locale.to_s], (@prefiled_value==value ? true : false), {})+value[I18n.locale.to_s],markup_options.merge(:class=>"control-label")) + end.join rescue "" end - result << end_block - result.html_safe end - - def render_date - label+controls_wrapper{date_select(get_field_name_base+"[value]",@prefiled_value)} + end_block + def render_select + control_group_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value),markup_options)} rescue "" end - def render_select - label+controls_wrapper{select_tag( get_field_name_base+"[value]",options_for_select(markup_value.collect{|p| [p[1][I18n.locale.to_s],p[0]]},@prefiled_value))} + end_block + def render_text_area + control_group_wrapper{|key,value|text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options)} end def render_text_field - result = "" - result << label - if self.locale? - @prefiled_value.each do |key,value| - result << controls_wrapper{text_field_tag("#{get_field_name_base}[#{key.to_s}]", value, {})} - end - else - value = @prefiled_value - result << controls_wrapper{text_field_tag(get_field_name_base, value, {})} + control_group_wrapper do |key,value| + if(add_more and value.is_a?(Hash)) + values = value + values.each_with_index.collect do |value,index| + text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,markup_options) + end.join.html_safe + else + text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}]"), value,markup_options) end - result << end_block - result.html_safe end - - def render_email - label+controls_wrapper{email_field_tag(get_field_name_base, value, {})}+ end_block - end - - def render_addr - label+controls_wrapper{text_field_tag(get_field_name_base, value, {})} + end_block - end - +end protected + def lang_panel_control_wrapper(&block) + result = '
' + result << '
' + result << controls_wrapper{yield} + result << '
' + result << '
' + result.html_safe + end def controls_wrapper(&block) result = "
" - result << yield + if can_muti_lang_input + result << "
" + result << "
" + VALID_LOCALES.collect do |key| + value = @prefiled_value[key.to_s] rescue nil + div_class = ["tab-pane" ,"fade"].join(" ") + div_class << (key == I18n.locale.to_s ? " active in" : '') + result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}") + end + result << "
" + result << "" + result << "
" + # @prefiled_value.collect do |key,value| + # result << yield(key,value) + # end + else + result << yield + end + if can_add_more + result << '' + result << ' Add' + result << '' + end result << "
" result.html_safe end - def control_group_wrapper(&block) - result = "
" - result << yield - result << "
" + def control_group_wrapper(&block) + div_class = can_muti_lang_input ? "control-group language-swich" : "control-group" + temp = label + controls_wrapper(&block) + + result = content_tag(:div,temp,:class=>div_class) + result << end_block + result.html_safe end @@ -148,4 +160,36 @@ protected label_tag(key,title,:class=>"control-label") end + def can_muti_lang_input + locale and LIST[:markups][markup]["muti_lang_input_supprt"] + end + + def can_add_more + locale and LIST[:markups][markup]["ext_support"] && add_more + end + +def render_anywhere(partial, assigns) + view = ActionView::Base.new(Rails::Configuration.new.view_path, assigns) + ActionView::Base.helper_modules.each { |helper| view.extend helper } + view.extend ApplicationHelper + view.render(:partial => partial) +end + +def gen_modal_dialog + result = '' + result.html_safe +end + end \ No newline at end of file diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index 826627eb..d7b21414 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -5,12 +5,15 @@ class AttributeField include AttributeFieldHelper field :key - field :markup #[select,text_field,email,date,addr] + field :markup field :markup_value ,:type => Hash + field :markup_options,:type => Hash field :locale, :type => Boolean, :default => true - field :list_options, :type => Array + # field :list_options, :type => Array field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false + field :add_more,:type => Boolean, :default => false + #field :title, localize: true field :locale_title, localize: true @@ -21,6 +24,20 @@ class AttributeField has_many :attribute_values # validates_uniqueness_of :key + + def markup_options=(var) + self[:markup_options] = (eval(var) rescue {}) + end + + def markup_options + if self[:markup_options].nil? + return {} + else + Hash[self[:markup_options].map{|key,val|[key.to_sym,val]}] rescue {} + end + + end + def role self.attribute.role end @@ -46,7 +63,7 @@ class AttributeField return self.neutral_title end end - + def title=(var) # binding.pry if locale @@ -56,15 +73,15 @@ class AttributeField end end - # Convert the string list_options into an array - def select_list_options=(var) - self.list_options = var.gsub(' ', '').split(',') - end + # # Convert the string list_options into an array + # def select_list_options=(var) + # self.list_options = var.gsub(' ', '').split(',') + # end - # Convert the array list_options into a string - def select_list_options - self.list_options.to_a.join(', ') - end + # # Convert the array list_options into a string + # def select_list_options + # self.list_options.to_a.join(', ') + # end def is_built_in? self.built_in diff --git a/app/models/user/attribute_value.rb b/app/models/user/attribute_value.rb index 49014e2a..efef05c1 100644 --- a/app/models/user/attribute_value.rb +++ b/app/models/user/attribute_value.rb @@ -11,7 +11,7 @@ class AttributeValue before_save :check_key - NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] + # NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] def check_key self.key = attribute_field.key @@ -31,19 +31,25 @@ class AttributeValue self.attribute_field.locale ? self[locale] : self[:value] when "select" self.attribute_field.markup_value[self[:value]][locale.to_s] || NoData - when "email" - self[:value] + when "text_area" + #self[:value] when "date" Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) when "addr" self[:value] + when "radio_button" + self[:value] + when "checkbox" + self[:value] + when "date_durnation" + self[:value] else self.attribute_field.locale ? self[locale] : self[:value] end end def get_values - if self.attribute_field.locale && !(NO_MULTI_TAG.include? self.attribute_field.markup) + if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"] return Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] else return self[:value] diff --git a/app/views/admin/attributes/_attribute_field.html.erb b/app/views/admin/attributes/_attribute_field.html.erb index 5111f015..58236e36 100644 --- a/app/views/admin/attributes/_attribute_field.html.erb +++ b/app/views/admin/attributes/_attribute_field.html.erb @@ -11,10 +11,18 @@ diff --git a/app/views/admin/users_new_interface/_info.html.erb b/app/views/admin/users_new_interface/_info.html.erb index d821b209..24b0d976 100644 --- a/app/views/admin/users_new_interface/_info.html.erb +++ b/app/views/admin/users_new_interface/_info.html.erb @@ -3,9 +3,7 @@
<% info.attribute_fields.each do |af|%> -
<%= af.block_helper(@user,@form_index)%> -
<% @form_index = @form_index +1 %> <% end %> diff --git a/app/views/admin/users_new_interface/_temp_profile.html.erb b/app/views/admin/users_new_interface/_temp_profile.html.erb index 7791030e..7112f994 100644 --- a/app/views/admin/users_new_interface/_temp_profile.html.erb +++ b/app/views/admin/users_new_interface/_temp_profile.html.erb @@ -1,9 +1,7 @@ <%= temp_profile.title %> <% temp_profile.attribute_fields.each do |af|%> -
<%= af.block_helper(@user,@form_index)%> -
<% @form_index = @form_index +1 %> <% end %> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/_user_role.html.erb b/app/views/admin/users_new_interface/_user_role.html.erb index 05ef4bb1..fd47de60 100644 --- a/app/views/admin/users_new_interface/_user_role.html.erb +++ b/app/views/admin/users_new_interface/_user_role.html.erb @@ -8,7 +8,7 @@ <% items.each do |item| %> <%= item[:name] %> - <%= item[:value] %> + <%= show_attribute_value(item[:value]) %> <% end -%> diff --git a/app/views/admin/users_new_interface/show.html.erb b/app/views/admin/users_new_interface/show.html.erb index 03aff8d4..41fb84a3 100644 --- a/app/views/admin/users_new_interface/show.html.erb +++ b/app/views/admin/users_new_interface/show.html.erb @@ -18,7 +18,6 @@
- <% #binding.pry%> <%= render :partial=> 'plugin_summary'%> <%= render :partial=> 'plugin_summary'%> <%= render :partial=> 'plugin_summary'%> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 3c2df376..78673abf 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -31,7 +31,7 @@ <%= yield %>
<%= yield :tertiary %>
- + diff --git a/config/application.rb b/config/application.rb index 9faef5d4..f5e0a078 100644 --- a/config/application.rb +++ b/config/application.rb @@ -68,3 +68,5 @@ module Orbit end Orbit_Apps = [] VALID_LOCALES = ["en", "zh_tw"] + + diff --git a/config/list.yml b/config/list.yml index 7e8d7567..7d1c2ad4 100644 --- a/config/list.yml +++ b/config/list.yml @@ -3,15 +3,34 @@ forbidden_item_names: - panel - appfront +#NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] + markups: - - text_field - - select - - date - - text_area #NC - - radio_button #NC - - checkbox #NC - - date_durnation #NC - - text_field_ext #NC for addr for phone + text_field: + muti_lang_input_supprt: true + ext_support: true + select: + muti_lang_input_supprt: false + ext_support: false + date: + muti_lang_input_supprt: false + ext_support: false + text_area: + muti_lang_input_supprt: true + ext_support: false + radio_button: + muti_lang_input_supprt: false + ext_support: false + checkbox: + muti_lang_input_supprt: false + ext_support: false + date_durnation: + muti_lang_input_supprt: false + ext_support: false + address: + muti_lang_input_supprt: true + ext_support: true + public_r_tags: - ad_banner diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index b56dd33b..ff07a5f6 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -24,6 +24,9 @@ zh_tw: help: 協助 hide: 隱藏 homepage: 首頁 + langs: + zh_tw: 中文 + en: 英文 login: 登入 logout: 登出 nccu: 政大 @@ -558,6 +561,7 @@ zh_tw: update: "更新%{model}" submit: "儲存%{model}" modal: + save_and_close: "儲存並關閉" close: "關閉" preview: "預覽" sys: @@ -568,4 +572,4 @@ zh_tw: module_page_lang_not_support: "很抱歉,本頁沒有開放中文版本" object_disable: change_to_true: "設為停用" - change_to_false: "重新啓用" + change_to_false: "重新啓用" \ No newline at end of file