Fix bug (fix order and select field required not working). Add Default option for select field.

This commit is contained in:
BoHung Chiu 2023-02-07 19:44:05 +08:00
parent 0e9168634f
commit 3177cd48f8
10 changed files with 413 additions and 155 deletions

View File

@ -50,9 +50,13 @@
border-top: 1px solid #d7dadb;
/*padding: 1em 0 0 20em;*/
}
.ask-question-form .form-actions input, .ask-question-form .form-actions a{
.ask-question-form .form-actions input, .ask-question-form .form-actions a {
float: right;
}
.ask-question-form .form-actions [type="reset"] {
float: right;
margin-right: 1em;
}
/*驗證碼*/
.text-error {
color: #b94a48;

View File

@ -26,7 +26,6 @@ class Admin::AsksController < OrbitAdminController
@set = AskCategoryPrintSetting.where(:category_id=>@category_id).first
@set = AskPrintSetting.first if @set.nil?
end
@set = AskPrintSetting.create if @set.nil?
@url = print_setting_save_admin_asks_path
end
def print_setting_save
@ -145,7 +144,6 @@ class Admin::AsksController < OrbitAdminController
end
end
def index
AskPrintSetting.create() if AskPrintSetting.first.nil?
@ask_setting = AskSetting.first
prepare_category_select
category_id = @category_id.present? ? @category_id : nil
@ -486,8 +484,9 @@ class Admin::AsksController < OrbitAdminController
ask_setting = AskCategorySetting.where(:category_id=>params[:category]).first
use_default = ask_setting && ask_setting.use_default
sort_number = params[:sort_number].map{|k,v| [k,v.to_i]}.to_h
if params[:category].present? && !use_default
if params[:category].present?
if ask_setting.nil?
use_default = true
default_setting = AskSetting.first
ask_setting = AskCategorySetting.create(category_id: params[:category])
p1 = default_setting.get_attrs
@ -496,50 +495,58 @@ class Admin::AsksController < OrbitAdminController
p1['reject_customs'] = []
p1['custom_fields'] = p1['custom_fields'].map{|k,v| ["default@#{k}", v]}.to_h rescue {}
ask_setting.update_attributes(p1)
ask_setting.update(:use_default => true)
ask_setting.update(:use_default => use_default)
ask_setting_index = AskCategorySettingIndex.where(category_id: params[:category]).first
ask_setting_index = AskCategorySettingIndex.create(category_id: params[:category]) if ask_setting_index.nil?
ask_setting_index.key = default_setting.custom_fields.keys[-1].to_i rescue 0
ask_setting_index.save
end
ask_setting.update(:sort_number=> sort_number)
default_ask_setting = AskSetting.first
default_sort_number = default_ask_setting.sort_number
ask_setting_id = ask_setting.id.to_s
part_sort_number = sort_number.select{|k,v| k.start_with?('default@')}.map{|k,v| tmp=k.split('@')[1..-1].join('@');[(tmp.start_with?('default@') ? tmp : "custom@#{ask_setting_id}@#{tmp}"), v]}.to_h
intersect_keys = default_sort_number.keys & part_sort_number.keys
non_intersect_keys = part_sort_number.keys - default_sort_number.keys
if intersect_keys.count != 0
org_order = intersect_keys.map{|k| [k, default_sort_number[k]]}.sort_by{|k,v| v}.to_h
default_sort_number = default_sort_number.merge(org_order.sort_by{|k, v| part_sort_number[k]}.map{|k,v| k}.zip(org_order.values).to_h)
if use_default
ask_setting.update(:default_sort_number=> sort_number)
else
sort_number_was = AskSetting.get_sort_number_only(false, ask_setting, true).merge(ask_setting.sort_number.to_h)
ask_setting.update(:sort_number=> sort_number)
default_ask_setting = AskSetting.first
last_fields = ["recaptcha", "usage_rule", "agree_show", "agree_usage"]
default_sort_number = AskSetting.get_sort_number_only(false, default_ask_setting, true).select{|k,v| k.exclude?('@') && last_fields.exclude?(k)}.map.with_index{|(k,v), i| [k, i]}.to_h.merge(default_ask_setting.sort_number)
ask_setting_id = ask_setting.id.to_s
sort_number_changed = (sort_number.map.with_index{|(k,v), i| [k,i]} - sort_number_was.map.with_index{|(k,v), i| [k,i]}).to_h
part_sort_number = sort_number_changed.select{|k,v| k.start_with?('default@')}.map{|k,v| tmp=k.split('@')[1..-1].join('@');[(tmp.start_with?('default@') ? tmp : "custom@#{ask_setting_id}@#{tmp}"), v]}.to_h
intersect_keys = part_sort_number.keys & default_sort_number.keys
non_intersect_keys = (part_sort_number.keys - default_sort_number.keys).select{|k| k.exclude?('default@')}
if intersect_keys.count != 0
org_order = intersect_keys.map{|k| [k, default_sort_number[k]]}.sort_by{|k,v| v}.to_h
default_sort_number = default_sort_number.merge(org_order.sort_by{|k, v| part_sort_number[k]}.map{|k,v| k}.zip(org_order.values).to_h)
end
preserve_count = AskSetting::All_default_fields.count
if non_intersect_keys.count != 0
max_sort_number = default_sort_number.map{|k,v| v.to_i}.max.to_i
max_sort_number += 1
max_sort_number += preserve_count
part_sort_number = non_intersect_keys.map.with_index{|(k,v), i| [k, max_sort_number + i]}
default_sort_number = default_sort_number.merge(part_sort_number.to_h)
end
default_ask_setting.update(:sort_number=>default_sort_number)
end
preserve_count = AskSetting::All_default_fields.count
if non_intersect_keys.count != 0
max_sort_number = default_sort_number.map{|k,v| v.to_i}.max.to_i
max_sort_number += 1
max_sort_number += preserve_count
part_sort_number = non_intersect_keys.map.with_index{|(k,v), i| [k, max_sort_number + i]}
default_sort_number = default_sort_number.merge(part_sort_number.to_h)
end
default_ask_setting.update(:sort_number=>default_sort_number)
else
ask_setting = AskSetting.first
if use_default
sort_number = ask_setting.sort_number.merge(sort_number)
end
AskSetting.update_all(:sort_number=>sort_number)
original_sort_info = AskSetting.get_sort_number_only(false, ask_setting, true)
sort_number_was = original_sort_info.merge(ask_setting.sort_number.to_h)
sort_number_changed = (sort_number.map.with_index{|(k,v), i| [k,i]} - sort_number_was.map.with_index{|(k,v), i| [k,i]}).to_h
ask_setting.update(:sort_number=>sort_number)
unless use_default
default_customs_sort_number = sort_number.select{|k, v| k.start_with?('default@')}.map{|k,v| ["default@#{k}",v]}
default_customs_sort_number = sort_number_changed.select{|k, v| k.start_with?('default@')}.map{|k,v| ["default@#{k}",v]}
custom_sort_number = sort_number.select{|k, v| k.start_with?('custom@')}
all_custom_sort_numbers = custom_sort_number.group_by{|k, v| k.split('@')[1]}
preserve_count = AskSetting::All_default_fields.count
last_fields = ["recaptcha", "usage_rule", "agree_show", "agree_usage"]
all_custom_sort_numbers.each do |ask_category_setting_id, part_sort_number|
ask_setting = AskCategorySetting.find(ask_category_setting_id) rescue nil
if ask_setting
sort_number = ask_setting.sort_number
sort_number = AskSetting.get_sort_number_only(false, ask_setting, true).select{|k,v| last_fields.exclude?(k)}.map.with_index{|(k,v), i| [k, i]}.to_h.merge(ask_setting.sort_number)
tmp_default_customs_sort_number = default_customs_sort_number.select{|k, v| ask_setting.agree_customs.include?(k.split('@')[-1])}
part_sort_number = (part_sort_number.map{|k,v| ["default@#{k.split('@')[-1]}", v]} + tmp_default_customs_sort_number).to_h
intersect_keys = sort_number.keys & part_sort_number.keys
intersect_keys = part_sort_number.keys & sort_number.keys
non_intersect_keys = part_sort_number.keys - sort_number.keys
if intersect_keys.count != 0
org_order = intersect_keys.map{|k| [k, sort_number[k]]}.sort_by{|k,v| v}.to_h

View File

@ -38,19 +38,18 @@ class AsksController < ApplicationController
end
if ask_setting.nil?
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
@default_ask_setting = ask_setting
else
@default_ask_setting = AskSetting.first
end
defalt_fields = cal_form_from_setting(ask_setting,categories)
all_fields = cal_form_from_setting(ask_setting,categories)
request = OrbitHelper.request
csrf_value = OrbitHelper.request.session[:_csrf_token] || SecureRandom.base64(32)
token_tag = hidden_field_tag('authenticity_token',csrf_value)
switch_form = cal_switch_form(ask_settings,categories,token_tag,referer_url)
email_regex = @default_ask_setting.get_email_regex(true)
{
'fields' => defalt_fields,
'fields' => all_fields,
'extras'=>{
'switch_form' => switch_form,
'email_regex' => email_regex
@ -230,7 +229,7 @@ class AsksController < ApplicationController
end
if tmp.present?
if is_date && v["range_flag"] == 'true'
if tmp.class != Array
if (tmp.class != Array) || (tmp.select{|v| v.blank?}.count != 0)
flag = false
break
end
@ -265,7 +264,7 @@ class AsksController < ApplicationController
end
end
if (email_regex ? ::Regexp.new(email_regex).match(temp_params["mail"].to_s) : true) && flag
@disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting.class == AskCategorySetting ? ask_setting.category_id : nil)
@disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting, true, nil, true)
@usage_rule = ask_setting.usage_rule
@ask_question.update_attributes(temp_params)
build_email(@ask_question)
@ -332,14 +331,28 @@ class AsksController < ApplicationController
end
private
def cal_form_from_setting(ask_setting,categories,show_categories=false,filter_fields=nil)
disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting.class == AskCategorySetting ? ask_setting.category_id : nil)
is_cat_record = (ask_setting.class == AskCategorySetting)
override_sort_number = nil
if is_cat_record
category_id = ask_setting.category_id
if ask_setting.use_default
override_sort_number = ask_setting.default_sort_number
ask_setting = @default_ask_setting
if @default_fields
return @default_fields.sort_by{|h| override_sort_number[h['field']].to_i}
end
is_cat_record = false
end
else
category_id = (categories[0].id.to_s rescue '')
end
tmp_ask_cat_id = (is_cat_record ? ask_setting.id.to_s : '')
disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting, true, override_sort_number, true)
if filter_fields
disp_fields_infos = disp_fields_infos.select{|field, info| filter_fields.include?(field)}
end
# tmp = 'mongoid.attributes.ask_question'
defalt_fields = []
tmp_type = (ask_setting.class == AskSetting) ? 0 : 1
tmp_ask_cat_id = (tmp_type == 1) ? ask_setting.id.to_s : ""
all_fields = []
set_input_name_for_ask("ask_question")
has_ask_category_id = false
disp_fields_infos.each do |field, info|
@ -349,17 +362,17 @@ class AsksController < ApplicationController
if v
field_name = info['trans']
if field_name.present?
defalt_fields << {'label'=>ask_label(field_name, v['required']),'content'=>show_on_front(k,v)}
all_fields << {'field'=>field,'label'=>ask_label(field_name, v['required']),'content'=>show_on_front(k,v)}
end
end
elsif field.start_with?("custom@") && tmp_ask_cat_id != ""
if tmp_type == 1 && field.include?(tmp_ask_cat_id)
elsif field.start_with?("custom@") && is_cat_record
if field.include?(tmp_ask_cat_id)
k = field[8+tmp_ask_cat_id.length..-1]
v = ask_setting.custom_fields[k]
if v
field_name = info['trans']
if field_name.present?
defalt_fields << {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
all_fields << {'field'=>field,'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
end
end
end
@ -368,12 +381,12 @@ class AsksController < ApplicationController
has_ask_category_id = true
if show_categories || ask_setting.default_setting[field]
if categories.count > 1
defalt_fields << {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}
else
defalt_fields << {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>"<span>#{(categories[0].title rescue '')}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
all_fields << {'field'=>field,'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("ask_category_id"),'true'),'content'=>"<span>#{(categories[0].title rescue '')}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
end
else
defalt_fields << {'style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
all_fields << {'field'=>field,'style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}
end
else
if ask_setting.default_setting[field] || field == "usage_rule"
@ -414,15 +427,19 @@ class AsksController < ApplicationController
when 'agree_usage'
f1['content'] = check_box_tag('ask_question[agree_usage]', "1", false, {required: required})
end
defalt_fields << f1
f1['field'] = field
all_fields << f1
end
end
end
end
unless has_ask_category_id
defalt_fields << {'style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (tmp_type == 1 ? ask_setting.category_id : (categories[0].id.to_s rescue '')))}
all_fields << {'field'=>'ask_category_id','style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', category_id)}
end
defalt_fields
unless is_cat_record
@default_fields = all_fields
end
all_fields
end
def cal_html(fields,token_tag,form_id,referer_url,is_hidden=true,ask_setting=None)
form_url = "/#{I18n.locale.to_s}/asks"

View File

@ -50,7 +50,7 @@ module Admin::AsksHelper
end.join.html_safe
end
end
def multiple_lang_show_tag_for_ask(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false)
def multiple_lang_show_tag_for_ask(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false, extra_tr_class="",only_contents=false)
if !index1.nil?
all_field = (get_input_name_for_ask + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
@ -85,7 +85,11 @@ module Admin::AsksHelper
tmp
end
end
tmp = "<tr><td>#{field_name}".html_safe + ":</td><td>".html_safe + tmp + "</td></tr>".html_safe
if only_contents
tmp
else
tmp = "<tr class=\"#{extra_tr_class}\"><td>#{field_name}".html_safe + ":</td><td>".html_safe + tmp + "</td></tr>".html_safe
end
end
def multiple_lang_tag_for_ask(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
if !index1.nil?
@ -157,7 +161,7 @@ module Admin::AsksHelper
def render_date_block(field_name,v,i,value)
case v['format']
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'),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'),style:'width:100%;'})
#t2_value = value['datetime']['h']["#{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))
@ -170,7 +174,7 @@ module Admin::AsksHelper
})
</script>".html_safe
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')})
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')})
"<div class=\"datetime_selector\">#{t1}</div>
<script>
jQuery(document).ready(function( $ ) {
@ -178,7 +182,7 @@ module Admin::AsksHelper
})
</script>".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 = 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}
<script>
jQuery(document).ready(function( $ ) {
@ -187,7 +191,7 @@ module Admin::AsksHelper
</script>
"
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 = 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}
<script>
jQuery(document).ready(function( $ ) {
@ -201,9 +205,9 @@ module Admin::AsksHelper
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|
options.select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
if multple_choose
if value[index1]==index1
if value && value[index1]==index1
"#{option[I18n.locale]}"
else
"#{option[I18n.locale]}"
@ -236,16 +240,22 @@ module Admin::AsksHelper
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]})
readonly ? value : text_field_tag(field_name,value,{:required => v['required']=='true',placeholder: v['prompt_word'][I18n.locale],title: 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')
prompt_hash.merge!(required: v['required']=='true')
options_hash = Hash(v['options'])
if lock
format_checkbox(v['options'],value)
format_checkbox(options_hash,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)
if v['default_option'].present?
default_idx = v['default_option'].to_i
default_key = options_hash.keys[default_idx]
value ||= default_key
end
readonly ? (v['options'][value.to_s][I18n.locale] rescue '') : select_tag(field_name,options_for_select(options_hash.select{|index1,option| option['disabled'] != 'true'}.collect{|index1,option| [option[I18n.locale],index1]},selected: value),prompt_hash)
end
when 'date'
if value.nil?
@ -293,29 +303,33 @@ module Admin::AsksHelper
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'})
readonly ? value : text_area_tag(field_name,value,{:required => v['required']=='true',:placeholder=> v['prompt_word'][I18n.locale],:title=> v['prompt_word'][I18n.locale],:class=>'ckeditor'})
when 'radio_button'
if value.nil?
value = {}
end
options_hash = Hash(v['options'])
if lock
format_checkbox(v['options'],value)
format_checkbox(options_hash,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|
default_idx = v['default_option'].to_i
value ||= options_hash.keys[default_idx]
readonly ? (options_hash[value.to_s][I18n.locale] rescue '') : options_hash.collect do |index1,option|
next if option['disabled'] == 'true'
"<label class=\"radio-inline\" for=\"#{field_name_underscre}_#{index1}\">#{radio_button_tag(field_name,index1,value==index1,{:required => v['required']=='true'})}#{option[I18n.locale]}</label>"
end.join
end.compact.join
end
when 'checkbox'
if value.nil?
value = {}
end
options_hash = Hash(v['options'])
if lock
format_checkbox(v['options'],value,true)
format_checkbox(options_hash,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|
default_idx = v['default_option'].to_i
default_key = options_hash.keys[default_idx]
options_values = options_hash.values
value ||= {default_key=>default_key}
readonly ? value.collect{|k1,v1| options_values[v1.to_i][I18n.locale]}.join(', ') : options_hash.collect do |index1,option|
next if option['disabled'] == 'true'
"#{check_box_tag("#{field_name}[#{index1}]",index1,value[index1]==index1)}#{option[I18n.locale]}"
end.join
end.compact.join
end
when 'file'
file_value = value[0] rescue nil
@ -346,10 +360,16 @@ module Admin::AsksHelper
markups = markups.map{|k,v| [v,k]}.to_h
tmp = markups[v['type']]
tmp = markups.values[0] if tmp.nil?
options_hash = Hash(v['options'])
tmp_field_select_tag_for_ask = "<tr><td>#{t('ask.setting_type')}:</td><td><div id=\"#{get_input_name_for_ask}[#{k}][type]\">#{tmp}</div></td></tr>"
active_prompt_class = ['date','radio_button','checkbox'].exclude?(v['type']) ? ' active' : ''
active_class = ['select','radio_button','checkbox'].include?(v['type']) ? ' active' : ''
multi_lang_prompt_tag = multiple_lang_show_tag_for_ask(t('ask.prompt_word'),k,'prompt_word',v['prompt_word'])
active_prompt_class = (v['type'] != 'instructions' ? '' : ' hide')
active_class = (['select','radio_button','checkbox'].include?(v['type']) ? '' : ' hide')
multi_lang_prompt_tag = multiple_lang_show_tag_for_ask(t('ask.prompt_word'),k,'prompt_word',v['prompt_word'],'',{},false, active_prompt_class)
multi_lang_default_option = multiple_lang_show_tag_for_ask(t('ask.default_option'),k,'default_option',v['default_option'].present? ? options_hash.values[v['default_option'].to_i] : I18n.t('ask.please_select'),'',{},false, active_class)
options_area = options_hash.collect do |key,value|
"#{multiple_lang_show_tag_for_ask("",k,"options][#{key}",value,'',{},false,"",true)}"
end.join
options_area = "<tr><td>#{I18n.t('ask.options')}</td><td>#{options_area}</td></tr>"
field_html = "
<style>
.show_field {
@ -366,6 +386,8 @@ module Admin::AsksHelper
#{require_ask_tag}
#{tmp_field_select_tag_for_ask}
#{multi_lang_prompt_tag}
#{multi_lang_default_option}
#{options_area}
</tbody>"
else
not_editable = k.to_s.include?('default@')
@ -374,18 +396,27 @@ module Admin::AsksHelper
hint_text = "<div style=\"font-weight: bold;\">" + t('ask.this_field_is_default_custom_fields') + "</div>"
end
disabled_attr = (not_editable ? 'disabled' : nil)
multi_lang_tag = multiple_lang_tag_for_ask(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), disabled: disabled_attr})
multi_lang_tag = multiple_lang_tag_for_ask(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), title: t('ask.field_name'), disabled: disabled_attr})
tmp_field_select_tag_for_ask = field_select_tag_for_ask(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)', :disabled=>disabled_attr})
key = hidden_field_tag "#{get_input_name_for_ask}[#{k}][key]",k,{'class' => 'key'}
all_new_options = Array(v['options']).collect do |key,value|
options_hash = Hash(v['options'])
all_new_options = options_hash.collect do |key,value|
tmp = create_delete_button_for_ask('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name_for_ask}[#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
hidden_style = value['disabled'] == 'true' ? {style: 'display:none;'} : {}
"#{multiple_lang_tag_for_ask(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name'), :disabled=>disabled_attr},tmp,hidden_style,true)}"
"#{multiple_lang_tag_for_ask(k,'text_field',"options][#{key}",value,{ placeholder: t('ask.option_name'), class: 'option_name_field', title: t('ask.option_name'), disabled: disabled_attr},tmp,hidden_style,true)}"
end.join
active_class = ['select','radio_button','checkbox'].include?(v['type']) ? ' active' : ''
active_prompt_class = ['date','radio_button','checkbox'].exclude?(v['type']) ? ' active' : ''
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag_for_ask(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word'), disabled: disabled_attr})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag_for_ask(k,'text_area','instructions',v['instructions'],{placeholder: t('ask.prompt_word'), class: 'ckeditor', disabled: disabled_attr})}</div>"
tmp_count = {}
options_hash.each{|k,v| v.each{|l,vv| tmp_count[l] = tmp_count[l].to_i + 1 if vv.present?}}
current_locale = I18n.locale.to_s
maximum_locale = tmp_count.sort_by{|k,v| [v, k == current_locale]}[0][0] rescue nil
maximum_locale = I18n.locale.to_s if maximum_locale.nil?
locale_options_for_field = options_hash.map.with_index{|(k, v), i| [v[maximum_locale], i] rescue ""}
is_selection_field = ['select','radio_button','checkbox'].include?(v['type'])
active_class = is_selection_field ? ' active' : ''
active_prompt_class = (v['type'] != 'instructions' ? ' active' : '')
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag_for_ask(k,'text_field','prompt_word',v['prompt_word'],{ placeholder: t('ask.prompt_word'), title: t('ask.prompt_word'), disabled: disabled_attr})}</div>"
multi_lang_default_option = "<div class=\"default_option#{active_class}\">#{field_select_tag_for_ask(k,'default_option',locale_options_for_field,v['default_option'],{ title: t('ask.default_option'), class: 'default_option_select', disabled: disabled_attr, data: {locale: maximum_locale}, prompt: I18n.t('ask.please_select')})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag_for_ask(k,'text_area','instructions',v['instructions'],{ placeholder: t('ask.prompt_word'), title: t('ask.prompt_word'), class: 'ckeditor', disabled: disabled_attr})}</div>"
require_ask_tag = "<div>#{t('ask.required')}:&nbsp;&nbsp;#{field_radio_button_tag(k,'required','true',v['required']=='true',{disabled: disabled_attr})}#{t('ask.yes')}#{field_radio_button_tag(k,'required','false',v['required']!='true',{disabled: disabled_attr})}#{t('ask.no')}</div>"
tmp = "<div class=\"add_new_options#{active_class}\">#{all_new_options}<input class=\"btn btn-info\" type=\"button\" value=\"#{t('ask.add_new_options')}\" onclick=\"add_new_options_for_field(this,#{k})\"></div>"
field_html = "<tr class=\"custom_field #{extra_class}\" data-key=\"#{k}\">
@ -396,6 +427,7 @@ module Admin::AsksHelper
#{require_ask_tag}
#{tmp_field_select_tag_for_ask}<br>
#{multi_lang_prompt_tag}
#{multi_lang_default_option}
#{instructions_text_area}
#{time_setting_block(k,v)}
#{tmp}

View File

@ -1,8 +1,33 @@
class AskCategorySetting
include Mongoid::Document
include Mongoid::Timestamps
after_initialize do
if !self.new_record?
before_save do
unless @skip_callback
if self.sort_number_changed?
self.sort_number = self.sort_number.map{|k,v| [k,v.to_i]}.sort_by{|k,v| v}.to_h
need_recalc_sort = true
else
need_recalc_sort = false
end
if self.default_sort_number_changed?
need_recalc_sort = true
end
if self.custom_fields_changed?
delete_custom_fields = self.custom_fields.select{|k,v| v['delete'] == true}.keys
delete_custom_fields.each{|f| self.sort_number.delete(f)}
delete_custom_fields = delete_custom_fields.select{|k| k.include?("default@")}
self.delete_customs_func(delete_custom_fields, true)
self.custom_fields = self.custom_fields.select{|k,v| v['delete'] != true}
need_recalc_sort = true
end
if need_recalc_sort
self.recalc_sort(false)
end
end
true
end
def migrate_old
unless self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
@ -15,23 +40,18 @@ class AskCategorySetting
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.save
self.recalc_sort(true)
end
end
before_save do
unless @skip_callback
if self.sort_number_changed?
self.sort_number = self.sort_number.map{|k,v| [k,v.to_i]}.sort_by{|k,v| v}.to_h
end
if self.custom_fields_changed?
delete_custom_fields = self.custom_fields.select{|k,v| v['delete'] == true}.keys
delete_custom_fields.each{|f| self.sort_number.delete(f)}
delete_custom_fields = delete_custom_fields.select{|k| k.include?("default@")}
self.delete_customs_func(delete_custom_fields, true)
self.custom_fields = self.custom_fields.select{|k,v| v['delete'] != true}
end
def recalc_sort(save_flag=true)
self.tmp_sort_number = AskSetting.get_sort_number_only(true, self, true).map.with_index{|(k,v), i| [k,i]}.to_h
self.save if save_flag
end
def get_cache_sort_number #For Frontend
if self.tmp_sort_number.blank?
self.recalc_sort
end
true
self.tmp_sort_number
end
def field_name(k,locale=I18n.locale.to_s)
(self.default_setting_field_name[k]&&self.default_setting_field_name[k][locale]) ? self.default_setting_field_name[k][locale] : self.default_field_name(k,locale)
@ -67,6 +87,7 @@ class AskCategorySetting
apply_custom_fields.each{|k| self.custom_fields["default@#{k}"] = check_custom_fields[k]}
self.need_check_customs -= apply_custom_fields
self.reject_customs -= apply_custom_fields
self.recalc_sort(false)
@skip_callback = true
self.save
@skip_callback = false
@ -87,6 +108,7 @@ class AskCategorySetting
self.custom_fields.delete("default@#{f}")
end
end
self.recalc_sort(false)
@skip_callback = true
self.save
@skip_callback = false
@ -107,6 +129,7 @@ class AskCategorySetting
unless is_locale
self.agree_customs.each{|k| self.custom_fields["default@#{k}"] = check_custom_fields[k]}
end
self.recalc_sort(false)
@skip_callback = true
self.save
@skip_callback = false
@ -119,7 +142,9 @@ class AskCategorySetting
tmp = nil if !(self.email_regex_enable) || (self.application_form_signup_field_sets.where(:field_name=>'email').pluck(:disabled)[0] rescue false)
tmp
end
field :tmp_sort_number, type: Hash, default: {} # For Frontend
field :sort_number, type: Hash, default: {}
field :default_sort_number, type: Hash, default: {}
field :default_setting, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: true,appointment: true,recaptcha: true,agree_show: true,agree_usage: true}
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: false,agree_usage: true}
field :default_setting_field_name, type: Hash,default: {}
@ -134,5 +159,5 @@ class AskCategorySetting
field :need_check_customs, type: Array, default: [] #From AskSetting
field :reject_customs, type: Array, default: [] #From AskSetting
field :agree_customs, type: Array, default: [] #From AskSetting
scope :enabled, ->{where(:use_default.ne=>true)}
scope :enabled, ->{any_of([{:use_default.ne=>true}, {:use_default=>true, :default_sort_number.nin=>[nil, {}]}])}
end

View File

@ -4,26 +4,12 @@ class AskSetting
All_default_fields = ['ask_category_id','name','sex','mail','phone','appointment','recaptcha','usage_rule','agree_show','agree_usage']
No_prompt_word = ['ask_category_id', 'sex', 'appointment', 'recaptcha']
No_required = ['agree_show']
after_initialize do
if !self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
if self.default_setting[:agree_show].nil?
self.default_setting[:agree_show] = true
end
if self.default_setting[:agree_usage].nil?
self.default_setting[:agree_usage] = false
end
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.save
end
end
before_save do
if self.sort_number_changed?
self.sort_number = self.sort_number.map{|k,v| [k,v.to_i]}.sort_by{|k,v| v}.to_h
need_recalc_sort = true
else
need_recalc_sort = false
end
@email_regex_enable_changed = self.email_regex_enable_changed?
@email_regex_changed = self.email_regex_changed?
@ -34,6 +20,10 @@ class AskSetting
@delete_custom_fields = self.custom_fields.select{|k,v| v['delete'] == true}.keys
@delete_custom_fields.each{|f| self.sort_number.delete(f)}
self.custom_fields = self.custom_fields.select{|k,v| v['delete'] != true}
need_recalc_sort = true
end
if need_recalc_sort
self.recalc_sort(false)
end
true
end
@ -59,6 +49,26 @@ class AskSetting
end
end
end
def use_default
false
end
def migrate_old
unless self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
if self.default_setting[:agree_show].nil?
self.default_setting[:agree_show] = true
end
if self.default_setting[:agree_usage].nil?
self.default_setting[:agree_usage] = false
end
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.recalc_sort(true)
end
end
def field_name(k,locale=I18n.locale.to_s,use_checkbox_trans=false)
tmp = self.default_setting_field_name[k]
(tmp&&tmp[locale]) ? tmp[locale] : self.default_field_name(k,locale)
@ -83,6 +93,7 @@ class AskSetting
end
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
field :tmp_sort_number, type: Hash, default: {}
field :sort_number, type: Hash, default: {}
field :default_setting, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: true,appointment: true,recaptcha: true,agree_show: true,agree_usage: true}
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: false,agree_usage: true}
@ -94,6 +105,16 @@ class AskSetting
field :title_layout, type: Integer, default: 0
field :last_ticket_key, type: Integer, default: 0
field :last_serial_number, type: Integer, default: 0
def recalc_sort(save_flag=true)
self.tmp_sort_number = AskSetting.get_sort_number_only(true, self, true).map.with_index{|(k,v), i| [k,i]}.to_h
self.save if save_flag
end
def get_cache_sort_number #For Frontend
if self.tmp_sort_number.blank?
self.recalc_sort
end
self.tmp_sort_number
end
def get_attrs
attrs = self.attributes.clone
self.fields.each do |k, v|
@ -107,37 +128,158 @@ class AskSetting
def self.update_last_serial_number(last_serial_number=nil)
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
if last_serial_number.nil?
last_serial_number = (can_update_shared_hash ? OrbitHelper::SharedHash["ask"][:last_serial_number] : AskSetting.pluck(:last_serial_number)[0].to_i)
AskSetting.all.inc({'last_serial_number'=>1})
last_serial_number = (can_update_shared_hash ? OrbitHelper::SharedHash["ask"][:last_serial_number] : self.pluck(:last_serial_number)[0].to_i)
self.all.inc({'last_serial_number'=>1})
last_serial_number += 1
else
AskSetting.all.update_all(:last_serial_number=>last_serial_number)
self.all.update_all(:last_serial_number=>last_serial_number)
end
if can_update_shared_hash
OrbitHelper::SharedHash["ask"][:last_serial_number] = last_serial_number
end
last_serial_number
end
def self.get_disp_fields_infos(only_display=true, cat=nil)
def self.get_sort_number_only(only_display=true, cat=nil, cat_is_record=false, override_sort_number=nil, use_cache=false)
ask_setting = nil
if cat.present?
ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first
if cat_is_record
ask_setting = cat
is_cat_record = !(override_sort_number.nil?) || cat.class == AskCategorySetting
else
if cat.present?
ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first
is_cat_record = true
end
ask_setting = self.first if ask_setting.nil?
ask_setting = self.create() if ask_setting.nil?
end
if only_display && use_cache
if override_sort_number
sort_number = override_sort_number
else
sort_number = ask_setting.get_cache_sort_number
end
return sort_number
end
if override_sort_number.present?
sort_number = override_sort_number
else
sort_number = ask_setting.sort_number
if ask_setting.use_default
if ask_setting.default_sort_number.blank?
sort_number = ((ask_setting.class == self) ? sort_number : self.first.sort_number)
else
sort_number = ask_setting.default_sort_number
end
override_sort_number = sort_number
ask_setting = self.first
end
end
ask_setting = self.first if ask_setting.nil?
ask_setting = self.create() if ask_setting.nil?
default_ask_setting = ask_setting.class == self ? ask_setting : self.first
disp_fields = self::All_default_fields
disp_fields_infos = {}
locale = I18n.locale.to_s
if !only_display || ask_setting.default_setting['title'] != false
disp_fields_infos['title'] = {"trans"=>ask_setting.field_name('title'), "sort_number"=>ask_setting.sort_number['title'].to_i}
disp_fields_infos['title'] = sort_number['title'].to_i
end
tmp = disp_fields[0...-4]
if only_display
tmp = tmp.select{|f| ask_setting.default_setting[f]}
end
tmp.each do |f|
disp_fields_infos[f] = {"trans"=>default_ask_setting.field_name(f,locale),"sort_number"=>ask_setting.sort_number[f]}
disp_fields_infos[f] = sort_number[f]
end
tmp_locales = I18n.available_locales.map{|l| l.to_s}
tmp_locales = [locale] + (tmp_locales - [locale])
ask_setting.custom_fields.each do |k,v|
tmp_k = (k.start_with?('default@') ? k : "default@#{k}")
disp_fields_infos[tmp_k] = sort_number[tmp_k]
end
ask_category_settings = []
if is_cat_record
ask_category_settings = []
else
ask_category_settings = AskCategorySetting.enabled.to_a
end
ask_category_settings.each do |c|
cat = Category.find(c.category_id) rescue nil
if cat.nil?
c.destroy
next
end
c.custom_fields.each do |k,v|
next if k.start_with?('default@')
tmp_k = "custom@#{c.id}@#{k}"
cat_title = cat.title rescue ""
disp_fields_infos[tmp_k] = sort_number[tmp_k]
end
end
tmp = disp_fields[-4..-1]
if only_display
tmp = tmp.select{|f| ask_setting.default_setting[f] || f == 'usage_rule'}
end
tmp.each do |f|
disp_fields_infos[f] = sort_number[f]
end
max_sort_number = disp_fields_infos.values.map{|v| v}.compact.max
if max_sort_number
max_sort_number = max_sort_number + 1
disp_fields_infos.each_with_index do |(k,v), i|
if v.blank?
disp_fields_infos[k] = max_sort_number + i
end
end
disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value}.to_h
end
disp_fields_infos
end
def self.get_disp_fields_infos(only_display=true, cat=nil, cat_is_record=false, override_sort_number=nil, use_cache=false)
ask_setting = nil
if cat_is_record
ask_setting = cat
is_cat_record = !(override_sort_number.nil?) || cat.class == AskCategorySetting
else
if cat.present?
ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first
is_cat_record = true
end
ask_setting = self.first if ask_setting.nil?
ask_setting = self.create() if ask_setting.nil?
end
sort_number = nil
if only_display && use_cache
if override_sort_number
sort_number = override_sort_number
else
sort_number = ask_setting.get_cache_sort_number
end
else
use_cache = false
sort_number = ask_setting.sort_number
if override_sort_number.present?
sort_number = override_sort_number
elsif ask_setting.use_default
if ask_setting.default_sort_number.blank?
sort_number = ((ask_setting.class == self) ? sort_number : self.first.sort_number)
else
sort_number = ask_setting.default_sort_number
end
override_sort_number = sort_number
ask_setting = self.first
end
end
default_ask_setting = ask_setting.class == self ? ask_setting : self.first
disp_fields = self::All_default_fields
disp_fields_infos = {}
locale = I18n.locale.to_s
if !only_display || ask_setting.default_setting['title'] != false
disp_fields_infos['title'] = {"trans"=>ask_setting.field_name('title'), "sort_number"=>sort_number['title'].to_i}
end
tmp = disp_fields[0...-4]
if only_display
tmp = tmp.select{|f| ask_setting.default_setting[f]}
end
tmp.each do |f|
disp_fields_infos[f] = {"trans"=>default_ask_setting.field_name(f,locale),"sort_number"=>sort_number[f]}
end
tmp_locales = I18n.available_locales.map{|l| l.to_s}
tmp_locales = [locale] + (tmp_locales - [locale])
@ -150,11 +292,11 @@ class AskSetting
end
end
next if trans.class != String
tmp_k = "default@#{k}"
disp_fields_infos[tmp_k] = {"trans"=>trans,"sort_number"=>ask_setting.sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]}
tmp_k = (k.start_with?('default@') ? k : "default@#{k}")
disp_fields_infos[tmp_k] = {"trans"=>trans,"sort_number"=>sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]}
end
ask_category_settings = []
if ask_setting.class == AskCategorySetting || cat.present?
if is_cat_record
ask_category_settings = []
else
ask_category_settings = AskCategorySetting.enabled.to_a
@ -177,7 +319,7 @@ class AskSetting
next if k.start_with?('default@')
tmp_k = "custom@#{c.id}@#{k}"
cat_title = cat.title rescue ""
disp_fields_infos[tmp_k] = {"trans"=>"#{cat_title}-#{trans}","sort_number"=>ask_setting.sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]}
disp_fields_infos[tmp_k] = {"trans"=>"#{cat_title}-#{trans}","sort_number"=>sort_number[tmp_k],"key"=>k,"type"=>v["type"],"options"=>v["options"],"instructions"=>v["instructions"]}
end
end
tmp = disp_fields[-4..-1]
@ -185,19 +327,19 @@ class AskSetting
tmp = tmp.select{|f| ask_setting.default_setting[f] || f == 'usage_rule'}
end
tmp.each do |f|
disp_fields_infos[f] = {"trans"=>default_ask_setting.field_name(f,locale),"sort_number"=>ask_setting.sort_number[f]}
disp_fields_infos[f] = {"trans"=>default_ask_setting.field_name(f,locale),"sort_number"=>sort_number[f]}
end
max_sort_number = disp_fields_infos.values.map{|h| h["sort_number"]}.compact.max
if max_sort_number
max_sort_number = max_sort_number + 1
disp_fields_infos.each_with_index do |(k,h), i|
if h["sort_number"].blank?
h["sort_number"] = max_sort_number + i
else
h["sort_number"] = h["sort_number"]
unless use_cache
max_sort_number = max_sort_number + 1
disp_fields_infos.each_with_index do |(k,h), i|
if h["sort_number"].blank?
h["sort_number"] = max_sort_number + i
end
end
end
disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value["sort_number"]}
disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value["sort_number"]}.to_h
end
disp_fields_infos
end

View File

@ -3,10 +3,10 @@
text-align: center;
color: blueviolet;
}
.add_new_options,.prompt_word,.time_setting_block{
.add_new_options,.prompt_word,.default_option,.time_setting_block{
display: none;
}
.add_new_options.active,.prompt_word.active,.time_setting_block.active{
.add_new_options.active,.prompt_word.active,.default_option.active,.time_setting_block.active{
display: block;
}
tr td {
@ -58,20 +58,15 @@
</style>
<script type="text/javascript">
<%
option_multi_lang_tag = multiple_lang_tag_for_ask(-1,'text_field','options][-2',nil,{placeholder: t('ask.option_name')},create_delete_button_for_ask('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name_for_ask}[-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}),{},true)
option_multi_lang_tag = multiple_lang_tag_for_ask(-1,'text_field','options][-2',nil,{ placeholder: t('ask.option_name'), class: 'option_name_field', title: t('ask.option_name'), data: {locale: I18n.locale.to_s}},create_delete_button_for_ask('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name_for_ask}[-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}),{},true)
%>
function check_available_setting_block(ele){
var tmp = $(ele).val()
var parent_div = $(ele).parents('.custom_field').eq(0)
if (tmp != 'date' && tmp != 'radio_button' && tmp!='checkbox'){
parent_div.find('.prompt_word').addClass('active');
}else{
parent_div.find('.prompt_word').removeClass('active');
}
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
parent_div.find('.add_new_options').addClass('active');
parent_div.find('.add_new_options, .default_option').addClass('active');
}else{
parent_div.find('.add_new_options').removeClass('active');
parent_div.find('.add_new_options, .default_option').removeClass('active');
}
if (tmp == 'instructions'){
parent_div.find('.instructions_text_area').removeClass('hide');
@ -102,11 +97,34 @@
add_html = add_html.replace(/-2/g,tab_panel_length)
add_html = add_html.replace(/icons-list-3/g,'icons-list-2')
parent_div.find('input[type="button"]').eq(-1).before($('<div/>').html(add_html).text().slice(1,-2))
parent_div.siblings('.default_option').find('.default_option_select').append(new Option('',tab_panel_length));
}
function delete_added_select_option(ele){
var parent_div = $(ele).parents('.tab-panel')
var parent_div = $(ele).parents('.tab-panel');
var select_box = parent_div.parent().siblings('.default_option').find('>.default_option_select');
console.log(select_box)
var idx = parent_div.index();
var selected_val = parseInt(select_box.val());
if(selected_val == idx){
select_box.val('0');
}else if(selected_val > idx){
select_box.val(selected_val - 1);
}
var idx_offset = 1;
select_box.find('option').eq(idx+idx_offset).remove();
select_box.find('option').slice(idx+idx_offset).each(function(i,v){
$(v).attr('value', i + idx);
})
parent_div.remove();
}
$(document).on('input', '.option_name_field', function(){
var _this = $(this);
var idx_offset = 1;
var select_box = _this.parents('.add_new_options').siblings('.default_option').find('>.default_option_select');
if(_this.attr('name').match(new RegExp(select_box.data('locale')+'\\]$'))){
select_box.find('option').eq(_this.parents('.tab-panel:eq(0)').index()+idx_offset).text(_this.val());
}
})
</script>
<style type="text/css">
.border {

View File

@ -2,6 +2,9 @@ en:
situation: Status
sex: Sex
ask:
options: "Options"
please_select: '--Please Select--'
default_option: Default Option
batch_modify_status: "Batch Modify Status"
delete_selected: "Delete Selected"
backend_table_setting: Backend Table Setting

View File

@ -6,6 +6,9 @@ zh_tw:
errors:
verification_failed: 驗證碼錯誤
ask:
options: "選項"
please_select: '--請選擇--'
default_option: 預設選項
batch_modify_status: "批次修改狀態"
delete_selected: "刪除所選"
backend_table_setting: 後台表格設定

View File

@ -2,9 +2,11 @@ Rails.application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
Thread.new do
AskPrintSetting.create() if AskPrintSetting.count == 0
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
update_flag = s.respond_to?(:tmp_flags)
need_update = !update_flag || !(s.tmp_flags.include?('askf1'))
need_update2 = !update_flag || !(s.tmp_flags.include?('askf2'))
if need_update
ask_setting = AskSetting.first
check_custom_fields = {}
@ -43,9 +45,14 @@ Rails.application.routes.draw do
a.save
end
if update_flag
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
s.tmp_flags << 'askf1'
s.save
Site.update_all("$push"=>{"tmp_flags"=>'askf1'})
end
elsif need_update2
([AskSetting.first] + AskCategorySetting.all.to_a).each do |a|
a.migrate_old
end
if update_flag
Site.update_all("$push"=>{"tmp_flags"=>'askf2'})
end
end
end