".html_safe
when 'format3'
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker'),:class => 'yearpicker'})
"#{t1}
"
when 'format4'
t1 = text_field_tag("#{field_name}[datetime][date][#{i}]",(value['datetime']['date']["#{i}"] rescue nil),{:required => v['required']=='true',autocomplete: 'off',placeholder: t('ask.datepicker'),:class => 'yearpicker'})
"#{t1}
"
end
end
def ask_label(value,required='false')
label_tag(nil,value,{:class=>"control-label#{required=='true' ? ' required' : ''}"})
end
def format_checkbox(options,value,multple_choose=false)
Array(options).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
if multple_choose
if value[index1]==index1
"●#{option[I18n.locale]}"
else
"○#{option[I18n.locale]}"
end
else
if index1 == value
"●#{option[I18n.locale]}"
else
"○#{option[I18n.locale]}"
end
end
end.join(' ')
end
def show_on_front(k,v,object=nil,readonly=false,lock=false)
value = nil
if !object.nil?
value = object.custom_values[k]
if value.nil?
if k.start_with?("default@")
value = object.custom_values[k.sub(/.*@/,'')]
elsif k.start_with?("custom@")
category_id, k = k.scan(/custom@((?:(?!@).)*)@\w+/)[0][0]
if category_id==object.category_id.to_s
value = object.custom_values[k]
end
end
end
end
field_name = "#{get_input_name_for_ask}[custom_values][#{k}]"
begin
case v['type']
when 'text_field'
readonly ? value : text_field_tag(field_name,value,{:required => v['required']=='true',placeholder: v['prompt_word'][I18n.locale]})
when 'instructions'
(v['instructions'][I18n.locale].html_safe rescue "")
when 'select'
prompt_hash = v['prompt_word'][I18n.locale].blank? ? {} : {prompt: v['prompt_word'][I18n.locale]}
prompt_hash.merge(:required => v['required']=='true')
if lock
format_checkbox(v['options'],value)
else
readonly ? (v['options'][value.to_s][I18n.locale] rescue '') : select_tag(field_name,options_for_select(Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect{|index1,option| [option[I18n.locale],index1]},selected: value),prompt_hash)
end
when 'date'
if value.nil?
value = {}
end
if v['range_flag']=='true'
if readonly
format_str = "%Y/%m/%d %H:%M"
case v['format']
when 'format1'
format_str = "%Y/%m/%d %H:%M"
when 'format2'
format_str = "%Y/%m/%d"
when 'format3'
format_str = "%Y/%m"
when 'format4'
format_str = "%Y"
end
tmp = value['datetime']['date'] rescue {}
"#{DateTime.parse(tmp['0']).strftime(format_str) rescue ''}~#{DateTime.parse(tmp['1']).strftime(format_str) rescue ''}"
else
"
#{render_date_block(field_name,v,0,value)}
~
#{render_date_block(field_name,v,1,value)}
".html_safe
end
else
if readonly
format_str = "%Y/%m/%d %H:%M"
case v['format']
when 'format1'
format_str = "%Y/%m/%d %H:%M"
when 'format2'
format_str = "%Y/%m/%d"
when 'format3'
format_str = "%Y/%m"
when 'format4'
format_str = "%Y"
end
tmp = value['datetime']['date'] rescue {}
(DateTime.parse(tmp['0']).strftime(format_str) rescue '')
else
render_date_block(field_name,v,0,value)
end
end
when 'text_area'
readonly ? value : text_area_tag(field_name,value,{:required => v['required']=='true',:placeholder=> v['prompt_word'][I18n.locale],:class=>'ckeditor'})
when 'radio_button'
if value.nil?
value = {}
end
if lock
format_checkbox(v['options'],value)
else
field_name_underscre = field_name.gsub(/(\[|\])/,'_').gsub('__','_').chomp('_')
readonly ? (v['options'][value.to_s][I18n.locale] rescue '') : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
""
end.join
end
when 'checkbox'
if value.nil?
value = {}
end
if lock
format_checkbox(v['options'],value,true)
else
readonly ? value.collect{|k1,v1| Array(v['options'])[v1.to_i][1][I18n.locale]}.join(', ') : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
"#{check_box_tag("#{field_name}[#{index1}]",index1,value[index1]==index1)}#{option[I18n.locale]}"
end.join
end
when 'file'
file_value = value[0] rescue nil
file_path = value[1] rescue nil
file_required = v['required']=='true' ? 'required="required"' : ''
readonly ? "#{file_value}" : "
"
end
end
def create_delete_button_for_ask(func_name)
""
end
def page_for_askquestion(askquestion)
ann_page = nil
pages = Page.where(:module=>'ask')
pages.each do |page|
if page.categories.count ==1
if page.categories.include?(askquestion.category.id.to_s)
ann_page = page
end
end
break if !ann_page.nil?
end
if ann_page.nil?
pages.each do |page|
if page.categories.include?(askquestion.category.id.to_s)
ann_page = page
end
break if !ann_page.nil?
end
end
ann_page = pages.first if ann_page.nil?
request.protocol+(request.host_with_port+ann_page.url+'/'+askquestion.to_param).gsub('//','/') rescue "/"
end
end