add_more ok

This commit is contained in:
Matthew K. Fu JuYuan 2012-11-08 18:59:19 +08:00
parent 58d4554b0b
commit dafe28ffb5
12 changed files with 373 additions and 217 deletions

View File

@ -35,7 +35,6 @@ class Admin::UsersNewInterfaceController < ApplicationController
attribute_values = @user.attribute_values attribute_values = @user.attribute_values
attribute_values.each{|att_val| attribute_values.each{|att_val|
binding.pry if att_val.id.to_s == '5052dab52b5c49ae9d000006'
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale.to_s)}) if att_val.attribute_field.attribute.key=="profile" rescue false @profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale.to_s)}) if att_val.attribute_field.attribute.key=="profile" rescue false
} }
@ -79,7 +78,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
# @user.attribute_values.build(value) # @user.attribute_values.build(value)
# } # }
# @user.rebuild_sub_roles_from_attribute_values!(attribute_values) # @user.rebuild_sub_roles_from_attribute_values!(attribute_values)
binding.pry # binding.pry
if @user.save if @user.save
flash[:notice] = t('admin.create_success_user') flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index redirect_to :action => :index
@ -104,6 +103,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
def update def update
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.update_attributes(params[:user]) @user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values' attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key) attribute_values = params[:user].delete(attribute_values_key)

View File

@ -1,6 +1,4 @@
#encoding: utf-8 #encoding: utf-8
# require ActionView::Helpers::FormTagHelper
module AttributeFieldsHelper module AttributeFieldsHelper
include ActionView::Helpers::FormTagHelper include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::FormOptionsHelper
@ -49,8 +47,8 @@ module AttributeFieldsHelper
end end
def render_checkbox def render_checkbox
@prefiled_value ||=[] @prefiled_value ||=[]
# @prefiled_value = @prefiled_value.keys unless @prefiled_value ==[]
# begin # begin
# markup_value = eval(self.markup_value) # markup_value = eval(self.markup_value)
# rescue # rescue
@ -92,8 +90,7 @@ module AttributeFieldsHelper
end end
def render_select def render_select
prompt = @panel_setting["initial"][I18n.locale.to_s] rescue nil
prompt = @panel_setting[:prompt][I18n.locale] rescue nil
@markup_options.merge!(:prompt => prompt) unless prompt.nil? @markup_options.merge!(:prompt => prompt) unless prompt.nil?
# markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {} # markup_value = (self.markup_value.is_a?(Hash) ? self.markup_value : eval(self.markup_value) )rescue {}
# check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]} # check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]}
@ -102,38 +99,31 @@ module AttributeFieldsHelper
def render_text_area def render_text_area
control_group_wrapper do |key,value| control_group_wrapper do |key,value|
if(add_more and value.is_a?(Hash)) # if(add_more and value.is_a?(Hash))
values = value # values = value
values.each_with_index.collect do |value,index| # values.each_with_index.collect do |value,index|
place_holder= @panel_setting["placeholder"][key] # place_holder= @panel_setting["placeholder"][key]
text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder)) # text_area_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
end.join.html_safe # end.join.html_safe
else # else
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
key = can_muti_lang_input ? "[#{key}]" : "" key = can_muti_lang_input ? "[#{key}]" : ""
place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue '' place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue ''
text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder)) text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder))
end # end
end end
end end
def render_text_field def render_text_field
control_group_wrapper do |key,value| control_group_wrapper do |key,value,add_more_counter|
if(add_more) if(add_more)
values = value place_holder= @panel_setting["placeholder"][key]
result = "" text_field_tag(get_field_name_base + (key.nil? ? '' : "[][#{key}]"), value,@markup_options.merge(:placeholder=>place_holder)) + link_to( (content_tag :i,'',:class=>"icon-trash"),'#',:class=> "btn removeInput")
unless values.nil?
result = values.each_with_index.collect do |value,index|
place_holder= @panel_setting["placeholder"][key]
text_field_tag(get_field_name_base + (key.nil? ? '' : "[#{key}][#{index}]"), value.last,@markup_options.merge(:placeholder=>place_holder))
end.join.html_safe
end
result
else else
value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
key_field = can_muti_lang_input ? "[#{key}]" : "" key_field = can_muti_lang_input ? "[#{key}]" : ""
place_holder= @panel_setting["placeholder"][key] rescue '' place_holder= @panel_setting["placeholder"][key] rescue ''
text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder)) text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
end end
end end
end end
@ -147,25 +137,40 @@ protected
result.html_safe result.html_safe
end end
def controls_wrapper(&block) def controls_wrapper(&block)
result = "<div class='controls'>" loop_time = self.add_more ? @attribute_value.add_more_counter : 1
result = ''
result << "<div class='multipleInput'>" if self.add_more
result << "<div class='controls'>"
loop_time.times do |loop_counter|
if can_muti_lang_input if can_muti_lang_input
result << "<div class='tabbable'>" result << "<div class='tabbable'>"
result << "<div class='tab-content'>"
result << "<div class='tab-content'>"
VALID_LOCALES.collect do |key| VALID_LOCALES.collect do |key|
value = @prefiled_value[key.to_s] rescue nil value = @prefiled_value[key.to_s] rescue nil
div_class = ["tab-pane" ,"fade"].join(" ") div_class = ["tab-pane" ,"fade"].join(" ")
div_class << (key == I18n.locale.to_s ? " active in" : '') 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}") if self.add_more
end div_class << " input-append #{add_more_tab(:input_field,loop_counter,key)}"
# binding.pry
add_more_field_value = @prefiled_value[loop_counter][key] rescue ''
result << content_tag(:div,yield(key,add_more_field_value,loop_counter),:class=>div_class)#,:id=>"tab"+id.to_s+"_#{key}_#{loop_counter}"
else
result << content_tag(:div,yield(key,value),:class=>div_class,:id=>"tab"+id.to_s+"_#{key}")
end
end # of VALID_LOCALES.collect for tabed input
result << "</div>" result << "</div>"
result << "<ul class='nav nav-pills'>" result << "<ul class='nav nav-pills'>"
VALID_LOCALES.each do |key| VALID_LOCALES.each do |key|
result << content_tag(:li,link_to(I18n.t("langs."+key),"#tab"+id.to_s+"_#{key}",:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil)) link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}"
end result << content_tag(:li,link_to(I18n.t("langs."+key),link_entry,:data=>{:toggle=>"tab"}),:class=>(key == I18n.locale.to_s ? "active" : nil))
end # of VALID_LOCALES.collect for tabs
result << "</ul>" result << "</ul>"
result << "</div>" result << "</div>"
# @prefiled_value.collect do |key,value| # @prefiled_value.collect do |key,value|
# result << yield(key,value) # result << yield(key,value)
@ -173,14 +178,19 @@ protected
else else
result << yield result << yield
end end
if can_add_more if can_add_more and (loop_counter == loop_time-1)
temp_field_name = get_basic_field_name_base + '[temp]'
result << '<span class="help-block">' result << '<span class="help-block">'
result << '<a href="#"><i class="icon-plus-sign"></i> Add</a>' result << '<a href="#"><i class="icon-plus-sign"></i>'+I18n.t("admin.infos.add")+' </a>'
result << hidden_field_tag("#{temp_field_name}[count]",loop_time,:class=>"list_count")
result << hidden_field_tag("#{temp_field_name}[count]",get_basic_field_name_base,:class=>"field_name")
result << '</span>' result << '</span>'
end end
end # of loop_time
result << "</div>" result << "</div>"
result << "</div>" if self.add_more
result.html_safe result.html_safe
end end # of def controls_wrapper(&block)
def control_group_wrapper(&block) def control_group_wrapper(&block)
div_class = can_muti_lang_input ? "control-group language-swich" : "control-group" div_class = can_muti_lang_input ? "control-group language-swich" : "control-group"
@ -200,6 +210,23 @@ protected
end end
end end
def add_more_tab(mode,counter,key)
case mode
when :input_field
get_pairing_tab_class(:suffix=>['','tab'+counter.to_s,key].join('-'))
when :tab_btn
".#{get_pairing_tab_class(:suffix=>['','tab'+counter.to_s,key].join('-'))}"
end
end
def get_pairing_tab_class(opts)
prefix = opts[:prefix]
suffix = opts[:suffix]
str = get_basic_field_name_base.gsub("[","-").gsub("]",'')
str = prefix.nil? ? str : prefix+ str
suffix.nil? ? str : str + suffix
end
def get_basic_field_name_base def get_basic_field_name_base
if @new_attribute if @new_attribute
"user[new_attribute_values][#{@index}]" "user[new_attribute_values][#{@index}]"

View File

@ -0,0 +1,68 @@
module AttributeValuesHelper
def show_west_calender
date = get_date
case self.attribute_field["typeC"]["format"]
when 'format1' # Y/M/D h:m
date.strftime("%Y/%m/%d %H:%M")
when 'format2' # Y/M/D
date.strftime("%Y/%m/%d")
when 'format3' # Y/M
date.strftime("%Y/%m")
when 'format4' # Y
date.strftime("%Y")
end # of case west cal format
end
def show_minguo_calendar
get_minguo
date = get_date
year_str = ""
unless date.year == 1912
m_year = (date.year - 1912).abs.to_s + I18n.t("admin.infos.date.minguo_calendar.year")
year_str = minguo_format_year(m_year)
end
get_minguo_year + minguo_m_y_d_time
end
def get_minguo_year
date = get_date
m_year = (date.year - 1911).abs
year_end = I18n.t("admin.infos.date.minguo_calendar.year")
case
when date.year <1912
I18n.t("admin.infos.date.minguo_calendar.before") + (m_year+1).to_s + year_end
when date.year ==1912
I18n.t("admin.infos.date.minguo_calendar.first_year")
when date.year >1912
I18n.t("admin.infos.date.minguo_calendar.after")+ (m_year).to_s + year_end
end # of case tw_claendar year
end
def minguo_m_y_d_time
date = get_date
case self.attribute_field["typeC"]["format"]
when 'format1' # Y/M/D h:m
date.strftime(" %m/%d %H:%M")
when 'format2' # Y/M/D
date.strftime(" %m/%d")
when 'format3' # Y/M
date.strftime(" %m#{I18n.t("admin.infos.date.minguo_calendar.month")}")
when 'format4' # Y
''
end # of case
end
def get_date_by_format
case I18n.locale
when :zh_tw
case
when self.attribute_field["typeC"]["claendar"] == "west_claendar"
show_west_calender
when self.attribute_field["typeC"]["claendar"] == "tw_claendar"
show_minguo_calendar
end #case self.attribute_field["typeC"]["claendar"]
when :en
show_west_calender
end
end
end

View File

@ -13,10 +13,10 @@ class AttributeField
field :built_in, :type => Boolean, :default => false field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false
field :to_delete,:type=> Boolean,:default => false field :to_delete,:type=> Boolean,:default => false
field :typeA,:type=> Hash,:default=>{} field :typeA,:type=> Hash,:default=>{:cross_lang=>false}
field :typeB,:type=> Hash,:default=>{} field :typeB,:type=> Hash,:default=>{}
field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar"} field :typeC,:type=> Hash,:default=>{:claendar=>"west_claendar",:format=>"format3"}
field :typeD,:type=> Hash,:default=>{} field :typeD,:type=> Hash,:default=>{:cross_lang=>false}
field :typeE,:type=> Hash,:default=>{} field :typeE,:type=> Hash,:default=>{}
@ -30,6 +30,11 @@ class AttributeField
has_many :attribute_values,:autosave => true, :dependent => :destroy has_many :attribute_values,:autosave => true, :dependent => :destroy
before_save :check_option_list before_save :check_option_list
# validates_uniqueness_of :key # validates_uniqueness_of :key
def markup_value
get_data["option_list"]
end
def add_more def add_more
(get_data["add_more"] == "true" ? true : false) rescue false (get_data["add_more"] == "true" ? true : false) rescue false
end end
@ -47,11 +52,11 @@ class AttributeField
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false (self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
end end
def markup_value=(var) # def markup_value=(var)
if !self_defined_markup_options? # if !self_defined_markup_options?
self[:markup_value] = (eval(var) rescue {}) # self[:markup_value] = (eval(var) rescue {})
end # end
end # end
def option_list def option_list
if self_defined_markup_options? if self_defined_markup_options?
@ -139,6 +144,47 @@ class AttributeField
# self.list_options.to_a.join(', ') # self.list_options.to_a.join(', ')
# end # end
def add_more_convert(opt)
case opt
when :to_add_more
self.attribute_values.each do |av|
VALID_LOCALES.each do |loc|
splited_str = av[loc].split(",") rescue []
av["val"] = [] if av["val"].nil?
splited_str.each_with_index{|value,index| av["val"][index] = av["val"][index].nil? ? {loc=>value} : av["val"][index].merge(loc=>value) }
# av[loc] = Hash[splited_str.each_with_index.map{|t,index| [index.to_s,t]}] rescue {"0"=>av[loc].to_s}
end
av.save
end #of self.attribute_values.each
when :to_no_add_more
self.attribute_values.each do |av|
VALID_LOCALES.each do |loc|
if av["val"].kind_of? Array
av[loc] = av["val"].collect{|t| t[loc]}.join(",")
else
av[loc] = av["val"]
end
# av[loc] = av["val"].invert.keys.join(",") rescue av["val"]
# av.save(:validate => false)
end
av.unset("val")
av.save
end #of self.attribute_values.each
end
end
def typeA=(var)
if self["typeA"]["add_more"] != var["add_more"]
case var["add_more"]
when "true" #from no-add_more to add_more
add_more_convert(:to_add_more)
else #from add_more to no-add_more
add_more_convert(:to_no_add_more)
end # of case
end # of if
self["typeA"] = var
end
def is_built_in? def is_built_in?
self.built_in self.built_in
end end

View File

@ -1,9 +1,8 @@
class AttributeValue class AttributeValue
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes include Mongoid::MultiParameterAttributes
include AttributeValuesHelper
field :key field :key
belongs_to :attribute_field belongs_to :attribute_field
@ -14,48 +13,52 @@ class AttributeValue
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"] # NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def data_proc def add_more_counter
# binding.pry index_max = self["val"].count rescue 0
# binding.pry if self.attribute_field.markup == 'radio_button' index_max == 0 ? 1 : index_max
# if self.attribute_field
case self.attribute_field.markup
when 'text_field','text_area'
# binding.pry
self[:temp_data].each{|key,val|
self[key] = val
} unless self[:temp_data].nil?
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
else # if not locale
case self.attribute_field.markup
when 'text_field','text_area'
self["val"] = self[:temp_data]
when 'select','date','radio_button'
self["val"] = self[:temp_data]
when 'checkbox'
self["val"] = self[:temp_data].keys rescue {}
end #end of case
# end #of if self.attribute_field
self.unset('temp_data')
end end
def value def data_proc
unless self[:temp_data].nil?
case self.attribute_field.markup
when 'text_field','text_area'
if self.attribute_field.add_more
self["val"] = self["temp_data"]
else # if not add_more
self[:temp_data].each{|key,val|
self[key] = val
} if(!self.attribute_field.get_data[:cross_lang])
self["val"] = self[:temp_data] if(self.attribute_field.get_data[:cross_lang])
end # of self.attribute_field.add_more
result="" when 'select','date','radio_button'
if self.attribute_field.locale && (self.attribute_field.markup == "text_field" || self.attribute_field.markup == "text_area") self["val"] = self[:temp_data]
result= Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] when 'checkbox'
else self["val"] = self[:temp_data].keys
result = self["val"] end #end of case self.attribute_field.markup
end end # of self[:temp_data].nil?
result self.unset('temp_data')
self.unset('temp')
end #of data_proc
def value(index = nil)
result = case self.attribute_field.markup
when 'text_field','text_area'
if self.attribute_field.add_more and (self.attribute_field.markup == "text_field")
index.nil? ? self["val"] : self["val"][index]
# self.attribute_field.get_data[:cross_lang] ? Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}] : self["val"] #if !self.attribute_field.get_data[:cross_lang]
else
self.attribute_field.get_data[:cross_lang] ? self["val"] : Hash[VALID_LOCALES.collect{|lang| [lang,self[lang.to_sym]]}]
end
when 'select','date','radio_button'
self["val"]
when 'checkbox'
self["val"]
end #end of case self.attribute_field.markup
end end
def value=(value) def value=(value)
#save everything to temp_data waiting for futher process #save everything to temp_data waiting for futher process
# binding
self[:temp_data] = value self[:temp_data] = value
end end
@ -71,26 +74,31 @@ class AttributeValue
end end
end end
def get_value_by_locale(locale) def get_value_by_locale(locale,add_more_index=nil)
case self.attribute_field.markup case self.attribute_field.markup
when "text_field" when "text_field"
self.attribute_field.locale ? self[locale.to_s] : self.value case self.attribute_field.add_more
when true
add_more_index.nil? ? self.value.collect{|t| t[locale]}.join(",") : self.value(add_more_index)[locale]
when false
self.attribute_field.locale ? self[locale.to_s] : self.value
end
when "select" when "select"
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value) markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : self.attribute_field.markup_value
markup_values[self.value][locale.to_s] rescue 'NoData' markup_values[self.value][locale.to_s] rescue 'NoData'
when "text_area" when "text_area"
self.attribute_field.locale ? self[locale.to_s] : self.value self.attribute_field.locale ? self[locale.to_s] : self.value
when "date" when "date"
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil get_date_by_format
when "addr" when "addr"
self.value self.value
when "radio_button" when "radio_button"
markup_values = eval(self.attribute_field.markup_value) markup_values = self.attribute_field.markup_value
markup_values[:value][locale.to_s] markup_values[self.value][locale.to_s]
when "checkbox" when "checkbox"
markup_values = self.attribute_field.markup_value markup_values = self.attribute_field.markup_value
self[:value].keys.collect{|key| markup_values[key][locale.to_s]}.join(",") self.value.collect{|key| markup_values[key][locale.to_s]}.join(",")
when "date_durnation" when "date_durnation"
self.value self.value
else else
@ -113,5 +121,10 @@ class AttributeValue
# end # end
# end # end
# end # end
protected
def get_date
Date.new(self[:val]["(1i)"].to_i,self[:val]["(2i)"].to_i,self[:val]["(3i)"].to_i) rescue nil
end
end end

View File

@ -33,8 +33,8 @@
<label class="control-label"><%= t("admin.infos.options")%></label> <label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls"> <div class="controls">
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][multilingual]","true",attribute_field["typeA"]["multilingual"]) %> <%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][cross_lang]","true",attribute_field["typeA"]["cross_lang"]) %>
<%= t("admin.infos.multilingual")%> <%= t("admin.infos.cross_lang")%>
</label> </label>
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %> <%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %>
@ -48,7 +48,12 @@
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %> <%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %>
<%= render :partial=> "placeholder_block",:locals=>{:label_ext=>t("admin.infos.initial"),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeB][initial]"}%> <%= render :partial=> "placeholder_block",:locals=>{:label_ext=>t("admin.infos.initial"),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeB][initial]"}%>
<%= render :partial=>"list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][typeB][option_list]"} %> <% if attribute_field.self_defined_markup_options?%>
<%= render :partial=>"list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][attribute][role][statuses]"} %>
<%else #normal list%>
<%= render :partial=>"list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][typeB][option_list]"} %>
<% end #of self_defined_markup_options?%>
<% end %> <% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeC") do %> <%= content_tag :div,:class=>show_type_panel(attribute_field,"typeC") do %>
<div class="control-group"> <div class="control-group">
@ -85,8 +90,8 @@
<label class="control-label"><%= t("admin.infos.options")%></label> <label class="control-label"><%= t("admin.infos.options")%></label>
<div class="controls"> <div class="controls">
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeD][multilingual]","true",attribute_field["typeD"]["multilingual"]) %> <%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeD][cross_lang]","true",attribute_field["typeD"]["cross_lang"]) %>
<%= t("admin.infos.multilingual")%> <%= t("admin.infos.cross_lang")%>
</label> </label>
</div> </div>
</div> </div>

View File

@ -32,7 +32,7 @@
<thead class="list_head"> <thead class="list_head">
<tr> <tr>
<td><%= t('admin.key') %></td> <td><%= t('admin.key') %></td>
<td><%= t('admin.multilingual') %></td> <td><%= t('admin.cross_lang') %></td>
<% @site_valid_locales.each do |locale| %> <% @site_valid_locales.each do |locale| %>
<td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td> <td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
<% end %> <% end %>

View File

@ -20,88 +20,50 @@
<% content_for :page_specific_javascript do -%> <% content_for :page_specific_javascript do -%>
<script> <script>
// $('.site-map').masonry({ var CloneTarget ;
// itemSelector: '.map-block', var NewNode;
// columnWidth: 450,
// isAnimated: true
// });
$(document).ready(function(){
function subrole_disable_field( triggled_object, switch_value_str){
var switch_field = triggled_object.attr("for");
$("input.subrole_disable_field[for="+switch_field+"]").val(switch_value_str)
}
function checkSwitch() { $(document).ready(function(){
$(".groups").each(function() { function checkMultipleInput() {
$(this).find('.form-horizontal > .hide').length < $(this).find('.form-horizontal > div').length ? $(this).removeClass("disabled") : $(this).addClass("disabled") $(".multipleInput").each(function(i) {
}); $(this).find('.tabbable').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
}
function checkMultipleInput() {
$(".multipleInput").each(function() {
$(this).find('.controls').length==1 ? $(this).addClass("plural") : $(this).removeClass("plural")
});
}
function removeInput(){
$(".removeInput").click(function (){
$(this).parents(".controls").remove();
checkMultipleInput();
return false;
});
}
checkSwitch();
checkMultipleInput();
removeInput();
$(".help-block a").click(function (){
var $CloneTarget = $(this).parents(".controls").prev(".multipleInput").find('.controls:last');
$(this).parents(".controls").prev(".multipleInput").append($CloneTarget.clone());
$(this).parents(".controls").prev(".multipleInput").find('.controls:last input').val("");
removeInput();
checkMultipleInput();
return false;
})
$(".status select").each(function (i) {
$(this).change(function () {
$(".status option:selected").eq(i).each(function () {
if($(this).attr("value")=="alumna") {
$(this).parents(".status").nextAll(".graduated").removeClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").removeAttr("disabled");
}else{
$(this).parents(".status").nextAll(".graduated").addClass("hide");
$(this).parents(".status").nextAll(".graduated").find("select").attr({disabled:''});
}
}); });
}
function removeInput(){
$(".removeInput").live('click',function (){
$(this).parents(".tabbable").remove();
checkMultipleInput();
return false;
});
}
checkMultipleInput();
removeInput();
$(".help-block a").live('click',function (){
CloneTarget = $(this).parents(".controls").find(".tabbable:last");
NewNode = CloneTarget.clone();
var index;
NewNode.find("input").each(function(k,v){
index = CloneTarget.parents("div.control-group").find(".list_count").val();
field_name = CloneTarget.parents("div.control-group").find(".field_name").val();
ori_str = $(v).attr("name").replace(field_name,"");
lang = ori_str.match(/\[\D*\]/);
new_field_name = (field_name+"[" + (parseInt(index)+1) + "]" + lang);
$(v).attr("name",new_field_name);
$(v).val("");
})
$(this).parents("div.control-group").find(".list_count").val(parseInt(index)+1)
$(this).parents(".controls").find(".tabbable:last").after(NewNode);
removeInput();
// checkMultipleInput();
return false;
}) })
})
$('.onoff').click(function () {
if($(this).parents("h4").length==1) {
$(this).parents(".map-block").toggleClass("disabled");
$(this).parents(".map-block").find(".form-horizontal").toggleClass("hide");
if($(this).parents(".map-block").hasClass("disabled")){
$(this).text("OFF");
// console.log("LV1");
// console.log($(this));
}else{
$(this).text("ON");
// console.log("LV1");
// console.log($(this));
}
}
if($(this).parents("legend").length==1) {
$(this).toggleClass("disabled");
$(this).parents("legend").next("div").toggleClass("hide");
if($(this).parents("legend").next("div").hasClass("hide")){
$(this).text("OFF");
console.log("LV2");
subrole_disable_field($(this),"true");
}else{
$(this).text("ON");
console.log("LV2");
subrole_disable_field($(this),"false");
}
checkSwitch();
}
return false;
}); });
}) </script>
</script> </script>
<% end -%> <% end -%>

View File

@ -2,6 +2,6 @@
<% show_sub_role.attribute_fields.each do |item|%> <% show_sub_role.attribute_fields.each do |item|%>
<tr> <tr>
<td class="span1"><%= item.title %></td> <td class="span1"><%= item.title %></td>
<td><%= show_attribute_value(@user.get_attribute_value(item).get_value_by_locale(I18n.locale)) %></td> <td><%= show_attribute_value(@user.get_attribute_value(item).get_value_by_locale(I18n.locale)) rescue '' %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -100,7 +100,7 @@ zh_tw:
item_name: 資料表名稱 item_name: 資料表名稱
name: 名稱 name: 名稱
options: 選項 options: 選項
multilingual: 語言輸入 :cross_lang: 語言輸入
add_more: 使用者可自行延伸欄位 add_more: 使用者可自行延伸欄位
add: 新增 add: 新增
placeholder: 輸入協助 placeholder: 輸入協助
@ -114,6 +114,12 @@ zh_tw:
range: 本欄為時間區段 range: 本欄為時間區段
format: 格式 format: 格式
tw_claendar: 民國 tw_claendar: 民國
minguo_calendar:
after: 民國
before: 民前
first_year: 民國元年
year:
month:
west_claendar: 西元 west_claendar: 西元
access: access:
denied: denied:

View File

@ -1,5 +1,6 @@
defaults: &defaults defaults: &defaults
host: localhost host: localhost
port: 37017
# slaves: # slaves:
# - host: slave1.local # - host: slave1.local
# port: 27018 # port: 27018

View File

@ -3,6 +3,32 @@ require 'spec_helper'
describe AttributeValue do describe AttributeValue do
describe "#attribute_value" do describe "#attribute_value" do
context "Date should render out right value"
before do
@user = User.where(email:'chris@rulingcom.com').first
@af = AttributeField.last
@af.markup = "date"
@af.save
@av = @user.attribute_values.build :attribute_field=>@af
end # of before
it "should be 民前 1年" do
@av.value = {"(1i)"=>"1911", "(2i)"=>"11", "(3i)"=>"6"}
binding.pry
@av.get_value_by_locale("zh_tw").should match /^民前.*/
end
it "should be 民國元年" do
@av.value = {"(1i)"=>"1912", "(2i)"=>"11", "(3i)"=>"6"}
@av.get_value_by_locale("zh_tw").should "民國元年"
end
it "should be 民國 75年" do
@av.value ={"(1i)"=>"1913", "(2i)"=>"11", "(3i)"=>"6"}
@av.get_value_by_locale("zh_tw").should match /^民國.*/
end
context "Data should be able to input and out put as aspect" context "Data should be able to input and out put as aspect"
before do before do
@ -15,45 +41,47 @@ describe AttributeValue do
LIST[:markups].each do |markup| LIST[:markups].each do |markup|
@av = nil @av = nil
it "[#{markup[0]}]Input: should save data at right way when local is set to #{locale_sat}" do it "[#{markup[0]}]Input: should save data at right way when local is set to #{locale_sat}" do
@af.markup = markup[0] pending
@av = nil # @af.markup = markup[0]
@input_value = assume_result = case markup[0] # @av = nil
when 'text_field','text_area' # @input_value = assume_result = case markup[0]
(locale_sat ? {"en"=> "lalala","zh_tw"=>"拉拉拉"} : "hahaha") # when 'text_field','text_area'
when 'select','radio_button' # (locale_sat ? {"en"=> "lalala","zh_tw"=>"拉拉拉"} : "hahaha")
"1" # when 'select','radio_button'
when 'date' # "1"
{"(1i)"=>Date.today.year.to_s,"(2i)"=>Date.today.month.to_s,"(3i)"=>Date.today.day.to_s} # when 'date'
when 'checkbox' # {"(1i)"=>Date.today.year.to_s,"(2i)"=>Date.today.month.to_s,"(3i)"=>Date.today.day.to_s}
{"1"=>"true", "3"=>"true"} # when 'checkbox'
end #end of case # {"1"=>"true", "3"=>"true"}
assume_result = ["1","3"] if markup[0] == 'checkbox' # end #end of case
@af.locale = locale_sat # assume_result = ["1","3"] if markup[0] == 'checkbox'
@af.save # @af.locale = locale_sat
@data_hash = {"attribute_field_id" => @af.id,"value" => @input_value} # @af.save
@av = @user.attribute_values.build(@data_hash) # @data_hash = {"attribute_field_id" => @af.id,"value" => @input_value}
@av.save # @av = @user.attribute_values.build(@data_hash)
# @av.save
@av.value.should == assume_result # @av.value.should == assume_result
# @av.destroy # @av.destroy
end end
it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do
locale = I18n.locale pending
assume_result = case markup[0] # locale = I18n.locale
when 'text_area' # assume_result = case markup[0]
(locale_sat ? "拉拉拉" : "hahaha") # when 'text_area'
when 'text_field' # (locale_sat ? "拉拉拉" : "hahaha")
(locale_sat ? "拉拉拉" : "hahaha") # when 'text_field'
when 'select','radio_button' # (locale_sat ? "拉拉拉" : "hahaha")
(locale_sat ? "男性" : "男性") # when 'select','radio_button'
when 'date' # (locale_sat ? "男性" : "男性")
Date.today # when 'date'
when 'checkbox' # Date.today
(locale_sat ? "男性,不公開" : "男性,不公開") # when 'checkbox'
end #end of case # (locale_sat ? "男性,不公開" : "男性,不公開")
# end #end of case
@av.get_value_by_locale(locale).should == assume_result # @av.get_value_by_locale(locale).should == assume_result
end end
end #end of LIST loop end #end of LIST loop