Update a lots.(2022/07/28 on trello)

This commit is contained in:
BoHung Chiu 2022-08-18 11:07:45 +08:00
parent ff7a0d9394
commit 2ba3253f67
18 changed files with 601 additions and 109 deletions

View File

@ -43,9 +43,11 @@
/*button*/
.form-horizontal .form-actions {
border-top: 1px solid #d7dadb;
padding: 1em 0 0 20em;
/*padding: 1em 0 0 20em;*/
}
.form-horizontal .form-actions input, .form-horizontal .form-actions a{
float: right;
}
/*驗證碼*/
.text-error {
color: #b94a48;

View File

@ -69,7 +69,7 @@ class Admin::AsksController < OrbitAdminController
ask_setting = AskSetting.first
p1 = ask_setting_params(ask_setting,'ask_setting')
ask_setting.update_attributes(p1)
redirect_to "/#{locale}/admin/asks"
redirect_to "/#{locale}/admin/asks/setting"
end
def switch_to_default_setting
if AskCategorySetting.where(:id=>params[:id]).update_all(:use_default=>params[:use_default] == "true").documents[0]["nModified"] != 0
@ -82,10 +82,8 @@ class Admin::AsksController < OrbitAdminController
locale = I18n.locale
ask_setting = AskCategorySetting.where(category_id: params['category_id']).first
ask_setting = AskCategorySetting.create(category_id: params['category_id']) if ask_setting.nil?
p1 = ask_setting_params(ask_setting,'ask_category_setting')
puts ask_setting.inspect
puts ["update!", p1]
ask_setting.update!(p1)
p1 = ask_setting_params(ask_setting,'ask_category_setting', ask_setting.agree_customs.map{|k| "default@#{k}"})
ask_setting.update_attributes(p1)
redirect_to "/#{locale}/admin/asks/category_setting"
end
def setting
@ -106,6 +104,36 @@ class Admin::AsksController < OrbitAdminController
ask_setting_index.save
render :json => {key: ask_setting_index.key.to_i}
end
def apply_default_custom_fields
ask_setting = AskCategorySetting.where(:category_id=>params[:category]).first
if ask_setting
if params[:apply_all].to_s == 'true'
apply_fields = ask_setting.need_check_customs
if params[:include_reject].to_s == 'true'
apply_fields += ask_setting.reject_customs
apply_fields = apply_fields.sort_by{|k| k.to_i}
end
else
apply_fields = params[:apply_fields].to_a
end
is_agree = params[:agree].to_s == 'true'
if is_agree
ask_setting.agree_customs_func(apply_fields)
custom_fields = AskSetting.first.custom_fields
set_input_name('ask_category_setting[custom_fields]')
view_context.set_input_name('ask_category_setting[custom_fields]') #prevent not setting variables
html = apply_fields.map do |k|
view_context.custom_field_block("default@#{k}", custom_fields[k])
end.join("\n")
else
ask_setting.delete_customs_func(apply_fields, true)
html = ""
end
render :json => {:success=>true, :html=>html}
else
render :json => {:success=>false}
end
end
def index
AskPrintSetting.create() if AskPrintSetting.first.nil?
@ask_setting = AskSetting.first
@ -113,7 +141,7 @@ class Admin::AsksController < OrbitAdminController
@categories = @module_app.categories.enabled.sort_by{|category| (((@module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
@filter_fields = filter_fields(@categories, @tags)
# 列表欄位
@table_fields = [:situation, :category, 'title' , 'ask.name', 'ask.phone', 'ask.appointment','ask.created_at','ask.ip']
@table_fields = ['ask.serial_number', :situation, :category, 'title' , 'ask.name', 'ask.phone', 'ask.appointment','ask.created_at','ask.ip']
# 列表排序
# debugger
if filter2("situation").blank? and filter2("identity").blank?
@ -413,17 +441,21 @@ class Admin::AsksController < OrbitAdminController
p1 = default_setting.get_attrs
ask_setting.update_attributes(p1)
ask_setting.update(:use_default => true)
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.include?('default@')}.map{|k,v| ["custom@#{ask_setting_id}@#{k.split('@')[-1]}", v]}.to_h
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]]}
default_sort_number = default_sort_number.merge(intersect_keys.zip(org_order.sort_by{|k, v| part_sort_number[k]}.map{|k,v| v}).to_h)
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
@ -441,19 +473,21 @@ class Admin::AsksController < OrbitAdminController
end
AskSetting.update_all(:sort_number=>sort_number)
unless use_default
custom_sort_number = sort_number.select{|k, v| k.include?('custom@')}
default_customs_sort_number = sort_number.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
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
part_sort_number = part_sort_number.map{|k,v| ["default@#{k.split('@')[-1]}", v]}.to_h
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
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_number = sort_number.merge(intersect_keys.zip(org_order.sort_by{|k, v| part_sort_number[k]}.map{|k,v| v}).to_h)
org_order = intersect_keys.map{|k| [k, sort_number[k]]}.sort_by{|k,v| v}.to_h
sort_number = sort_number.merge(org_order.sort_by{|k, v| part_sort_number[k]}.map{|k,v| k}.zip(org_order.values).to_h)
end
if non_intersect_keys.count != 0
max_sort_number = sort_number.map{|k,v| v.to_i}.max.to_i
@ -499,21 +533,21 @@ class Admin::AsksController < OrbitAdminController
render :json => {:success=>true}
end
private
def ask_setting_params(ask_setting,collection_name)
def ask_setting_params(ask_setting,collection_name, except_customs=[])
param = params.require(collection_name).except("id").permit!
param_clone = param.clone
param_clone['default_setting'].each { |k, v| param_clone['default_setting'][k] = (v == 'true'? true : false) if param_clone['default_setting'][k].class==String}
param_clone['default_setting_required'].each { |k, v| param_clone['default_setting_required'][k] = (v == 'true'? true : false) if param_clone['default_setting_required'][k].class==String}
param_clone.delete('custom_fields')
param_clone.delete('email_regex')
ask_setting.custom_fields_will_change!
custom_fields = params['not_clone_attrs'] ? {} : ask_setting['custom_fields'].clone
params_custom_fields = (params.require(collection_name).require('custom_fields') rescue {})
params_custom_fields.each do |k,v|
next if except_customs.include?(k.to_s)
custom_fields[k] = v
end
field_to_delete = params['delete_field'].to_s.split(',').select{|v| !v.empty?}
puts ["field_to_delete", field_to_delete]
puts ["custom_fields", custom_fields]
field_to_delete.each do |k|
if custom_fields.keys.include? k
custom_fields[k]['delete'] = true

View File

@ -45,7 +45,7 @@ class AsksController < ApplicationController
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.email_regex_enable ? @default_ask_setting.email_regex.gsub("\\A","^").gsub("\\z","$") : nil
email_regex = @default_ask_setting.get_email_regex(true)
{
'fields' => defalt_fields,
'extras'=>{
@ -155,7 +155,7 @@ class AsksController < ApplicationController
switch_form = cal_switch_form(ask_settings,categories,token_tag,referer_url)
tags = module_app.tags
ask_question = AskQuestion.new(id: nil)
email_regex = @default_ask_setting.email_regex_enable ? @default_ask_setting.email_regex.gsub("\\A","^").gsub("\\z","$") : nil
email_regex = @default_ask_setting.get_email_regex(true)
{
'layout_type' => 'index',
'ask_question' => ask_question,
@ -194,17 +194,55 @@ class AsksController < ApplicationController
temp_params = create_params
all_to_save = []
ask_setting = AskCategorySetting.enabled.where(category_id: params['ask_question']['category_id']).first
email_regex = nil
if ask_setting.nil?
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
email_regex = ask_setting.email_regex
else
email_regex = AskSetting.first.email_regex rescue nil
end
email_regex = nil if !(ask_setting.email_regex_enable) || !(ask_setting.default_setting['mail'])
check_fields = ask_setting.default_setting.select{|k,v| v}.keys & ask_setting.default_setting_required.select{|k,v| v}.keys - AskSetting::No_required
flag = true
check_fields.each do |f|
next if f == 'ask_category_id' || f == 'recaptcha'
if temp_params[f].blank?
flag = false
break
end
end
custom_values = temp_params[:custom_values]
custom_values = {} if custom_values.nil?
if flag
check_custom_fields = ask_setting.custom_fields.select{|k,v| v["required"] == 'true' }
if check_custom_fields.count != 0
check_custom_fields.each do |k,v|
next if v['type'] == 'instructions'
tmp = custom_values[k]
v_type = v['type']
is_date = false
if v_type == "checkbox"
tmp = tmp.values rescue []
elsif v_type == 'date'
is_date = true
tmp = tmp["datetime"].values[0].values rescue []
end
if tmp.present?
if is_date && v["range_flag"] == 'true'
if tmp.class != Array
flag = false
break
end
end
else
flag = false
break
end
end
end
end
if !flag
redirect_to "#{params[:referer_url]}?method=sorry" and return
end
email_regex = ask_setting.get_email_regex
ask_setting.custom_fields.select{|k,v| v['type']=='file' || v['type']=='image'}.each do |k,v|
file = temp_params['custom_values'][k]
file = custom_values[k]
if !file.blank?
if v['type']=='image'
all_to_save += [[k,AskImage.new(file: file,ask_question_id: @ask_question.id)]]
@ -213,11 +251,12 @@ class AsksController < ApplicationController
end
end
end
puts "flag", flag
flag = !ask_setting.default_setting['recaptcha'] || gotcha_valid?
if flag
all_to_save.each do |to_save|
flag = flag && to_save[1].save
temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url]
custom_values[to_save[0]] = [custom_values[to_save[0]].original_filename ,to_save[1].file.url]
end
end
if (email_regex ? ::Regexp.new(email_regex).match(temp_params["mail"].to_s) : true) && flag
@ -280,8 +319,7 @@ class AsksController < ApplicationController
"usage_rule" => @usage_rule
}
)
email_er.email.deliver
# email_er.email.deliver
end
def create_params
@ -293,26 +331,30 @@ class AsksController < ApplicationController
if filter_fields
disp_fields_infos = disp_fields_infos.select{|field, info| filter_fields.include?(field)}
end
tmp = 'mongoid.attributes.ask_question'
title_trans = ask_setting.field_name('title')
required = ask_setting.default_setting_required['title']
defalt_fields = [{'style_html'=>'','label'=>ask_label(title_trans, required.to_s),'content'=>text_field_tag('ask_question[title]',nil,placeholder: title_trans,required: required)}]
# 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 : ""
set_input_name("ask_question")
disp_fields_infos.each do |field, info|
if field.include?("default@")
if field.start_with?("default@")
k = field[8..-1]
v = ask_setting.custom_fields[k]
if v
defalt_fields << {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
field_name = info['trans']
if field_name.present?
defalt_fields << {'label'=>ask_label(field_name, v['required']),'content'=>show_on_front(k,v)}
end
end
elsif field.include?("custom@") && tmp_ask_cat_id != ""
elsif field.start_with?("custom@") && tmp_ask_cat_id != ""
if tmp_type == 1 && field.include?(tmp_ask_cat_id)
k = field[8+tmp_ask_cat_id.length..-1]
v = ask_setting.custom_fields[k]
if v
defalt_fields << {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,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)}
end
end
end
else
@ -328,12 +370,15 @@ class AsksController < ApplicationController
end
else
if ask_setting.default_setting[field] || field == "usage_rule"
required = ask_setting.default_setting_required[field]
required = ask_setting.is_required(field)
f1 = {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("#{field}"),required.to_s)}
field_name = "ask_question[#{field}]"
placeholder = @default_ask_setting.prompt_word(field)
case field
when 'title'
f1['content'] = text_field_tag(field_name,nil,placeholder: placeholder,required: required)
when 'name'
f1['content'] = text_field_tag(field_name,nil,data: (required ? {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} : {}),required: required,placeholder:@default_ask_setting.field_name("#{field}"))
f1['content'] = text_field_tag(field_name,nil,data: (required ? {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} : {}),required: required,placeholder: placeholder)
when 'sex'
f1['content'] = "<label class=\"radio-inline\">
#{radio_button_tag(field_name,'male', false, {required: required})}#{I18n.t('users.male')}
@ -342,16 +387,16 @@ class AsksController < ApplicationController
#{radio_button_tag(field_name,'female', false, {required: required})}#{I18n.t('users.female')}
</label>"
when 'mail'
f1['content'] = text_field_tag(field_name,nil,data: (required ? {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} : {}),required: required,placeholder:@default_ask_setting.field_name("#{field}"))
f1['content'] = text_field_tag(field_name,nil,data: (required ? {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} : {}),required: required,placeholder: placeholder)
when 'phone'
f1['content'] = text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"),required: required)
f1['content'] = text_field_tag(field_name,nil,placeholder: placeholder,required: required)
when 'appointment'
if @appointment_idx.nil?
@appointment_idx = 0
else
@appointment_idx += 1
end
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"),data: {format: 'yy/mm/dd HH:MM'},required: required, id: "ask_question_appointment_#{@appointment_idx}")}</div>"
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder: placeholder,data: {format: 'yyyy/MM/dd hh:mm'},required: required, id: "ask_question_appointment_#{@appointment_idx}")}</div>"
when 'recaptcha'
f1['content'] = "#{gotcha_error}#{gotcha}"
when 'usage_rule'

View File

@ -52,9 +52,9 @@ module Admin::AsksHelper
end
def multiple_lang_show_tag(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
all_field = (get_input_name + "[#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
end
tmp = (I18n.available_locales.collect do |locale|
active_flag = ((locale == I18n.locale) ? ' active' : '')
@ -84,9 +84,9 @@ module Admin::AsksHelper
end
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
all_field = (get_input_name + "[#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
end
tmp = (I18n.available_locales.collect do |locale|
active_flag = ((locale == I18n.locale) ? ' active' : '')
@ -141,8 +141,8 @@ module Admin::AsksHelper
def field_select_tag(index1,field,options,selected=nil,custom_options={})
select_tag("#{get_input_name}[#{index1}][#{field}]",options_for_select(options,selected: selected),custom_options)
end
def field_radio_button_tag(index1,field,show_value,value,custom_options={})
radio_button_tag("#{get_input_name}[#{index1}][#{field}]",show_value,value)
def field_radio_button_tag(index1,field,show_value,checked,custom_options={})
radio_button_tag("#{get_input_name}[#{index1}][#{field}]",show_value,checked,custom_options)
end
def render_date_block(field_name,v,i,value)
case v['format']
@ -228,14 +228,45 @@ module Admin::AsksHelper
value = {}
end
if v['range_flag']=='true'
tmp = value['datetime']['date'] rescue {}
readonly ? "#{tmp['0']}~#{tmp['1']}" : "<div style=\"display:inline-flex;flex-direction:column;\">
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
"<div style=\"display:inline-flex;flex-direction:column;\">
#{render_date_block(field_name,v,0,value)}
<div style=\"display: inline-flex;align-items: center;writing-mode: tb-rl;padding: 0.3em;\">~</div>
#{render_date_block(field_name,v,1,value)}
</div>".html_safe
</div>".html_safe
end
else
readonly ? value : render_date_block(field_name,v,0,value)
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'})
@ -282,7 +313,7 @@ module Admin::AsksHelper
"<pre>#{e.inspect}<br>#{e.backtrace.to_yaml}</pre>"
end
end
def custom_field_block(k,v={},show_only=false)
def custom_field_block(k,v={},show_only=false, other_first_rows="",extra_class="")
markups = LIST[:markups].select{|k,v| k != 'member_relationship' && k != 'address'}.collect{|key,val| [t("lists.markups."+key),key]} +[[t('ask.file_field'),'file'],[t('ask.image_field'),'image'],[t('ask.instructions'),'instructions']]
if show_only
multi_lang_tag = multiple_lang_show_tag(t('ask.field_name'),k,'field',v['field'])
@ -304,29 +335,37 @@ module Admin::AsksHelper
overflow-y: auto;
}
</style>
<tbody class=\"custom_field\">
<tbody class=\"custom_field #{extra_class}\" data-key=\"#{k}\">
#{other_first_rows}
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}
#{multi_lang_prompt_tag}
</tbody>"
else
multi_lang_tag = multiple_lang_tag(k,'text_field','field',v['field'],{placeholder: t('ask.field_name')})
field_select_tag = field_select_tag(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)'})
not_editable = k.to_s.include?('default@')
hint_text = ""
if not_editable
hint_text = "<div style=\"font-weight: bold;\">" + t('ask.this_field_is_default_custom_fields') + "</div>"
end
multi_lang_tag = multiple_lang_tag(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), disabled: (not_editable ? 'disabled' : nil)})
field_select_tag = field_select_tag(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)', :disabled=>(not_editable ? 'disabled' : nil)})
key = hidden_field_tag "#{get_input_name}[#{k}][key]",k,{'class' => 'key'}
all_new_options = Array(v['options']).collect do |key,value|
tmp = create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name}[#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
hidden_style = value['disabled'] == 'true' ? {style: 'display:none;'} : {}
"#{multiple_lang_tag(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name')},tmp,hidden_style,true)}"
"#{multiple_lang_tag(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name'), :disabled=>(not_editable ? 'disabled' : nil)},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(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word')})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag(k,'text_area','instructions',v['instructions'],{placeholder: t('ask.prompt_word'), class: 'ckeditor'})}</div>"
require_ask_tag = "<div>#{t('ask.required')}:&nbsp;&nbsp;#{field_radio_button_tag(k,'required','true',v['required']=='true')}#{t('ask.yes')}#{field_radio_button_tag(k,'required','false',v['required']!='true')}#{t('ask.no')}</div>"
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word'), disabled: (not_editable ? 'disabled' : nil)})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag(k,'text_area','instructions',v['instructions'],{placeholder: t('ask.prompt_word'), class: 'ckeditor', disabled: 'disabled'})}</div>"
require_ask_tag = "<div>#{t('ask.required')}:&nbsp;&nbsp;#{field_radio_button_tag(k,'required','true',v['required']=='true',{disabled: (not_editable ? 'disabled' : nil)})}#{t('ask.yes')}#{field_radio_button_tag(k,'required','false',v['required']!='true',{disabled: (not_editable ? 'disabled' : nil)})}#{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\">
field_html = "<tr class=\"custom_field #{extra_class}\" data-key=\"#{k}\">
<td>
#{other_first_rows}
#{hint_text}
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}<br>

View File

@ -18,9 +18,20 @@ class AskCategorySetting
self.save
end
end
def custom_fields
tmp = super
tmp.select{|k,v| v['delete'] != true}
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
end
true
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)
@ -33,10 +44,86 @@ class AskCategorySetting
def field_name_translations(k)
I18n.available_locales.map{|v| [v.to_s,self.field_name(k,v.to_s)]}.to_h
end
def prompt_word(k,locale=I18n.locale.to_s,use_checkbox_trans=false)
tmp = self.default_setting_prompt_word[k]
(tmp&&tmp[locale]) ? tmp[locale] : self.field_name(k,locale)
end
def prompt_word_translations(k)
I18n.available_locales.map{|v| [v.to_s,self.prompt_word(k,v.to_s)]}.to_h
end
def is_required(k)
self.default_setting_required[k]
end
def agree_customs_func(apply_custom_fields, check_custom_fields=nil)
if apply_custom_fields.count != 0
self.agree_customs += apply_custom_fields
self.agree_customs.uniq!
if check_custom_fields.nil?
check_custom_fields = AskSetting.first.custom_fields
end
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
@skip_callback = true
self.save
@skip_callback = false
end
true
end
def delete_customs_func(delete_custom_fields, add_to_reject=false)
if delete_custom_fields.count != 0
delete_custom_fields = delete_custom_fields.map{|f| f.sub('default@', '')}
self.need_check_customs -= delete_custom_fields
self.agree_customs -= delete_custom_fields
if add_to_reject
self.reject_customs += delete_custom_fields
self.reject_customs.uniq!
else
self.reject_customs -= delete_custom_fields
delete_custom_fields.each do |f|
self.custom_fields.delete(f)
end
end
@skip_callback = true
self.save
@skip_callback = false
end
true
end
def update_need_check_customs(check_custom_fields, is_locale=false, need_check=false)
if need_check
check_custom_fields = check_custom_fields.map{|k,v| [k, v["field"][I18n.default_locale.to_s]]}.to_h unless is_locale
category_custom_fields = self.custom_fields.map{|k,v| v["field"][I18n.default_locale.to_s]}
self.need_check_customs += check_custom_fields.select{|k,v| v.blank? || !(category_custom_fields.include?(v))}.keys
else
self.need_check_customs += check_custom_fields.keys
end
self.need_check_customs = self.need_check_customs.uniq
self.need_check_customs -= self.reject_customs
self.need_check_customs -= self.agree_customs
unless is_locale
self.agree_customs.each{|k| self.custom_fields["default@#{k}"] = check_custom_fields[k]}
end
@skip_callback = true
self.save
@skip_callback = false
end
def get_email_regex(frontend=false)
tmp = self.email_regex
if tmp
tmp = tmp.gsub("\\A","^").gsub("\\z","$").gsub("\\","\\\\\\\\")
end
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 :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: 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: {}
field :default_setting_prompt_word, type: Hash,default: {}
field :use_default, type: Boolean, default: false
field :custom_fields, type: Hash,default: {}
field :usage_rule
@ -44,5 +131,8 @@ class AskCategorySetting
field :title_layout, type: Integer
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
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)}
end
end

View File

@ -6,6 +6,7 @@ class AskQuestion
# include OrbitTag::Taggable
# 欄位
field :serial_number, type: Integer
field :ip, type: String
field :name, type: String
field :identity, type: String
@ -26,7 +27,10 @@ class AskQuestion
field :agree_show,type: Boolean,default: false
field :agree_usage,type: Boolean,default: false
# validates_presence_of :name, :identity, :mail, :title, :content
before_create do
last_serial_number = AskSetting.update_last_serial_number
self.serial_number = last_serial_number
end
def email
mail = Email.find(self.email_id) rescue nil
end
@ -46,9 +50,19 @@ class AskQuestion
a.destroy
end
end
email_address.uniq!
email_address = email_address +[self.mail] if !self.mail.blank?
email_address.flatten
email_address.uniq!
end
def get_serial_number(last_serial_number=nil, display_length=nil)
if display_length.nil? && last_serial_number.nil?
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
last_serial_number = (can_update_shared_hash ? OrbitHelper::SharedHash["ask"][:last_serial_number] : AskSetting.pluck(:last_serial_number)[0].to_i)
end
display_length = [last_serial_number.to_s.length + 1, 4].max if display_length.nil?
display_format_string(self.serial_number, display_length)
end
def display_format_string(num, str_length)
return format("%0#{str_length}d", num)
end
end

View File

@ -2,6 +2,8 @@ class AskSetting
include Mongoid::Document
include Mongoid::Timestamps
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
@ -19,20 +21,51 @@ class AskSetting
self.save
end
end
after_save do
if self.email_regex_enable_changed? || self.email_regex_changed?
AskCategorySetting.all.update_all(email_regex_enable: self.email_regex_enable,email_regex: self.email_regex)
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
end
@email_regex_enable_changed = self.email_regex_enable_changed?
@email_regex_changed = self.email_regex_changed?
@default_setting_prompt_word_changed = self.default_setting_prompt_word_changed?
@default_setting_field_name_changed = self.default_setting_field_name_changed?
@custom_fields_changed = self.custom_fields_changed?
if @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)}
self.custom_fields = self.custom_fields.select{|k,v| v['delete'] != true}
end
true
end
def custom_fields
tmp = super
tmp.select{|k,v| v['delete'] != true}
after_save do
update_all_hash = {}
if @email_regex_enable_changed || @email_regex_changed
update_all_hash[:email_regex_enable] = self.email_regex_enable
update_all_hash[:email_regex] = self.email_regex
end
if @default_setting_prompt_word_changed
update_all_hash[:default_setting_prompt_word] = self.default_setting_prompt_word
end
if @default_setting_field_name_changed
update_all_hash[:default_setting_field_name] = self.default_setting_field_name
end
if update_all_hash.present?
AskCategorySetting.all.update_all(update_all_hash)
end
if @custom_fields_changed
AskCategorySetting.all.each do |a|
a.delete_customs_func(@delete_custom_fields)
a.update_need_check_customs(self.custom_fields)
end
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)
end
def is_required(k)
self.default_setting_required[k]
end
def default_field_name(k,locale=I18n.locale.to_s,use_checkbox_trans=false)
I18n.with_locale(locale){ (use_checkbox_trans && ['agree_show','agree_usage'].include?(k.to_s)) ? I18n.t("ask.#{k}_checkbox") : I18n.t("mongoid.attributes.ask_question.#{k}")}
end
@ -40,17 +73,27 @@ class AskSetting
def field_name_translations(k)
I18n.available_locales.map{|v| [v.to_s,self.field_name(k,v.to_s)]}.to_h
end
def prompt_word(k,locale=I18n.locale.to_s,use_checkbox_trans=false)
tmp = self.default_setting_prompt_word[k]
(tmp&&tmp[locale]) ? tmp[locale] : self.field_name(k,locale)
end
def prompt_word_translations(k)
I18n.available_locales.map{|v| [v.to_s,self.prompt_word(k,v.to_s)]}.to_h
end
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
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: 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: {}
field :default_setting_prompt_word, type: Hash,default: {}
field :custom_fields, type: Hash,default: {}
field :usage_rule
field :title_layout, type: Integer
field :last_ticket_key, type: Integer, default: 0
field :last_serial_number, type: Integer, default: 0
def get_attrs
attrs = self.attributes.clone
self.fields.each do |k, v|
@ -59,7 +102,21 @@ class AskSetting
attrs.delete(k)
end
end
attrs.except("_type","_id","uid","updated_at", "created_at", "email_regex", "last_ticket_key")
attrs.except("_type","_id","uid","updated_at", "created_at", "email_regex", "last_ticket_key", "default_setting_required", "last_serial_number")
end
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 += 1
else
AskSetting.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)
ask_setting = nil
@ -72,6 +129,9 @@ class AskSetting
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}
end
tmp = disp_fields[0...-4]
if only_display
tmp = tmp.select{|f| ask_setting.default_setting[f]}
@ -84,7 +144,10 @@ class AskSetting
ask_setting.custom_fields.each do |k,v|
trans = v["field"]
tmp_locales.each do |l|
trans = trans[l] if trans[l].present?
if trans[l].present?
trans = trans[l]
break
end
end
next if trans.class != String
tmp_k = "default@#{k}"
@ -101,9 +164,13 @@ class AskSetting
c.custom_fields.each do |k,v|
trans = v["field"]
tmp_locales.each do |l|
trans = trans[l] if trans[l].present?
if trans[l].present?
trans = trans[l]
break
end
end
next if trans.class != String
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"]}
@ -119,9 +186,9 @@ class AskSetting
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 do |k,h|
disp_fields_infos.each_with_index do |(k,h), i|
if h["sort_number"].blank?
h["sort_number"] = max_sort_number + h["key"].to_i
h["sort_number"] = max_sort_number + i
else
h["sort_number"] = h["sort_number"]
end
@ -130,4 +197,12 @@ class AskSetting
end
disp_fields_infos
end
def get_email_regex(frontend=false)
tmp = self.email_regex
if tmp
tmp = tmp.gsub("\\A","^").gsub("\\z","$").gsub("\\","\\\\\\\\")
end
tmp = nil if !(self.email_regex_enable) || (self.application_form_signup_field_sets.where(:field_name=>'email').pluck(:disabled)[0] rescue false)
tmp
end
end

View File

@ -180,7 +180,7 @@
</div>
</div>
<% end %>
<table>
<table class="table layoutfix_table">
<thead>
<tr>
<th>
@ -193,6 +193,9 @@
<th>
<%= t('ask.field_name') %>
</th>
<th>
<%= t('ask.prompt_word') %>
</th>
<% end %>
<th>
<%= t('ask.required') %>
@ -219,6 +222,13 @@
<td class="center">
<%= multiple_lang_tag(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
</td>
<td class="center">
<% if AskSetting::No_prompt_word.include?(k) %>
<%= t('ask.the_same_as_field_name') %>
<% else %>
<%= multiple_lang_tag(nil,'text_field',"default_setting_prompt_word][#{k}",ask_setting.prompt_word_translations(k),{placeholder: tmp}) %>
<% end %>
</td>
<% end %>
<% v = ask_setting.default_setting_required[k] %>
<td>
@ -252,6 +262,125 @@
<input class="btn btn-primary" type="submit" value="<%= submit_text %>">
</td>
</tr>
<% has_need_check_customs = (ask_setting.class == AskCategorySetting && (ask_setting.need_check_customs.count + ask_setting.reject_customs.count) != 0)
org_hide = ask_setting.class == AskCategorySetting ? (ask_setting.need_check_customs.count == 0) : true;
%>
<% if has_need_check_customs %>
<tr class="ask_setting_clone_fields">
<td colspan="2" style="text-align: center;">
<%= t('ask.default_custom_fields') %>
</td>
<td>
<span style="margin-right: 1em; font-weight: bold;" class="<%='hide' if ask_setting.reject_customs.count == 0 %>" id="display_discard_fields_block">
<input type="checkbox" id="display_discard_fields" style="float: left;">
<label for="display_discard_fields" style="float: left;"><%= t('ask.display_discard_fields') %></label>
</span>
<a class="apply_default_customs btn btn-success <%= 'hide' if org_hide %>" title="<%=t('ask.apply_all')%>" data-category="<%=ask_setting.category_id%>" data-apply-all="true"><%=t('ask.apply_all')%></a>
<a class="discard_default_customs btn btn-danger <%= 'hide' if org_hide %>" title="<%=t('ask.discard_changes')%>" data-category="<%=ask_setting.category_id%>" data-apply-all="true"><%=t('ask.discard_changes')%></a>
</td>
</tr>
<% end %>
</tbody>
<% if has_need_check_customs %>
<% (ask_setting.need_check_customs + ask_setting.reject_customs).sort_by{|k| k.to_i}.each do |k| %>
<% if ask_setting.reject_customs.include?(k) %>
<% other_first_rows = "<tr><td colspan=\"2\"><a class=\"apply_default_customs btn btn-success\" title=\"#{t('ask.apply')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.apply')}</a></td></tr>" %>
<%= custom_field_block(k, @default_ask_setting.custom_fields[k], true, other_first_rows, "discard_fields hide").html_safe %>
<% else %>
<% other_first_rows = "<tr><td colspan=\"2\"><a class=\"apply_default_customs btn btn-success\" title=\"#{t('ask.apply')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.apply')}</a><a class=\"discard_default_customs btn btn-danger\" title=\"#{t('ask.discard')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.discard')}</a></td></tr>" %>
<%= custom_field_block(k, @default_ask_setting.custom_fields[k], true, other_first_rows).html_safe %>
<% end %>
<% end %>
<script>
var show_customs_count = <%= ask_setting.need_check_customs.count %>;
$(".apply_default_customs, .discard_default_customs").off('click').on('click', function(){
var _this = $(this);
var category = _this.data('category');
var apply_all = _this.attr('data-apply-all') == 'true';
var apply_fields = _this.data('apply-field');
apply_fields = apply_fields ? [apply_fields] : [];
var agree = _this.hasClass('apply_default_customs');
var hint_text = "";
if(agree){
hint_text = '<%=t("ask.are_you_sure_to_apply")%>';
}else{
hint_text = '<%=t("ask.are_you_sure_to_discard")%>';
}
var display_discard_fields = $('#display_discard_fields').prop('checked');
if(window.confirm(hint_text)){
$.post('<%=apply_default_custom_fields_admin_asks_path%>', {
category: category, apply_all: apply_all,
apply_fields: apply_fields, agree: agree,
include_reject: display_discard_fields
}).done(function(data){
var table = _this.parents('table.layoutfix_table');
if(data["success"]){
if(!agree){
$('#display_discard_fields_block').removeClass('hide');
}
table.find('tr.add_field').before(data['html']);
if(apply_all){
show_customs_count = 0;
var find_target = 'tbody.custom_field';
if(!display_discard_fields){
find_target += ":not(.discard_default_customs)";
}
if(agree){
table.find(find_target).remove();
_this.parents('tr.ask_setting_clone_fields').remove();
}else{
var tmp = 'discard_fields';
if(!display_discard_fields){
tmp += ' hide';
}
table.find(find_target).addClass(tmp);
table.find('.discard_default_customs').remove();
}
}else{
show_customs_count -= 1;
if(agree){
_this.parents('tbody.custom_field').remove();
if(table.find('tbody.custom_field').length == 0)
table.find('.ask_setting_clone_fields').remove();
}else{
var tmp = 'discard_fields';
if(!display_discard_fields){
tmp += ' hide';
}
_this.parents('tbody.custom_field').addClass(tmp);
_this.remove();
}
}
}
})
}
})
$('#display_discard_fields').off('click').on('click', function(){
if($(this).prop('checked')){
$('tbody.custom_field.discard_fields').removeClass('hide');
var can_display = '.apply_default_customs';
if(show_customs_count > 0){
can_display += ', .discard_default_customs';
}
$('tr.ask_setting_clone_fields').find(can_display).removeClass('hide');
}else{
$('tbody.custom_field.discard_fields').addClass('hide');
if(show_customs_count > 0){
$('tr.ask_setting_clone_fields').find('.apply_default_customs, .discard_default_customs').removeClass('hide');
}else{
$('tr.ask_setting_clone_fields').find('.apply_default_customs, .discard_default_customs').addClass('hide');
}
}
})
</script>
<% end %>
</table>
<style>
.layoutfix_table{
table-layout: fixed;
}
.layoutfix_table th,.layoutfix_table td {
word-wrap: break-word;
}
</style>
</fieldset>

View File

@ -55,6 +55,9 @@
<td><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></td>
<!-- <td><%# AskQuestion.human_attribute_name(:fax) %><%# @ask_question.fax %></td> -->
</tr>
<tr>
<td colspan="5"><%= t('ask.serial_number') %><%= @ask_question.get_serial_number %></td>
</tr>
<tr>
<td colspan="5"><%= t('ask.ip') %><%= @ask_question.ip %></td>
</tr>

View File

@ -3,7 +3,7 @@
<tr class="sort-header">
<% @table_fields.each do |f| %>
<% tmp = f.to_s.gsub(/ask\./,'') %>
<% if @ask_setting.default_setting[tmp].nil? || @ask_setting.default_setting[tmp] %>
<% if true #@ask_setting.default_setting[tmp].nil? || @ask_setting.default_setting[tmp] %>
<%= thead(f) %>
<% end %>
<% end %>
@ -18,9 +18,12 @@
"is_published"=>"label-success"
}
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
last_serial_number = @ask_setting.last_serial_number
display_length = [last_serial_number.to_s.length + 1, 4].max
%>
<% @askquestions.each do |b| %>
<tr>
<td><%= b.get_serial_number(last_serial_number, display_length) %></td>
<td>
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
</td>

View File

@ -35,19 +35,21 @@
type = field_info["type"]
if ["select", "radio_button", "checkbox"].include?(type)
if type == "checkbox"
val = val.values
val = val.values rescue []
else
val = Array(val)
end
val = val.map{|v| field_info["options"][v][locale] rescue ""}.join("<br>").html_safe
elsif ["file", "image"].include?(type)
val = "<a href=\"#{@data['site_host']}#{val[1]}\">#{val[0]}</a>".html_safe
if val.present?
val = "<a href=\"#{@data['site_host']}#{val[1]}\">#{val[0]}</a>".html_safe
end
elsif type == "date"
val = val["datetime"].values[0].values
val = val["datetime"].values[0].values rescue []
if val.count == 2
val = val[0] + " ~ " + val[1]
val = val[0].gsub('-', '/') + " ~ " + val[1].gsub('-', '/')
else
val = val[0]
val = val[0].gsub('-', '/')
end
elsif type == "instructions"
val = field_info["instructions"][locale].to_s.html_safe rescue ""
@ -56,6 +58,8 @@
val = Category.find(val).title rescue ''
elsif f == 'usage_rule'
val = @data['usage_rule'].to_s.html_safe
elsif f == 'appointment'
val = question.appointment.strftime('%Y/%m/%d %H:%M') rescue ""
else
val = val.to_s.html_safe
end

View File

@ -3,6 +3,6 @@
<p>發問失敗,請重新發問!</p>
<p>Failed to ask questions, please re-ask!</p>
<div class="form-actions">
<input name="goback" type="button" class="btn" onclick="window.history.go(-1);" onkeypress="window.history.go(-1);" value="回上一頁">
<input name="goback" type="button" class="btn" onclick="window.history.go(-1);" onkeypress="window.history.go(-1);" value="<%=t('ask.go_back')%>">
</div>
</div>

View File

@ -7,5 +7,8 @@
text = t('ask.thank_text') if text.to_s.empty?
%>
<%= text.html_safe %>
<div class="form-actions">
<a class="btn" href="<%= OrbitHelper.request.path_info %>"><%=t('ask.go_back')%></a>
</div>
</h2>
</div>

View File

@ -34,7 +34,7 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]
s.metadata = {
"_require" => "#{File.expand_path("../app/models/ask_setting", __FILE__)}",
"global_hash" => "{last_ticket_key: (AskSetting.pluck(:last_ticket_key)[0] rescue 0)}"
"global_hash" => "{last_ticket_key: (AskSetting.pluck(:last_ticket_key)[0].to_i rescue 0), last_serial_number: (AskSetting.pluck(:last_serial_number)[0].to_i rescue 0)}"
}
# s.add_dependency ~> "gotcha"
end

View File

@ -2,6 +2,18 @@ en:
situation: Status
sex: Sex
ask:
go_back: "Go back"
this_field_is_default_custom_fields: "This field is default custom fields(Not editable)"
display_discard_fields: "Display discard fields"
are_you_sure_to_apply: "Are you sure to apply?"
are_you_sure_to_discard: "Are you sure to discard?"
apply: "Apply"
discard: "Discard"
apply_all: "Apply All"
discard_changes: "Discard Changes"
default_custom_fields: "Default custom fields"
serial_number: "No."
the_same_as_field_name: "The same as Field Name"
recover_data: "Recover Data"
are_you_sure_to_recover_data: "Are you sure to recover data?"
are_you_sure_to_switch_to_default_setting: "Are you sure to switch to default setting?"

View File

@ -6,6 +6,18 @@ zh_tw:
errors:
verification_failed: 驗證碼錯誤
ask:
go_back: "回上一頁"
this_field_is_default_custom_fields: "此欄位為預設客製化欄位(不可修改)"
display_discard_fields: "顯示捨棄的欄位"
are_you_sure_to_apply: "您確定要套用嗎?"
are_you_sure_to_discard: "您確定要捨棄嗎?"
apply: "套用"
discard: "捨棄"
apply_all: "套用全部"
discard_changes: "捨棄變更"
default_custom_fields: "預設客製化欄位"
serial_number: "單號"
the_same_as_field_name: "與欄位名稱相同"
recover_data: "復原資料"
are_you_sure_to_recover_data: "您確定要復原資料嗎?"
are_you_sure_to_switch_to_default_setting: "您確定要切換成預設設定嗎?"

View File

@ -2,24 +2,50 @@ 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
ask_setting = AskSetting.first
if ask_setting.nil?
ask_setting = AskSetting.create
else
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.to_h
ask_setting.save
end
AskCategorySetting.all.each do |ask_setting|
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.to_h
ask_setting.save
end
default_keys = AskTicketStatus::DefaultKeys
if AskTicketStatus.count < default_keys.count
default_keys.each do |k|
ticket_status = AskTicketStatus.where(:is_default=>true,:key=>k).first
if ticket_status.nil?
AskTicketStatus.create(:is_default=>true,:key=>k, :title_translations=>locales.map{|l| [l.to_s, I18n.with_locale(l){I18n.t("ask.#{k}")}]}.to_h )
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'))
if need_update
ask_setting = AskSetting.first
check_custom_fields = {}
if ask_setting.nil?
ask_setting = AskSetting.create
else
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.sort_by{|k,v| v}.to_h
AskSetting::No_required.each do |f|
ask_setting.default_setting_required.delete(f)
end
ask_setting.save
check_custom_fields = ask_setting.custom_fields.map{|k,v| [k, v["field"][I18n.default_locale.to_s]]}.to_h
end
default_setting_field_name = ask_setting.default_setting_field_name
AskCategorySetting.all.each do |ask_setting|
ask_setting.sort_number = ask_setting.sort_number.map{|k,v| [k, v.to_i]}.sort_by{|k,v| v}.to_h
AskSetting::No_required.each do |f|
ask_setting.default_setting_required.delete(f)
end
ask_setting.default_setting_field_name = default_setting_field_name
ask_setting.update_need_check_customs(check_custom_fields, true, true)
ask_setting.save
end
default_keys = AskTicketStatus::DefaultKeys
if AskTicketStatus.count < default_keys.count
default_keys.each do |k|
ticket_status = AskTicketStatus.where(:is_default=>true,:key=>k).first
if ticket_status.nil?
AskTicketStatus.create(:is_default=>true,:key=>k, :title_translations=>locales.map{|l| [l.to_s, I18n.with_locale(l){I18n.t("ask.#{k}")}]}.to_h )
end
end
end
AskQuestion.where(:serial_number=>nil).asc(:id).each do |a|
last_serial_number = AskSetting.update_last_serial_number
a.serial_number = last_serial_number
a.save
end
if update_flag
s = OrbitHelper::SharedHash['current_site']['site'] rescue Site.first
s.tmp_flags << 'askf1'
s.save
end
end
end
@ -52,6 +78,7 @@ Rails.application.routes.draw do
post 'export', to: 'asks#do_export'
get 'order_fields'
post 'update_order_fields'
post 'apply_default_custom_fields'
end
end
resources :ask_acknowledgements

View File

@ -157,4 +157,4 @@ module Ask
end
end
end
end
end