add_more ok
This commit is contained in:
1 parent
58d4554b0b
commit
dafe28ffb5
12 files changed
+373
-217
No files matched your search
@@ -1,6 +1,4 @@
|
||||
#encoding: utf-8
|
||||
# require ActionView::Helpers::FormTagHelper
|
||||
|
||||
module AttributeFieldsHelper
|
||||
include ActionView::Helpers::FormTagHelper
|
||||
include ActionView::Helpers::FormOptionsHelper
|
||||
@@ -49,8 +47,8 @@ module AttributeFieldsHelper
|
||||
end
|
||||
|
||||
def render_checkbox
|
||||
|
||||
@prefiled_value ||=[]
|
||||
# @prefiled_value = @prefiled_value.keys unless @prefiled_value ==[]
|
||||
# begin
|
||||
# markup_value = eval(self.markup_value)
|
||||
# rescue
|
||||
@@ -92,8 +90,7 @@ module AttributeFieldsHelper
|
||||
end
|
||||
|
||||
def render_select
|
||||
|
||||
prompt = @panel_setting[:prompt][I18n.locale] rescue nil
|
||||
prompt = @panel_setting["initial"][I18n.locale.to_s] rescue 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 {}
|
||||
# check self[:option_list].collect{|p| [p[1][I18n.locale.to_s],p[0]]}
|
||||
@@ -102,38 +99,31 @@ module AttributeFieldsHelper
|
||||
|
||||
def render_text_area
|
||||
control_group_wrapper do |key,value|
|
||||
if(add_more and value.is_a?(Hash))
|
||||
values = value
|
||||
values.each_with_index.collect do |value,index|
|
||||
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))
|
||||
end.join.html_safe
|
||||
else
|
||||
# if(add_more and value.is_a?(Hash))
|
||||
# values = value
|
||||
# values.each_with_index.collect do |value,index|
|
||||
# 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))
|
||||
# end.join.html_safe
|
||||
# else
|
||||
value = can_muti_lang_input ? @prefiled_value[key] : @prefiled_value
|
||||
key = can_muti_lang_input ? "[#{key}]" : ""
|
||||
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))
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
def render_text_field
|
||||
control_group_wrapper do |key,value|
|
||||
control_group_wrapper do |key,value,add_more_counter|
|
||||
if(add_more)
|
||||
values = value
|
||||
result = ""
|
||||
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
|
||||
place_holder= @panel_setting["placeholder"][key]
|
||||
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")
|
||||
else
|
||||
value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
|
||||
key_field = can_muti_lang_input ? "[#{key}]" : ""
|
||||
place_holder= @panel_setting["placeholder"][key] rescue ''
|
||||
text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
|
||||
value = (can_muti_lang_input ? @prefiled_value[key] : @prefiled_value) rescue nil
|
||||
key_field = can_muti_lang_input ? "[#{key}]" : ""
|
||||
place_holder= @panel_setting["placeholder"][key] rescue ''
|
||||
text_field_tag(get_field_name_base + key_field, value,@markup_options.merge(:placeholder=>place_holder))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -147,25 +137,40 @@ protected
|
||||
result.html_safe
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
result << "<div class='tabbable'>"
|
||||
result << "<div class='tab-content'>"
|
||||
|
||||
result << "<div class='tab-content'>"
|
||||
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
|
||||
|
||||
if self.add_more
|
||||
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 << "<ul class='nav nav-pills'>"
|
||||
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))
|
||||
end
|
||||
result << "</ul>"
|
||||
link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}"
|
||||
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 << "</div>"
|
||||
# @prefiled_value.collect do |key,value|
|
||||
# result << yield(key,value)
|
||||
@@ -173,14 +178,19 @@ protected
|
||||
else
|
||||
result << yield
|
||||
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 << '<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>'
|
||||
end
|
||||
end # of loop_time
|
||||
result << "</div>"
|
||||
result << "</div>" if self.add_more
|
||||
result.html_safe
|
||||
end
|
||||
end # of def controls_wrapper(&block)
|
||||
|
||||
def control_group_wrapper(&block)
|
||||
div_class = can_muti_lang_input ? "control-group language-swich" : "control-group"
|
||||
@@ -200,6 +210,23 @@ protected
|
||||
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
|
||||
if @new_attribute
|
||||
"user[new_attribute_values][#{@index}]"
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user