This commit is contained in:
BoHung Chiu 2023-02-10 13:34:07 +08:00
parent 3177cd48f8
commit 274ea9c71a
6 changed files with 33 additions and 16 deletions

View File

@ -158,10 +158,11 @@ module Admin::AsksHelper
def field_radio_button_tag(index1,field,show_value,checked,custom_options={}) def field_radio_button_tag(index1,field,show_value,checked,custom_options={})
radio_button_tag("#{get_input_name_for_ask}[#{index1}][#{field}]",show_value,checked,custom_options) radio_button_tag("#{get_input_name_for_ask}[#{index1}][#{field}]",show_value,checked,custom_options)
end end
def render_date_block(field_name,v,i,value) def render_date_block(field_name,v,i,value, prefix_contents="")
case v['format'] case v['format']
when 'format1' when 'format1'
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'),title: t('ask.datepicker'),style:'width:100%;'}) 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'),title: t('ask.datepicker')})
t1 = prefix_contents + t1
#t2_value = value['datetime']['h']["#{i}"] rescue nil #t2_value = value['datetime']['h']["#{i}"] rescue nil
#t3_value = value['datetime']['m']["#{i}"] rescue nil #t3_value = value['datetime']['m']["#{i}"] rescue nil
#t2 = select_tag("#{field_name}[datetime][h][#{i}]",options_for_select((1..24).collect{|v1| v1.to_s.rjust(2, "0")},selected: t2_value)) #t2 = select_tag("#{field_name}[datetime][h][#{i}]",options_for_select((1..24).collect{|v1| v1.to_s.rjust(2, "0")},selected: t2_value))
@ -175,6 +176,7 @@ module Admin::AsksHelper
</script>".html_safe </script>".html_safe
when 'format2' when 'format2'
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'),title: t('ask.datepicker')}) 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'),title: t('ask.datepicker')})
t1 = prefix_contents + t1
"<div class=\"datetime_selector\">#{t1}</div> "<div class=\"datetime_selector\">#{t1}</div>
<script> <script>
jQuery(document).ready(function( $ ) { jQuery(document).ready(function( $ ) {
@ -183,7 +185,8 @@ module Admin::AsksHelper
</script>".html_safe </script>".html_safe
when 'format3' 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'),title: t('ask.datepicker'),:class => 'yearpicker'}) 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'),title: t('ask.datepicker'),:class => 'yearpicker'})
"#{t1} t1 = prefix_contents + t1
"<div class=\"datetime_selector\">#{t1}</div>
<script> <script>
jQuery(document).ready(function( $ ) { jQuery(document).ready(function( $ ) {
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy-mm',show_view: 'month'}); $(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy-mm',show_view: 'month'});
@ -192,7 +195,8 @@ module Admin::AsksHelper
" "
when 'format4' 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'),title: t('ask.datepicker'),:class => 'yearpicker'}) 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'),title: t('ask.datepicker'),:class => 'yearpicker'})
"#{t1} t1 = prefix_contents + t1
"<div class=\"datetime_selector\">#{t1}</div>
<script> <script>
jQuery(document).ready(function( $ ) { jQuery(document).ready(function( $ ) {
$(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy',show_view: 'year'}); $(\"input[name='#{field_name}[datetime][date][#{i}]']\").ui_datepicker({dateFormat: 'yy',show_view: 'year'});
@ -278,9 +282,9 @@ module Admin::AsksHelper
"#{DateTime.parse(tmp['0']).strftime(format_str) rescue ''}~#{DateTime.parse(tmp['1']).strftime(format_str) rescue ''}" "#{DateTime.parse(tmp['0']).strftime(format_str) rescue ''}~#{DateTime.parse(tmp['1']).strftime(format_str) rescue ''}"
else else
"<div style=\"display:inline-flex;flex-direction:column;\"> "<div style=\"display:inline-flex;flex-direction:column;\">
#{render_date_block(field_name,v,0,value)} #{render_date_block(field_name,v,0,value, t('ask.start') + ': ')}
<div style=\"display: inline-flex;align-items: center;writing-mode: tb-rl;padding: 0.3em;\">~</div> <div style=\"display: inline-flex;align-items: center;writing-mode: tb-rl;padding: 0.3em;\">~</div>
#{render_date_block(field_name,v,1,value)} #{render_date_block(field_name,v,1,value, t('ask.end') + ': ')}
</div>".html_safe </div>".html_safe
end end
else else

View File

@ -160,13 +160,14 @@ class AskSetting
end end
return sort_number return sort_number
end end
is_default_setting = (ask_setting.class == self)
if override_sort_number.present? if override_sort_number.present?
sort_number = override_sort_number sort_number = override_sort_number
else else
sort_number = ask_setting.sort_number sort_number = ask_setting.sort_number
if ask_setting.use_default if ask_setting.use_default
if ask_setting.default_sort_number.blank? if ask_setting.default_sort_number.blank?
sort_number = ((ask_setting.class == self) ? sort_number : self.first.sort_number) sort_number = (is_default_setting ? sort_number : self.first.sort_number)
else else
sort_number = ask_setting.default_sort_number sort_number = ask_setting.default_sort_number
end end
@ -174,7 +175,7 @@ class AskSetting
ask_setting = self.first ask_setting = self.first
end end
end end
default_ask_setting = ask_setting.class == self ? ask_setting : self.first default_ask_setting = is_default_setting ? ask_setting : self.first
disp_fields = self::All_default_fields disp_fields = self::All_default_fields
disp_fields_infos = {} disp_fields_infos = {}
locale = I18n.locale.to_s locale = I18n.locale.to_s
@ -222,10 +223,12 @@ class AskSetting
end end
max_sort_number = disp_fields_infos.values.map{|v| v}.compact.max max_sort_number = disp_fields_infos.values.map{|v| v}.compact.max
if max_sort_number if max_sort_number
max_sort_number = max_sort_number + 1 if !use_cache || (is_default_setting && override_sort_number.nil?)
disp_fields_infos.each_with_index do |(k,v), i| max_sort_number = max_sort_number + 1
if v.blank? disp_fields_infos.each_with_index do |(k,v), i|
disp_fields_infos[k] = max_sort_number + i if v.blank?
disp_fields_infos[k] = max_sort_number + i
end
end end
end end
disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value}.to_h disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value}.to_h
@ -245,6 +248,7 @@ class AskSetting
ask_setting = self.first if ask_setting.nil? ask_setting = self.first if ask_setting.nil?
ask_setting = self.create() if ask_setting.nil? ask_setting = self.create() if ask_setting.nil?
end end
is_default_setting = (ask_setting.class == self)
sort_number = nil sort_number = nil
if only_display && use_cache if only_display && use_cache
if override_sort_number if override_sort_number
@ -259,7 +263,7 @@ class AskSetting
sort_number = override_sort_number sort_number = override_sort_number
elsif ask_setting.use_default elsif ask_setting.use_default
if ask_setting.default_sort_number.blank? if ask_setting.default_sort_number.blank?
sort_number = ((ask_setting.class == self) ? sort_number : self.first.sort_number) sort_number = (is_default_setting ? sort_number : self.first.sort_number)
else else
sort_number = ask_setting.default_sort_number sort_number = ask_setting.default_sort_number
end end
@ -267,7 +271,7 @@ class AskSetting
ask_setting = self.first ask_setting = self.first
end end
end end
default_ask_setting = ask_setting.class == self ? ask_setting : self.first default_ask_setting = is_default_setting ? ask_setting : self.first
disp_fields = self::All_default_fields disp_fields = self::All_default_fields
disp_fields_infos = {} disp_fields_infos = {}
locale = I18n.locale.to_s locale = I18n.locale.to_s
@ -331,7 +335,7 @@ class AskSetting
end end
max_sort_number = disp_fields_infos.values.map{|h| h["sort_number"]}.compact.max max_sort_number = disp_fields_infos.values.map{|h| h["sort_number"]}.compact.max
if max_sort_number if max_sort_number
unless use_cache if !use_cache || (is_default_setting && override_sort_number.nil?)
max_sort_number = max_sort_number + 1 max_sort_number = max_sort_number + 1
disp_fields_infos.each_with_index do |(k,h), i| disp_fields_infos.each_with_index do |(k,h), i|
if h["sort_number"].blank? if h["sort_number"].blank?

View File

@ -66,7 +66,9 @@
.ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{ .ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{
width: 97%; width: 97%;
} }
.ask-question .form-horizontal input[type="text"].hasDatepicker{
width: auto;
}
.ask-question .form-horizontal .form-actions{ .ask-question .form-horizontal .form-actions{
position: relative; position: relative;
padding: 1em 0 0 0; padding: 1em 0 0 0;

View File

@ -2,6 +2,8 @@ en:
situation: Status situation: Status
sex: Sex sex: Sex
ask: ask:
start: "Start"
end: "End"
options: "Options" options: "Options"
please_select: '--Please Select--' please_select: '--Please Select--'
default_option: Default Option default_option: Default Option

View File

@ -6,6 +6,8 @@ zh_tw:
errors: errors:
verification_failed: 驗證碼錯誤 verification_failed: 驗證碼錯誤
ask: ask:
start: "開始"
end: "結束"
options: "選項" options: "選項"
please_select: '--請選擇--' please_select: '--請選擇--'
default_option: 預設選項 default_option: 預設選項

View File

@ -41,6 +41,9 @@
.ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{ .ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{
width: 97%; width: 97%;
} }
.ask-question .form-horizontal input[type="text"].hasDatepicker{
width: auto;
}
.ask-question .form-horizontal .form-actions{ .ask-question .form-horizontal .form-actions{
position: relative; position: relative;
padding: 1em 0 0 0; padding: 1em 0 0 0;