Add ticket status setting.
Display all items in email.
Fix order bug,
Add required setting.
This commit is contained in:
BoHung Chiu 2022-07-07 16:54:09 +08:00
parent 164357aedf
commit 92285feef3
24 changed files with 1055 additions and 285 deletions

View File

@ -71,17 +71,25 @@ class Admin::AsksController < OrbitAdminController
ask_setting.update_attributes(p1)
redirect_to "/#{locale}/admin/asks"
end
def switch_to_default_setting
if AskCategorySetting.where(:id=>params[:id]).update_all(:use_default=>params[:use_default] == "true").documents[0]["nModified"] != 0
render :json => {success: true}
else
render :json => {success: false}
end
end
def category_setting_save
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')
ask_setting.update_attributes(p1)
puts ask_setting.inspect
puts ["update!", p1]
ask_setting.update!(p1)
redirect_to "/#{locale}/admin/asks/category_setting"
end
def setting
@ask_setting = AskSetting.first
@ask_setting = AskSetting.create() if @ask_setting.nil?
@url = setting_save_admin_asks_path
end
def get_new_setting_index
@ -101,12 +109,11 @@ class Admin::AsksController < OrbitAdminController
def index
AskPrintSetting.create() if AskPrintSetting.first.nil?
@ask_setting = AskSetting.first
@ask_setting = AskSetting.create() if @ask_setting.nil?
@tags = @module_app.tags
@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']
@table_fields = [:situation, :category, 'title' , 'ask.name', 'ask.phone', 'ask.appointment','ask.created_at','ask.ip']
# 列表排序
# debugger
if filter2("situation").blank? and filter2("identity").blank?
@ -142,17 +149,9 @@ class Admin::AsksController < OrbitAdminController
@categories = current_user.approved_categories_for_module(@module_app).sort_by{|category| (((@module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
@category_ids = @categories.collect(&:id)
@category_titles = @categories.collect{|v| v.title}
@category_added = AskCategorySetting.all.asc(:created_at)
@category_added_ids = @category_added.pluck(:category_id)
@category_not_add_index = @category_ids.to_enum.with_index.select{|v,i| @category_added_ids.exclude? v.to_s}.collect{|v,i| i}
@category_not_add = @category_titles.values_at(*@category_not_add_index).zip(@category_ids.values_at(*@category_not_add_index))
@category_print_added = AskCategoryPrintSetting.all.asc(:created_at)
@category_print_added_ids = @category_print_added.pluck(:category_id)
@category_print_not_add_index = @category_ids.to_enum.with_index.select{|v,i| @category_print_added_ids.exclude? v.to_s}.collect{|v,i| i}
@category_print_not_add = @category_titles.values_at(*@category_print_not_add_index).zip(@category_ids.values_at(*@category_print_not_add_index))
@category_added = AskCategorySetting.all.asc(:created_at).map{|a| [a.category_id, a]}.to_h
@category_added_ids = @category_added.map{|k,v| k}
@url = category_setting_save_admin_asks_path
end
def get_category_setting_field
@default_ask_setting = AskSetting.first
@ -294,7 +293,6 @@ class Admin::AsksController < OrbitAdminController
ask_setting = AskCategorySetting.where(category_id: params['ask_question']['category_id']).first
if ask_setting.nil?
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
end
if temp_params['custom_values'].nil?
temp_params['custom_values'] = {}
@ -402,42 +400,125 @@ class Admin::AsksController < OrbitAdminController
def order_fields
@cats_relations = get_categories_info
@category_id = (params[:category] || @cats_relations[0][0] rescue nil)
@disp_fields_infos = AskSetting.get_disp_fields_infos(@category_id)
@disp_fields_infos = AskSetting.get_disp_fields_infos(false,@category_id)
end
def update_order_fields
if params[:category]
ask_setting = AskCategorySetting.where(:category_id=>params[:category]).first
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 ask_setting.nil?
default_setting = AskSetting.first
default_setting = AskSetting.create if default_setting.nil?
ask_setting = AskCategorySetting.create(category_id: params[:category])
p1 = default_setting.get_attrs
ask_setting.update_attributes(p1)
ask_setting.update(:use_default => true)
end
ask_setting.update(:sort_number=>params[:sort_number])
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
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)
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
AskSetting.update_all(:sort_number=>params[:sort_number])
ask_setting = AskSetting.first
if use_default
sort_number = ask_setting.sort_number.merge(sort_number)
end
AskSetting.update_all(:sort_number=>sort_number)
unless use_default
custom_sort_number = sort_number.select{|k, v| k.include?('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
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)
end
if non_intersect_keys.count != 0
max_sort_number = 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]}
sort_number = sort_number.merge(part_sort_number.to_h)
end
ask_setting.update(:sort_number=>sort_number)
end
end
end
end
render :json => {:success=>true}
end
def ticket_status
@ticket_statuses = AskTicketStatus.all
if request.xhr?
render 'ticket_status', :layout => false
end
end
def get_ticket_status
ticket_status = AskTicketStatus.where(:id=>params[:id]).first
render :json => {
"id"=>params[:id],
"title_translations"=> (ticket_status ? ticket_status.get_title_translations : {})
}
end
def update_ticket_status
if params[:id].blank?
ticket_status = AskTicketStatus.new
else
ticket_status = AskTicketStatus.where(:id=>params[:id]).first
end
ticket_status.update_attributes(params.require(:ask_ticket_status).permit!)
render :json => {:success=>true}
end
def delete_ticket_status
ticket_status = AskTicketStatus.where(:id=>params[:id]).first
unless ticket_status.is_default
ticket_status.destroy
end
render :json => {:success=>true}
end
private
def ask_setting_params(ask_setting,collection_name)
param = params.require(collection_name).permit!
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'].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')
custom_fields = ask_setting['custom_fields'].clone
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|
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
end
end
param_clone.merge({custom_fields: custom_fields})
param_clone.merge({"custom_fields"=> custom_fields})
end
end

View File

@ -18,15 +18,21 @@ class AsksController < ApplicationController
else
categories = Category.where(:id.in=>OrbitHelper.widget_categories).enabled
end
categories = categories.sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
if (module_app.asc rescue true)
categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)}
else
categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)}
end
tags = module_app.tags
ask_question = AskQuestion.new
locale = I18n.locale
ask_settings = AskCategorySetting.where(:category_id.in=> categories.collect{|v| v.id.to_s}).to_a
category_ids = categories.collect{|v| v.id.to_s}
ask_settings = AskCategorySetting.enabled.where(:category_id.in=> category_ids).to_a
first_category_id = category_ids.first
ask_setting = ask_settings.select{|a| a.category_id == first_category_id}.first
if ask_settings.count != categories.count
ask_settings = [AskSetting.first]+ask_settings
end
ask_setting = AskCategorySetting.where(category_id: categories.first.id.to_s).first
if ask_setting.nil?
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
@ -100,7 +106,7 @@ class AsksController < ApplicationController
end
def show
ask_question = AskQuestion.where(id: @params['item']).first
ask_setting = AskCategorySetting.where(category_id: ask_question.category_id.to_s).first
ask_setting = AskCategorySetting.enabled.where(category_id: ask_question.category_id.to_s).first
ask_setting = AskSetting.first if ask_setting.nil?
{'ask_question' => ask_question,'layout_type'=>'show','ask_setting'=>ask_setting}
end
@ -125,12 +131,18 @@ class AsksController < ApplicationController
else
categories = Category.where(:id.in=>OrbitHelper.page_categories).enabled
end
categories = categories.sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)} if !(categories.include?("all"))
ask_settings = AskCategorySetting.where(:category_id.in=> categories.collect{|v| v.id.to_s}).to_a
if (module_app.asc rescue true)
categories = categories.sort_by{|category| (category.sort_number.to_i rescue category.id)}
else
categories = categories.sort_by{|category| (-category.sort_number.to_i rescue category.id)}
end
category_ids = categories.collect{|v| v.id.to_s}
ask_settings = AskCategorySetting.enabled.where(:category_id.in=> category_ids).to_a
first_category_id = category_ids.first
ask_setting = ask_settings.select{|a| a.category_id == first_category_id}.first
if ask_settings.count != categories.count
ask_settings = [AskSetting.first]+ask_settings
end
ask_setting = AskCategorySetting.where(category_id: categories.first.id.to_s).first
if ask_setting.nil?
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
@ -178,10 +190,10 @@ class AsksController < ApplicationController
if !params[:referer_url].blank? && !params[:referer_url].to_s.start_with?("/")
render :file => "#{Rails.root}/app/views/errors/403.html", :layout => false, :status => 403 and return
end
@ask_question = AskQuestion.new()
@ask_question = AskQuestion.new(:ip=>request.remote_ip)
temp_params = create_params
all_to_save = []
ask_setting = AskCategorySetting.where(category_id: params['ask_question']['category_id']).first
ask_setting = AskCategorySetting.enabled.where(category_id: params['ask_question']['category_id']).first
email_regex = nil
if ask_setting.nil?
ask_setting = AskSetting.first
@ -208,7 +220,9 @@ class AsksController < ApplicationController
temp_params['custom_values'][to_save[0]] = [temp_params['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
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)
@usage_rule = ask_setting.usage_rule
@ask_question.update_attributes(temp_params)
build_email(@ask_question)
redirect_to "#{params[:referer_url]}?method=thank"
@ -239,7 +253,10 @@ class AsksController < ApplicationController
site = current_site rescue Site.first
mail_from = site.title_translations[site.default_locale]
host_url = Site.first.root_url rescue "http://"
if host_url == "http://"
host_url = request.protocol + request.host_with_port
end
email_er.email.update_attributes(
:mail_lang=> site.default_locale,
:create_user=>(current_user rescue nil),
@ -256,7 +273,11 @@ class AsksController < ApplicationController
"phone" => email_er.phone,
# "fax" => email_er.fax,
# "content" => email_er.content
"appointment" => email_er.appointment
"appointment" => email_er.appointment,
"disp_fields_infos" => @disp_fields_infos,
"ask_question_id" => email_er.id.to_s,
"site_host" => host_url,
"usage_rule" => @usage_rule
}
)
@ -268,14 +289,17 @@ 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(ask_setting.class == AskCategorySetting ? ask_setting.category_id : nil)
disp_fields_infos = AskSetting.get_disp_fields_infos(true, ask_setting.class == AskCategorySetting ? ask_setting.category_id : nil)
if filter_fields
disp_fields_infos = disp_fields_infos.select{|field, info| filter_fields.include?(field)}
end
tmp = 'mongoid.attributes.ask_question'
defalt_fields = [{'style_html'=>'','label'=>ask_label(t('title'),'true'),'content'=>text_field_tag('ask_question[title]',nil,placeholder: t('title'),required: true)}]
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_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@")
k = field[8..-1]
@ -304,34 +328,34 @@ class AsksController < ApplicationController
end
else
if ask_setting.default_setting[field] || field == "usage_rule"
required = ['phone','appointment'].exclude?(field) ? 'true' : 'false'
f1 = {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("#{field}"),required)}
required = ask_setting.default_setting_required[field]
f1 = {'style_html'=>'','label'=>ask_label(@default_ask_setting.field_name("#{field}"),required.to_s)}
field_name = "ask_question[#{field}]"
case field
when 'name'
f1['content'] = text_field_tag(field_name,nil,data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"},required: true,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:@default_ask_setting.field_name("#{field}"))
when 'sex'
f1['content'] = "<label class=\"radio-inline\">
#{radio_button_tag(field_name,'male')}#{I18n.t('users.male')}
#{radio_button_tag(field_name,'male', false, {required: required})}#{I18n.t('users.male')}
</label>
<label class=\"radio-inline\">
#{radio_button_tag(field_name,'female')}#{I18n.t('users.female')}
#{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: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"},required: true,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:@default_ask_setting.field_name("#{field}"))
when 'phone'
f1['content'] = text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"))
f1['content'] = text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"),required: required)
when 'appointment'
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"))}</div>"
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,nil,placeholder:@default_ask_setting.field_name("#{field}"),required: required)}</div>"
when 'recaptcha'
f1['content'] = "#{gotcha_error}#{gotcha}"
when 'usage_rule'
next if ask_setting.usage_rule.blank?
f1['content'] = ask_setting.usage_rule
when 'agree_show'
f1['content'] = check_box_tag('ask_question[agree_show]')
f1['content'] = check_box_tag('ask_question[agree_show]', "1", false, {required: required})
when 'agree_usage'
f1['content'] = check_box_tag('ask_question[agree_usage]')
f1['content'] = check_box_tag('ask_question[agree_usage]', "1", false, {required: required})
end
defalt_fields << f1
end

View File

@ -16,11 +16,22 @@ module Admin::AsksHelper
OrbitHelper.set_this_module_app("ask")
cats_relations = []
access_level = OrbitHelper.user_access_level?
include_all = false
cats = []
if access_level == "sub_manager"
cats_relations = current_user.approved_categories_for_module(@module_app).map{|c| [c.id.to_s, c.title]}
cats = current_user.approved_categories_for_module(@module_app)
elsif access_level && access_level != "user"
cats = @module_app.categories.enabled
cats_relations = [["",t(:all)]] + cats.map{|c| [c.id.to_s, c.title]}
include_all = true
end
if (@module_app.asc rescue true)
cats = cats.sort_by{|category| (category.sort_number.to_i rescue category.id) }
else
cats = cats.sort_by{|category| (-category.sort_number.to_i rescue category.id)}
end
cats_relations = cats.map{|c| [c.id.to_s, c.title]}
if include_all
cats_relations.insert(0, ["",t(:all)])
end
cats_relations
end
@ -39,6 +50,38 @@ module Admin::AsksHelper
end.join.html_safe
end
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(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
end
tmp = (I18n.available_locales.collect do |locale|
active_flag = ((locale == I18n.locale) ? ' active' : '')
content_tag(:div,:class => "tab-content#{active_flag}",:id=>"#{all_field}_#{locale}") do
value_locale = value[locale.to_s] rescue nil
"<div class=\"show_field\" id=\"#{index1 ? "#{get_input_name}[#{index1}][#{field}][#{locale}]" : "#{get_input_name}[#{field}][#{locale}]"}\">#{value_locale}</div>".html_safe
end
end.join + create_lang_panel(all_field)).html_safe + combine_element
if sortable
if exteral_options['style'].nil?
exteral_options['style'] = 'display: flex;align-items: center;flex-wrap: nowrap;'
else
exteral_options['style'] = exteral_options['style'] + 'display: flex;align-items: center;flex-wrap: nowrap;'
end
tmp = content_tag(:div,{:class => "tab-panel border"}.merge(exteral_options)) do
("<i class=\"icons-list-2\" style=\"cursor: grab;font-size: x-large;\"></i>" +content_tag(:div) do
tmp
end).html_safe
end
else
tmp = content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
tmp
end
end
tmp = "<tr><td>#{field_name}".html_safe + ":</td><td>".html_safe + tmp + "</td></tr>".html_safe
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(/\]/,'')
@ -170,6 +213,8 @@ module Admin::AsksHelper
case v['type']
when 'text_field'
readonly ? value : text_field_tag(field_name,value,{:required => v['required']=='true',placeholder: v['prompt_word'][I18n.locale]})
when 'instructions'
(v['instructions'][I18n.locale].html_safe rescue "")
when 'select'
prompt_hash = v['prompt_word'][I18n.locale].blank? ? {} : {prompt: v['prompt_word'][I18n.locale]}
prompt_hash.merge(:required => v['required']=='true')
@ -221,7 +266,7 @@ module Admin::AsksHelper
file_path = value[1] rescue nil
file_required = v['required']=='true' ? 'required="required"' : ''
readonly ? "<a href=\"#{file_path}\" title=\"file\">#{file_value}</a>" : "<div class=\"file-selector\"><label class=\"ui-button\">
<input data-src=\"#{file_path}\" style=\"position: absolute;width:0.00000001em;opacity: 0;\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
<input data-src=\"#{file_path}\" style=\"position: absolute;width:0.1em;opacity: 0;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
<i class=\"fa fa-file\"></i> #{t('ask.upload_file')}
</label><div class=\"filename\"></div></div>"
when 'image'
@ -229,7 +274,7 @@ module Admin::AsksHelper
file_path = value[1] rescue nil
file_required = v['required']=='true' ? 'required="required"' : ''
readonly ? "<img src=\"#{file_path}\" alt=\"#{file_value}\">" : "<div class=\"file-selector\"><label class=\"ui-button\">
<input data-image-src=\"#{file_path}\" style=\"position: absolute;width:0.00000001em;\" accept=\"image/*\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
<input data-image-src=\"#{file_path}\" style=\"position: absolute;width:0.1em;padding: 0;border: 0;opacity: 0;left: 50%;top: 0;\" accept=\"image/*\" class=\"upload\" name=\"#{field_name}\" #{file_required} type=\"file\" value=\"#{file_value}\"/>
<i class=\"fa fa-photo\"></i> #{t('ask.upload_image')}
</label><div class=\"filename\"></div></div>"
end
@ -237,35 +282,65 @@ module Admin::AsksHelper
"<pre>#{e.inspect}<br>#{e.backtrace.to_yaml}</pre>"
end
end
def custom_field_block(k,v={})
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']]
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)'})
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)}"
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>"
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>"
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\">
<td>
def custom_field_block(k,v={},show_only=false)
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'])
require_ask_tag = "<tr><td>#{t('ask.required')}:</td><td>#{v['required']=='true' ? t('ask.yes') : t('ask.no')}</td></tr>"
markups = markups.map{|k,v| [v,k]}.to_h
tmp = markups[v['type']]
tmp = markups.values[0] if tmp.nil?
field_select_tag = "<tr><td>#{t('ask.setting_type')}:</td><td><div id=\"#{get_input_name}[#{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(t('ask.prompt_word'),k,'prompt_word',v['prompt_word'])
field_html = "
<style>
.show_field {
border: 1px solid black;
padding: 3px;
min-width: 1em;
height: 20px;
overflow-y: auto;
}
</style>
<tbody class=\"custom_field\">
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}<br>
#{field_select_tag}
#{multi_lang_prompt_tag}
#{time_setting_block(k,v)}
#{tmp}
#{key}
</td>
<td>
#{create_delete_button('delete_field_func')}
</td>
</tr>"
</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)'})
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)}"
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>"
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\">
<td>
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}<br>
#{multi_lang_prompt_tag}
#{instructions_text_area}
#{time_setting_block(k,v)}
#{tmp}
#{key}
</td>
<td>
#{create_delete_button('delete_field_func')}
</td>
</tr>"
end
end
def create_delete_button(func_name)
"<input class=\"btn btn-danger\" type=\"button\" value=\"#{t('delete_')}\" onclick=\"#{func_name}(this)\">"

View File

@ -34,14 +34,15 @@ class AskCategorySetting
I18n.available_locales.map{|v| [v.to_s,self.field_name(k,v.to_s)]}.to_h
end
field :sort_number, type: Hash, default: {}
field :default_setting, type: Hash,default: {ask_category_id: true,name: true,sex: false,mail: true,phone: false,appointment: false,recaptcha: false,agree_show: true,agree_usage: false}
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_field_name, type: Hash,default: {}
field :use_default, type: Boolean, default: false
field :custom_fields, type: Hash,default: {}
field :usage_rule
field :category_id
field :title_layout, type: Integer
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
scope :enabled, ->{where(:use_default.ne=>true)}
end

View File

@ -3,9 +3,10 @@ class AskQuestion
include Mongoid::Timestamps
# include ActiveModel::Validations
include OrbitCategory::Categorizable
include OrbitTag::Taggable
# include OrbitTag::Taggable
# 欄位
field :ip, type: String
field :name, type: String
field :identity, type: String
field :mail, type: String
@ -46,7 +47,7 @@ class AskQuestion
end
end
email_address.uniq!
# email_address = email_address +[self.mail] if !self.mail.blank?
email_address = email_address +[self.mail] if !self.mail.blank?
email_address.flatten
end

View File

@ -43,12 +43,14 @@ class AskSetting
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: {ask_category_id: true,name: true,sex: false,mail: true,phone: false,appointment: false,recaptcha: false,agree_show: true,agree_usage: false}
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_field_name, 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
def get_attrs
attrs = self.attributes.clone
self.fields.each do |k, v|
@ -57,20 +59,25 @@ class AskSetting
attrs.delete(k)
end
end
attrs.except("_type","_id","uid","updated_at", "created_at", "email_regex")
attrs.except("_type","_id","uid","updated_at", "created_at", "email_regex", "last_ticket_key")
end
def self.get_disp_fields_infos(cat=nil)
def self.get_disp_fields_infos(only_display=true, cat=nil)
ask_setting = nil
if cat.present?
ask_setting = AskCategorySetting.where(:category_id=>cat).first
ask_setting = AskCategorySetting.enabled.where(:category_id=>cat).first
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
disp_fields[0...-4].each do |f|
disp_fields_infos[f] = {"trans"=>ask_setting.field_name(f,locale),"sort_number"=>ask_setting.sort_number[f]}
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]}
end
tmp_locales = I18n.available_locales.map{|l| l.to_s}
tmp_locales = [locale] + (tmp_locales - [locale])
@ -81,13 +88,13 @@ class AskSetting
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]}
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"]}
end
ask_category_settings = []
if ask_setting.class == AskCategorySetting || cat.present?
ask_category_settings = []
else
ask_category_settings = AskCategorySetting.all.to_a
ask_category_settings = AskCategorySetting.enabled.to_a
end
ask_category_settings.each do |c|
cat = Category.find(c.category_id)
@ -99,20 +106,24 @@ class AskSetting
next if trans.class != String
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]}
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"]}
end
end
disp_fields[-4..-1].each do |f|
disp_fields_infos[f] = {"trans"=>ask_setting.field_name(f,locale),"sort_number"=>ask_setting.sort_number[f]}
tmp = disp_fields[-4..-1]
if only_display
tmp = tmp.select{|f| ask_setting.default_setting[f] || f == 'usage_rule'}
end
max_sort_number = disp_fields_infos.values.map{|h| h["sort_number"].to_i}.max
tmp.each do |f|
disp_fields_infos[f] = {"trans"=>default_ask_setting.field_name(f,locale),"sort_number"=>ask_setting.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 do |k,h|
if h["sort_number"].blank?
h["sort_number"] = max_sort_number
h["sort_number"] = max_sort_number + h["key"].to_i
else
h["sort_number"] = h["sort_number"].to_i
h["sort_number"] = h["sort_number"]
end
end
disp_fields_infos = disp_fields_infos.sort_by {|_key, value| value["sort_number"]}

View File

@ -0,0 +1,42 @@
class AskTicketStatus
include Mongoid::Document
include Mongoid::Timestamps
DefaultKeys = ["is_waiting", "is_processed", "is_referral", "is_published"]
field :title, type: String, localize: true
field :is_default, type: Boolean, default: false # if true => cannot delete
field :key, type: String
before_create do
if self.key.blank?
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
last_ticket_key = can_update_shared_hash ? OrbitHelper::SharedHash["ask"][:last_ticket_key] : AskSetting.pluck(:last_ticket_key)[0].to_i
self.key = last_ticket_key.to_s
AskSetting.all.inc({'last_ticket_key'=>1})
if can_update_shared_hash
OrbitHelper::SharedHash["ask"][:last_ticket_key] = last_ticket_key + 1
end
end
true
end
after_destroy do
# can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
# AskSetting.all.inc({'last_ticket_key'=>-1})
# if can_update_shared_hash
# OrbitHelper::SharedHash["ask"][:last_ticket_key] = OrbitHelper::SharedHash["ask"][:last_ticket_key] - 1
# end
end
def title
tmp = super
if self.is_default
tmp = I18n.t("ask.#{self.key}") if tmp.blank?
end
tmp
end
def get_title_translations(locales=nil)
locales = I18n.available_locales if locales.nil?
trans = {}
locales.each do |locale|
trans[locale] = I18n.with_locale(locale){self.title}
end
trans
end
end

View File

@ -43,7 +43,7 @@
.center .tab-panel{
justify-content: start;
}
tr.custom_field {
tr.custom_field, tbody.custom_field {
border: 0.1em solid #8e00ff;
}
tr.custom_field > td >div {
@ -64,23 +64,30 @@
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')
parent_div.find('.prompt_word').addClass('active');
}else{
parent_div.find('.prompt_word').removeClass('active')
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').addClass('active');
}else{
parent_div.find('.add_new_options').removeClass('active')
parent_div.find('.add_new_options').removeClass('active');
}
if (tmp == 'instructions'){
parent_div.find('.instructions_text_area').removeClass('hide');
parent_div.find('.prompt_word').removeClass('active');
}else{
parent_div.find('.instructions_text_area').addClass('hide');
parent_div.find('.prompt_word').addClass('active');
}
if (tmp == 'date'){
parent_div.find('.time_setting_block').addClass('active')
parent_div.find('.time_setting_block').addClass('active');
}else{
parent_div.find('.time_setting_block').removeClass('active')
parent_div.find('.time_setting_block').removeClass('active');
}
}
function delete_field_func(ele){
$(ele).parents('tr').remove()
$(ele).parents('tr').hide()
var all_delete_field = $('.delete_field').val()
all_delete_field = all_delete_field + ',' + $(ele).parents('tr').find('.key').val()
$('.delete_field').val(all_delete_field)
@ -113,6 +120,24 @@
set_input_name("#{form_type}")
%>
<fieldset>
<% if @has_switch_button %>
<div class="control-group">
<div class="control-label">
<a href="#" class="btn btn-danger cancel_edit" data-parent=".default_ask_setting"><%= t("ask.cancel_edit") %></a>
</div>
<div class="controls">
</div>
</div>
<% elsif form_type!= 'ask_setting' %>
<div class="control-group">
<div class="control-label">
<a href="#" class="btn btn-success switch_to_default" data-id="<%=f.object.id%>" data-use-default="true"><%= t("ask.use_default") %></a>
<%= hidden_field_tag "#{f.object_name}[use_default]", false %>
</div>
<div class="controls">
</div>
</div>
<% end %>
<div class="control-group">
<div class="control-label">
<label for="ask_title_layout"><%= t("ask.title_layout") %>:</label>
@ -141,6 +166,19 @@
}
})
</script>
<% else %>
<div class="control-group">
<div class="control-label">
<%= t("ask.email_regex") %>:
</div>
<div class="controls">
<%= check_box_tag :email_regex_enable, @default_ask_setting.email_regex_enable , nil , {:id=>"",:disabled=>'disabled'} %><%= t("ask.enable") %>
<div style="clear: both;"></div>
<div class="show_field">
<%= @default_ask_setting.email_regex %>
</div>
</div>
</div>
<% end %>
<table>
<thead>
@ -154,13 +192,22 @@
<% if form_type=='ask_setting' %>
<th>
<%= t('ask.field_name') %>
</td>
</th>
<% end %>
<th>
<%= t('ask.required') %>
</th>
</tr>
</thead>
<tbody>
<% locale = I18n.locale.to_s %>
<% ask_setting.default_setting.each do |k,v| %>
<%
default_setting = ask_setting.default_setting
if default_setting.keys[0].to_s != 'title'
default_setting = {title: true}.merge(default_setting)
end
%>
<% default_setting.each do |k,v| %>
<tr>
<td>
<%= tmp = (form_type=='ask_setting' ? ask_setting.default_field_name(k,locale, true) : @default_ask_setting.field_name(k,locale, true)) %>
@ -173,6 +220,10 @@
<%= multiple_lang_tag(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
</td>
<% end %>
<% v = ask_setting.default_setting_required[k] %>
<td>
<%= select_tag "#{get_input_name}[default_setting_required][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
</tr>
<% end %>
<% set_input_name(tmp_get_input_name) %>

View File

@ -1,8 +1,7 @@
<%
set_input_name('ask_category_setting[custom_fields]')
%>
<%= form_for ask_setting,method: 'post',url: "/#{I18n.locale}/admin/asks/category_setting_save",html: { class: "form-horizontal fade-in active detail", 'id' => ask_setting.id.to_s ,:id => ask_setting.id} do |f| %>
<%= form_for ask_setting,method: 'post',url: category_setting_save_admin_asks_path ,html: { class: "form-horizontal fade-in active detail", 'id' => ask_setting.id.to_s ,:id => ask_setting.id} do |f| %>
<%= render partial: 'ask_setting',locals:{ask_setting: ask_setting,f: f,submit_text: t('ask.modify')} %>
<%= hidden_field_tag "category_id",ask_setting.category_id %>
<button type="button" class="btn btn-danger" onclick="window.location='<%= "/#{I18n.locale}/admin/asks/category_setting_delete?id=#{ask_setting.id}" %>'"><%= t('delete_') %></button>
<% end %>

View File

@ -0,0 +1,13 @@
<div id="default_ask_setting" class="<%= 'hide' if @is_hidden %>">
<div class="show_default_ask_setting">
<%= render :partial => 'show_default_ask_setting' %>
</div>
<div class="default_ask_setting hide">
<%= form_for @default_ask_setting, method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
<% f.object_name = 'ask_category_setting' %>
<%= hidden_field_tag "not_clone_attrs", true , :class=> 'not_clone_attrs' %>
<%= hidden_field_tag "category_id", @first_category_id , :class=> 'hidden_category_id' %>
<%= render partial: 'ask_setting',locals:{ask_setting: @default_ask_setting,f: f,submit_text: t('submit'), :@has_email_regex => false, :@has_switch_button => true} %>
<% end %>
</div>
</div>

View File

@ -56,12 +56,17 @@
<!-- <td><%# AskQuestion.human_attribute_name(:fax) %><%# @ask_question.fax %></td> -->
</tr>
<tr>
<td colspan="5"><%= t('title') %><%= @ask_question.title %></td>
<td colspan="5"><%= t('ask.ip') %><%= @ask_question.ip %></td>
</tr>
<tr>
<td colspan="5"><%= AskQuestion.human_attribute_name(:appointment) %><%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><%# @ask_question.name %></td> -->
<td colspan="5"><%= t('title') %><%= @ask_question.title %></td>
</tr>
<% if ask_setting.default_setting['appointment'] %>
<tr>
<td colspan="5"><%= AskQuestion.human_attribute_name(:appointment) %><%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><%# @ask_question.name %></td> -->
</tr>
<% end %>
<tr>
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><br/><%# @ask_question.name.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td> -->
</tr>
@ -83,12 +88,7 @@
</tr>
<tr>
<td colspan="5"><%= f.label t('situation') %>
<%= f.select :situation, [
[t('ask.is_waiting'), 'is_waiting'],
[t('ask.is_processed'), 'is_processed'],
[t('ask.is_referral'), 'is_referral'],
[t('ask.is_published'),'is_published']
] %>
<%= f.select :situation, AskTicketStatus.all.map{|a| [a.title, a.key]} %>
</td>
</tr>

View File

@ -10,18 +10,19 @@
</tr>
</thead>
<tbody>
<%
situation_class_relation = {
"is_waiting"=>"label-important",
"is_processed"=>"label-warning",
"is_referral"=>"",
"is_published"=>"label-success"
}
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
%>
<% @askquestions.each do |b| %>
<tr>
<td>
<% if b.situation == 'is_waiting' %>
<span class='label label-important'><%= t('ask.is_waiting') %></span>
<% elsif b.situation == 'is_processed' %>
<span class='label label-warning'><%= t('ask.is_processed') %></span>
<% elsif b.situation == 'is_referral' %>
<span class='label'><%= t('ask.is_referral') %></span>
<% elsif b.situation == 'is_published' %>
<span class='label label-success'><%= t('ask.is_published') %></span>
<% end %>
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
</td>
<td>
<%= b.category.title rescue 'category not set' %>
@ -54,6 +55,7 @@
<td><%= b.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<% end %>
<td><%= b.created_at.strftime("%Y-%m-%d %H:%M") rescue nil %></td>
<td><%= b.ip %></td>
</tr>
<% end %>
</tbody>

View File

@ -0,0 +1,77 @@
<fieldset>
<style>
.show_field {
border: 1px solid black;
padding: 3px;
min-width: 1em;
height: 20px;
overflow-y: auto;
}
</style>
<table class="table">
<tbody>
<tr>
<td>
<a href="#" class="btn btn-primary clone_default_setting" data-parent=".show_default_ask_setting"><%= t('ask.clone_default_setting') %></a>
<a href="#" class="btn btn-success recover_data switch_to_default <%= 'hide' if @first_setting.nil? %>" data-parent=".show_default_ask_setting" data-id="<%= @first_setting.id if @first_setting%>" data-use-default="false"><%= t('ask.recover_data') %></a>
</td>
<td></td>
</tr>
<tr>
<td><%= t("ask.title_layout") %>:</td>
<td><%= [t("ask.single_column"),t("ask.two_column")][@default_ask_setting.title_layout] %></td>
</tr>
<tr>
<td><%= t("ask.email_regex") %>:</td>
<td>
<%= check_box_tag :email_regex_enable, @default_ask_setting.email_regex_enable , nil, {:id=>"",:disabled=>'disabled'} %><%= t("ask.enable") %>
<div style="clear: both;"></div>
<div class="show_field">
<%= @default_ask_setting.email_regex %>
</div>
</td>
</tr>
<tr>
<td>
<%= t('ask.field') %>
</td>
<td>
<%= t('ask.whether_open') %>
</td>
</tr>
<% locale = I18n.locale.to_s %>
<% true_false_trans = {'true'=> t('yes'), 'false'=>t('no')} %>
<%
default_setting = @default_ask_setting.default_setting
if default_setting.keys[0].to_s != 'title'
default_setting = {title: true}.merge(default_setting)
end
%>
<% default_setting.each do |k,v| %>
<tr>
<td>
<%= tmp = @default_ask_setting.field_name(k,locale, true) %>
</td>
<td>
<%=
tmp2 = true_false_trans[v]
tmp2 = true_false_trans.values[0] if tmp2.nil?
tmp2
%>
</td>
</tr>
<% end %>
<tr>
<td>
<%= t("ask.usage_rule") %>
</td>
<td colspan="2">
<%= @default_ask_setting.usage_rule.html_safe %>
</td>
</tr>
</tbody>
<% @default_ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block(k,v,true).html_safe %>
<% end %>
</table>
</fieldset>

View File

@ -1,42 +1,149 @@
<%= t('ask.setting_type') %>: <%= select_tag "setting_type", options_for_select([[t('ask.field_setting'),'field'],[t('ask.print_setting'),'print']]), :class => "category-selector" %>
<% if current_user.is_admin? || current_user.is_manager?(module_app) %>
<button class="btn" data-toggle="modal" data-target="#categoryModal" type="button">
<i class='icon-plus'></i> <%= t(:new_category) %>
</button>
<% end %>
<div class="modal fade" id="categoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel"><%= t(:new_category) %></h4>
</div>
<div class="modal-body">
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<label class="control-label"><%= "#{t(:name)} (#{t(locale)})" %></label>
<div class="controls">
<input class="input-large" id="<%=locale%>" name="category[title_translations][<%=locale%>]" placeholder="<%=t(:name)%>" type="text">
<span class="help-inline hide">Please enter category title</span>
</div>
</div>
<% end %>
<div class="control-group">
<label class="control-label"><%= "#{t(:sort_number)}" %></label>
<div class="controls">
<input class="input-large" id="sort_number" name="category[sort_number]" placeholder="<%=t(:sort_number)%>" type="number">
<span class="help-inline hide"><%= t('front_page.only_number') %></span>
</div>
</div>
<div class="text-error text-center"><%= t(:category_notice) %></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal"><%= t(:close) %></button>
<button type="button" class="btn btn-primary" id="add_category"><%= t(:add) %></button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('#setting_type').change(function(){
if ($(this).val()=='field'){
$('#field').attr('class','fade-in active')
$('#print').attr('class','fade-in')
$(function(){
$("#categoryModal").hide();
$('#categoryModal').modal('<%= @categories.blank? ? "show" : "hide" %>');
$("#add_category").click(createCategory);
$("#categoryModal .modal-body").keypress(function(e) {
if(e.which == 13) {
createCategory();
return false;
}
});
$.each($('#categoryModal .input-large'),function(){
$(this).blur(function(){
if($(this).val()==""){
$(this).parent().parent().addClass('error');
$(this).next().removeClass('hide');
}else{
$(this).parent().parent().removeClass('error');
$(this).next().addClass('hide');
}
});
});
});
var createCategory = function(){
var valid = true;
$.each($('#categoryModal .input-large'),function(){
if($(this).val()==""){
$(this).parent().parent().addClass('error');
$(this).next().removeClass('hide');
valid = false;
}else{
$(this).parent().parent().removeClass('error');
$(this).next().addClass('hide');
}
});
if(valid){
$.ajax({
url : "<%= create_in_form_admin_module_app_categories_path(:module_app_id=>@module_app.id.to_s,:module_app_type=>@module_app.class.to_s.underscore) %>",
type : "post",
data: $("input[name^='category']").serialize(),
}).done(function(data){
$.each($('#categoryModal .input-large'),function(){
$(this).val("");
});
var active_class = '';
if($('.toggle_tag_group a.toggle_tag').length == 0){
active_class = ' active_in';
window.ask_cateogry_id = data['id'];
$("#default_ask_setting").removeClass('hide');
$("#category_ask_setting").addClass('hide');
$("#default_ask_setting").find('.default_ask_setting .hidden_category_id').val(data['id']);
}
$('.toggle_tag_group').append('<a href="#'+ data['id'] +'" data-category-id="'+ data['id'] +'" data-toggle="tab" class="toggle_tag' + active_class + ' default_setting">' + data['title'] + ' (<%=t('ask.default')%>)</a>');
$('#categoryModal').modal('hide');
});
}
else{
$('#field').attr('class','fade-in')
$('#print').attr('class','fade-in active')
}
})
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$('select[name="category_id"]').change(function(){
var cat_id = $(this).val()
$(this).parents('form').eq(0).attr('data-cat-id',cat_id)
$(this).parents('form').eq(0).attr("class",'category-set-page-with-category')
})
$('.toggle_tag_group a').click(function(){
$(this).parents('.toggle_tag_group').eq(0).find('a').attr('class','toggle_tag')
$(this).attr('class','toggle_tag active_in')
})
$('.field a[data-toggle="tab"]').on('show.bs.tab', function (e) {
var id = $(e.target).attr('href')
if ($(id).length==0){
$.ajax({
url : "<%= "/#{I18n.locale}/admin/asks/get_category_setting_field" %>",
dataType : "text",
type : "post",
async: false,
data: {id: id.replace(/#/g,'')},
error: function(){
alert('get data failed, please try again later.')
},
success: function(data){
$('.toggle_tag_group.field').after(data)
CKEDITOR.replace($(id).find('.ckeditor')[0])
}
})
$('.add_new_options').sortable({'handle':'.icons-list-2'});
$(document).on('show.bs.tab', '.field a[data-toggle="tab"]', function (e, force_flag) {
var _this = $(e.target);
if(_this.hasClass('active_in') && !force_flag){
return;
}
window.ask_cateogry_id = _this.data('category-id');
_this.parents('.toggle_tag_group').eq(0).find('a').removeClass('active_in');
_this.addClass('active_in');
$('.cloned_setting_block').remove();
if(_this.hasClass('default_setting')){
var id = _this.attr('href').split('#')[1];
if(id.length){
$("#default_ask_setting").find('.recover_data').removeClass('hide').data('id', id);
}else{
$("#default_ask_setting").find('.recover_data').addClass('hide').data('id', '');
}
$("#default_ask_setting").removeClass('hide');
$("#category_ask_setting").addClass('hide');
}else{
$("#default_ask_setting").addClass('hide');
$("#category_ask_setting").removeClass('hide');
var id = _this.attr('href');
if ($(id).length==0){
$.ajax({
url : "<%= "/#{I18n.locale}/admin/asks/get_category_setting_field" %>",
dataType : "text",
type : "post",
async: false,
data: {id: id.replace(/#/g,'')},
error: function(){
alert('get data failed, please try again later.')
},
success: function(data){
$('#category_ask_setting').html(data);
$('#category_ask_setting').find('.ckeditor').each(function(i, item){
CKEDITOR.replace(item);
});
}
})
}
}
});
})
@ -91,83 +198,104 @@
success: function(data){
var add_field_html = "<%= custom_field_block(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$(ele).parents('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
$('.add_new_options').sortable({'handle':'.icons-list-2'})
var add_field = $(ele).parents('.add_field');
add_field.before($('<div/>').html(add_field_html).text().slice(1,-2))
var new_item = add_field.prev();
new_item.find('.add_new_options').sortable({'handle':'.icons-list-2'})
new_item.find('.ckeditor').each(function(i, item){
CKEDITOR.replace(item);
});
}
})
}
</script>
<% if @category_not_add.length != 0 %>
<% ask_setting = AskCategorySetting.new %>
<%= form_for ask_setting,method: 'post',url: "/#{I18n.locale}/admin/asks/category_setting_save",html: { class: "form-horizontal category-set-page"} do |f| %>
<div style="padding-bottom: 2em;border-bottom: 0.1em solid #002bff;">
<% prompt = t('ask.select_category') %>
<%= t('category') %>: <%= select_tag "category_id", options_for_select(@category_not_add.unshift(prompt),selected: prompt,disabled: prompt), :class => "category-selector" %>
<%= render partial: 'ask_setting',locals:{ask_setting: ask_setting,f: f,submit_text: t('submit')} %>
</div>
<% end %>
<% end %>
<% index1 = 0 %>
<% first_category_added = nil %>
<%
first_category_html = ""
@first_category_id = nil
@first_setting = nil
%>
<div class="toggle_tag_group field">
<% @category_added.each do |category_added| %>
<% category = @categories.select{|cat| cat.id.to_s==category_added.category_id.to_s}[0] %>
<% if !category.nil? %>
<% if first_category_added.nil?
first_category_added = category_added
end
%>
<% index1+=1 %>
<% name1 = category.title %>
<a href="#<%= category_added.id.to_s %>" data-toggle="tab" class="toggle_tag<%= ' active_in' if index1== 1 %>"><%= name1.blank? ? "no name" : name1 %></a>
<% end %>
<% @categories.each_with_index do |category, index1| %>
<%
category_id = category.id.to_s
has_category_setting = @category_added_ids.include?(category_id)
name1 = category.title
if name1.blank?
name1 = "No Name"
end
is_default = false
if has_category_setting
category_added = @category_added[category_id]
is_default = category_added.use_default
else
category_added = @default_ask_setting
is_default = true
end
if index1 == 0
@first_category_id = category_id
@first_setting = category_added
if has_category_setting && !is_default
first_category_html = render(partial: 'category_setting_field',locals: {ask_setting: category_added})
end
end
%>
<a href="#<%= has_category_setting ? category_added.id.to_s : '' %>" data-category-id="<%= category_id %>" data-toggle="tab" class="toggle_tag<%= ' active_in' if index1 == 0 %> <%= 'default_setting' unless has_category_setting && !is_default %>" data-default="<%=is_default%>"><%= name1 %><span class="default_text <%= 'hide' unless is_default%>">&nbsp;(<%=t('ask.default')%>)</span></a>
<% end %>
</div>
<% if !first_category_added.nil? %>
<%= render partial: 'category_setting_field',locals: {ask_setting: first_category_added} %>
<% end %>
<div id="category_ask_setting">
<%= first_category_html %>
</div>
<%= render(:partial=>"default_ask_setting", locals: {:@is_hidden=>(first_category_html.present? || @categories.length == 0), :@first_category_id=>@first_category_id}) %>
</div>
<div class="fade-in" id="print">
<% if @category_print_not_add.length != 0 %>
<form action="/<%= I18n.locale %>/admin/asks/category_print_setting_save" class='form-horizontal category-set-page' method="post">
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<div style="padding-bottom: 2em;border-bottom: 0.1em solid #002bff;">
<% prompt = t('ask.select_category') %>
<%= t('category') %>: <%= select_tag "category_id", options_for_select(@category_print_not_add.unshift(prompt),selected: prompt,disabled: prompt), :class => "category-selector" %>
<%= render partial: 'category_print_setting',locals:{print_setting: AskCategoryPrintSetting.new} %>
<input type="submit" class="btn btn-info" value="<%= t('add') %>">
<%= render partial: 'print_format_explain' %>
</div>
</form>
<% else %>
<%= render partial: 'print_format_explain' %>
<% end %>
<% index1 = 0 %>
<% categories = []%>
<div class="toggle_tag_group" style="margin-top: 1em;">
<% @category_print_added.each do |category_print_added| %>
<% category = @categories.select{|cat| cat.id.to_s==category_print_added.category_id.to_s}[0] %>
<% categories << category %>
<% if !category.nil? %>
<% index1+=1 %>
<% name1 = category.title %>
<a href="#<%= category_print_added.id.to_s %>" data-toggle="tab" class="toggle_tag<%= ' active_in' if index1== 1 %>"><%= name1.blank? ? "no name" : name1 %></a>
<% end %>
<% end %>
</div>
<% index2 = 0 %>
<% @category_print_added.each_with_index do |category_print_added,index1| %>
<% if !categories[index1].nil? %>
<% index2 = index2 + 1 %>
<form action="<%= "/#{I18n.locale}/admin/asks/category_print_setting_save" %>" method="post" id='<%= category_print_added.id.to_s %>' class="form-horizontal fade-in <%= 'active' if index2==1 %>">
<%= hidden_field_tag :category_id, category_print_added.category_id %>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<%= render partial: 'category_print_setting',locals:{print_setting: category_print_added} %>
<input class="btn btn-info" type="submit" value="<%= t('ask.modify') %>">
<button class="btn btn-danger" type="button" onclick="window.location='<%= "/#{I18n.locale}/admin/asks/category_print_setting_delete?id=#{category_print_added.id}" %>'"><%= t('delete_') %></button>
</form>
<% end %>
<% end %>
</div>
<script>
window.ask_cateogry_id = "<%= @first_category_id %>";
$(document).on('click', '.switch_to_default', function(){
var _this = $(this);
var id = _this.data('id');
var use_default = _this.attr('data-use-default');
if(window.confirm(use_default == "true" ? "<%=t('ask.are_you_sure_to_switch_to_default_setting')%>" : "<%=t('ask.are_you_sure_to_recover_data')%>")){
$.post("<%=switch_to_default_setting_admin_asks_path%>", {id: id, use_default: use_default}).done(function(data){
if(data["success"]){
if(use_default == "true"){
$('a[data-category-id="'+window.ask_cateogry_id+'"]').addClass('default_setting').find('.default_text').removeClass('hide');
var parent = _this.data('parent');
if(parent){
_this.parents(parent).addClass('hide').siblings().removeClass('hide');
}else{
var category_ask_setting = _this.parents('#category_ask_setting')
category_ask_setting.addClass('hide');
var clone_block = $('#default_ask_setting').clone();
clone_block.attr('id','').addClass('cloned_setting_block').removeClass('hide').find('.recover_data').removeClass('hide').data('id', id);
_this.siblings('input[type="hidden"]').val(true);
category_ask_setting.after(clone_block);
}
}else{ //Recover data
$('a[data-category-id="'+window.ask_cateogry_id+'"]').find('.default_text').addClass('hide');
$('a[data-category-id="'+window.ask_cateogry_id+'"]').removeClass('default_setting').trigger('show.bs.tab', true);
}
}else{
alert("Failed!");
window.location.reload();
}
})
}
})
$(document).on('click', '.cancel_edit', function(){
if(window.confirm('<%=t('ask.are_you_sure_to_cancel_edit')%>')){
var _this = $(this);
var parent = _this.data('parent');
$('a[data-category-id="'+window.ask_cateogry_id+'"]').find('.default_text').removeClass('hide');
if(parent){
var parent_block = _this.parents(parent);
parent_block.addClass('hide').siblings().removeClass('hide');
parent_block.replaceWith($('#default_ask_setting').find(parent).clone());
}
}
})
$(document).on('click', '.clone_default_setting', function(){
$('a[data-category-id="'+window.ask_cateogry_id+'"]').find('.default_text').addClass('hide');
var _this = $(this);
var parent_block = _this.parents('.show_default_ask_setting');
parent_block.addClass('hide').siblings().removeClass('hide').find('.hidden_category_id').val(window.ask_cateogry_id);
})
</script>

View File

@ -14,14 +14,18 @@
var add_field_html = "<%= custom_field_block(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$(ele).parents('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
$('.add_new_options').sortable({'handle':'.icons-list-2'})
var new_item = add_field.prev();
new_item.find('.add_new_options').sortable({'handle':'.icons-list-2'})
new_item.find('.ckeditor').each(function(i, item){
CKEDITOR.replace(item);
});
}
})
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.add_new_options').sortable({'handle':'.icons-list-2'})
$('.add_new_options').sortable({'handle':'.icons-list-2'});
})
</script>
<%= form_for @ask_setting,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>

View File

@ -0,0 +1,115 @@
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :ask_ticket_status, url: update_ticket_status_admin_asks_path, remote: true, :html=>{id: "ask_ticket_status_form"} do |f| %>
<fieldset>
<%= hidden_field_tag :id, "", {:id=>'hidden_id_field'} %>
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<label class="control-label"><%= "#{t('ask.status')} (#{t(locale)})" %></label>
<div class="controls">
<input class="input-large" id="<%=locale%>" name="<%=f.object_name%>[<%=locale%>]" placeholder="<%=t('ask.status')%>" type="text">
</div>
</div>
<% end %>
<% end %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small', id: "ask_ticket_status_submit" %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>
<table class="table main-list" id="status_table">
<thead>
<tr>
<th><%= t('ask.status') %></th>
<th><%= t('ask.action') %></th>
</tr>
</thead>
<tbody>
<% @ticket_statuses.each do |ticket_status| %>
<tr>
<td><%= ticket_status.title %></td>
<td>
<a href="#" class="btn btn-primary edit_ticket open-slide" data-id="<%=ticket_status.id%>"><%= t(:edit) %></a>
<% unless ticket_status.is_default %>
<button class="btn btn-danger delete_ticket" data-id="<%=ticket_status.id%>"><%= t(:delete_) %></button>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<a href="#" class="btn btn-primary new_ticket open-slide" data-title="<%=t("ask.new_status")%>"><%= t(:add) %></a>
<script>
function reload_page(){
$.get(window.location.href).done(function(data){
$('#status_table').html($(data).filter('#status_table').html());
openSlide();
})
}
$(document).ready(function(){
openSlide();
$('form#ask_ticket_status_form').bind('ajax:success', function(evt, data, status, xhr){
window.setTimeout(function(){
reload_page();
$.pageslide.close();
}, 500);
})
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
var id = item.data('id');
var form = pageslide.find('form');
$.post('<%= get_ticket_status_admin_asks_path %>', {id: id}).done(function(data){
form.find('#hidden_id_field').val(id);
Object.keys(data).forEach(function(k){
var v = data[k];
if(v instanceof Object){
console.log(v);
var tmp = Object.keys(v);
if(tmp.length){
tmp.forEach(function(kk){
form.find('[name*="ask_ticket_status['+k+']['+kk+']"').val(v[kk]);
});
}else{
form.find('[name*="ask_ticket_status['+k+']"').val('');
}
}else{
form.find('[name*="ask_ticket_status['+k+']"').val(v);
}
})
})
});
$(document).on('click', '.delete_ticket', function(){
var id = $(this).data('id');
var tr = $(this).parents('tr');
var sure_text = "<%=t(:are_you_sure_to_delete)%>";
if(window.confirm(sure_text)){
if(window.confirm(sure_text)){
$.ajax({
url : '<%=delete_ticket_status_admin_asks_path%>',
type : 'DELETE',
data: {id: id},
success: function(){
tr.remove();
}
});
}
}
})
})
</script>

View File

@ -6,6 +6,67 @@
<body>
<!-- <h1><%= @data['title'] %></h1> -->
<table>
<% question = AskQuestion.find(@data['ask_question_id']) rescue nil %>
<% if question %>
<%
yes_trans = t('ask.yes')
no_trans = t('ask.no')
locale = I18n.locale.to_s
%>
<% @data['disp_fields_infos'].each do |f, field_info| %>
<% next if f == 'recaptcha' %>
<tr>
<%
trans = field_info["trans"]
is_cat = false
is_custom = false
if f.include?("@")
f = field_info["key"]
is_custom = true
elsif f == 'ask_category_id'
f = 'category_id'
is_cat = true
end
val = question[f]
if val == true || val == false
val = val ? yes_trans : no_trans
else
val = question.custom_values[f] if is_custom
type = field_info["type"]
if ["select", "radio_button", "checkbox"].include?(type)
if type == "checkbox"
val = val.values
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
elsif type == "date"
val = val["datetime"].values[0].values
if val.count == 2
val = val[0] + " ~ " + val[1]
else
val = val[0]
end
elsif type == "instructions"
val = field_info["instructions"][locale].to_s.html_safe rescue ""
else
if is_cat
val = Category.find(val).title rescue ''
elsif f == 'usage_rule'
val = @data['usage_rule'].to_s.html_safe
else
val = val.to_s.html_safe
end
end
end
%>
<th><%= trans %></th>
<td><%= val %></td>
</tr>
<% end %>
<% else %>
<tr>
<th><%= AskQuestion.human_attribute_name(:name) %></th>
<td><%= @data['name'] %></td>
@ -33,7 +94,8 @@
<tr>
<th><%= AskQuestion.human_attribute_name(:name) %></th>
<td><%= @data['name'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td>
</tr>
</tr>
<% end %>
</table>
<p>此為系統自動發信,請勿直接回覆</p>
</body>

View File

@ -157,20 +157,29 @@ $(function(){
// }
})
$(document).ready(function(){
function scrollIntoView(selector, offset = 0) {
window.scroll(0, document.querySelector(selector).offsetTop - offset);
}
var email_regex = "<%=email_regex%>";
if(email_regex.length != 0){
email_regex = new RegExp(email_regex);
var submit_flag = false;
$(".ask-question-form").each(function(i, form){
var $form = $(form);
if($form.length != 0 && $form.find('#ask_question_mail').length != 0){
var email_field = $form.find('#ask_question_mail');
if($form.length != 0 && email_field.length != 0){
$form.submit(function(){
if(!submit_flag){
submit_flag = true;
if(email_regex.test($form.find('#ask_question_mail').val())){
if(email_regex.test(email_field.val())){
submit_flag = false;
}else{
email_field.css("border", "2px solid red");
scrollIntoView('#ask_question_mail');
alert("<%=t('ask.please_check_email_format')%>");
email_field.one("input",function(){
email_field.css("border", "");
})
submit_flag = false;
return false;
}

View File

@ -32,6 +32,9 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
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)}"
}
# s.add_dependency ~> "gotcha"
end

View File

@ -1,7 +1,22 @@
en:
situation: Situation
situation: Status
sex: Sex
ask:
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?"
are_you_sure_to_cancel_edit: "Are you sure to cancel edit?"
cancel_edit: "Cancel Edit"
instructions: "Instructions"
clone_default_setting: "Clone Default Setting"
use_default: "Use Default"
default: "Default"
new_status: "New Status"
status: "Status"
action: "Action"
ip: "IP"
ticket_status: "Ticket Status"
all_tickets: "All Tickets"
title_layout: Title layout
single_column: Single Column in One Row
two_column: Two Column in One Row
@ -40,7 +55,7 @@ en:
custom_explain: custom field which will automatically include all custom field to table but exclude the fields that are added
explanation: Explanation
name_mask: 'Name only show the first word,for example: 蔡**'
category_setting: Category Management
category_setting: Category fields
print_setting: Print Format Setting
print_format: Print Format
file_field: File Field

View File

@ -1,11 +1,26 @@
zh_tw:
situation:
situation:
identity: 身份
recaptcha:
errors:
verification_failed: 驗證碼錯誤
ask:
recover_data: "復原資料"
are_you_sure_to_recover_data: "您確定要復原資料嗎?"
are_you_sure_to_switch_to_default_setting: "您確定要切換成預設設定嗎?"
are_you_sure_to_cancel_edit: "您確定要取消修改嗎?"
cancel_edit: "取消修改"
instructions: "說明文字 Instructions"
clone_default_setting: "複製預設設定"
use_default: "使用預設"
default: "預設"
new_status: "新增狀態"
status: "狀態"
action: "動作"
ip: "IP"
ticket_status: "服務單狀態設定"
all_tickets: "全部服務單"
title_layout: 題目樣式
single_column: 單欄式
two_column: 兩欄式
@ -43,7 +58,7 @@ zh_tw:
show_title_trans: 會顯示當前語言的標籤翻譯
explanation: 說明
name_mask: 姓名只顯示第一個字,如蔡**
category_setting: 類別管理設定
category_setting: 類別欄位設計
print_setting: 列印格式設定
print_format: 列印格式
file_field: 檔案欄位
@ -68,7 +83,7 @@ zh_tw:
option_name: 選項名稱
field_name: 欄位名稱
whether_open: 是否開啟
setting: 基本欄位設定
setting: "基本欄位設定(預設值)"
name: 發問者
appointment: 預約時間
created_at: 發問時間
@ -110,7 +125,7 @@ zh_tw:
female:
appointment: 預約時間
fax: 傳真
title: 主旨
title: 標題
reply: 回覆
created_at: 日期
content: 內容

View File

@ -1,6 +1,29 @@
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 )
end
end
end
end
end
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do #backend
resources :asks do
@ -15,8 +38,13 @@ Rails.application.routes.draw do
get 'category_print_setting_delete'
post 'category_print_setting_save'
get 'category_print_setting_save'
post 'switch_to_default_setting'
get 'get_new_category_setting_index'
get 'print_setting'
get 'ticket_status'
post 'get_ticket_status'
post 'update_ticket_status'
delete 'delete_ticket_status'
post 'print_setting_save'
post 'setting_save'
post 'get_new_setting_index'

View File

@ -59,7 +59,7 @@ module Ask
set_keyword_contstraints ['/asks']
widget_methods ["widget"]
widget_settings [{"data_count"=>10}]
taggable "AskQuestion"
# taggable "AskQuestion"
begin
show_option_items data_item
rescue => e
@ -76,60 +76,65 @@ module Ask
active_for_controllers (['admin/asks'])
head_link_path "admin_asks_path"
context_link 'ask.all_articles',
context_link 'ask.all_tickets',
:link_path=>"admin_asks_path" ,
:priority=>1,
:active_for_action=>{'admin/asks'=>'index'},
:available_for => 'users'
# context_link 'tags',
# :link_path=>"admin_module_app_tags_path" ,
# :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
# :priority=>4,
# :active_for_action=>{'admin/ask'=>'tags'},
# :active_for_tag => 'Ask',
# :available_for => 'managers'
context_link 'ask.setting',
:link_path=>"setting_admin_asks_path" ,
:priority=>2,
:active_for_action=>{'admin/asks'=>'setting'},
:available_for => 'managers'
context_link 'ask.category_setting',
:link_path=>"category_setting_admin_asks_path" ,
:priority=>3,
:active_for_action=>{'admin/asks'=>'category_setting'},
:available_for => 'sub_managers'
context_link 'ask.order_fields',
:link_path=>"order_fields_admin_asks_path" ,
:priority=>4,
:active_for_action=>{'admin/asks'=>'order_fields'},
:available_for => 'sub_managers'
context_link 'ask.print_setting',
:link_path=>"print_setting_admin_asks_path" ,
:priority=>5,
:active_for_action=>{'admin/asks'=>'print_setting'},
:available_for => 'sub_managers'
context_link 'ask.ticket_status',
:link_path=>"ticket_status_admin_asks_path" ,
:priority=>6,
:active_for_action=>{'admin/asks'=>'ticket_status'},
:available_for => 'managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
:priority=>2,
:priority=>7,
:active_for_action=>{'admin/asks'=>'categories'},
:active_for_category => 'Ask',
:available_for => 'managers'
context_link 'ask.acknowledgements',
:link_path=>"admin_ask_acknowledgements_path" ,
:priority=>3,
:priority=>8,
:active_for_action=>{'admin/asks'=>'acknowledgements'},
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
:priority=>4,
:active_for_action=>{'admin/ask'=>'tags'},
:active_for_tag => 'Ask',
:available_for => 'managers'
context_link 'ask.admins',
:link_path=>"admin_ask_admins_path" ,
:priority=>5,
:priority=>9,
:active_for_action=>{'admin/asks'=>'admins'},
:available_for => 'managers'
context_link 'ask.exports',
:link_path=>"export_admin_asks_path" ,
:priority=>6,
:priority=>10,
:active_for_action=>{'admin/asks'=>'exports'},
:available_for => 'managers'
context_link 'ask.order_fields',
:link_path=>"order_fields_admin_asks_path" ,
:priority=>7,
:active_for_action=>{'admin/asks'=>'order_fields'},
:available_for => 'sub_managers'
context_link 'ask.setting',
:link_path=>"setting_admin_asks_path" ,
:priority=>7,
:active_for_action=>{'admin/asks'=>'setting'},
:available_for => 'managers'
context_link 'ask.category_setting',
:link_path=>"category_setting_admin_asks_path" ,
:priority=>7,
:active_for_action=>{'admin/asks'=>'category_setting'},
:available_for => 'sub_managers'
context_link 'ask.print_setting',
:link_path=>"print_setting_admin_asks_path" ,
:priority=>8,
:active_for_action=>{'admin/asks'=>'print_setting'},
:available_for => 'sub_managers'
# context_link 'new_',
# :link_path=>"new_admin_ask_path" ,
# :priority=>2,

View File

@ -75,20 +75,29 @@
}
})
$(document).ready(function(){
function scrollIntoView(selector, offset = 0) {
window.scroll(0, document.querySelector(selector).offsetTop - offset);
}
var email_regex = "{{email_regex}}";
if(email_regex.length != 0){
email_regex = new RegExp(email_regex);
var submit_flag = false;
$(".ask-question-form").each(function(i, form){
var $form = $(form);
if($form.length != 0 && $form.find('#ask_question_mail').length != 0){
var email_field = $form.find('#ask_question_mail');
if($form.length != 0 && email_field.length != 0){
$form.submit(function(){
if(!submit_flag){
submit_flag = true;
if(email_regex.test($form.find('#ask_question_mail').val())){
if(email_regex.test(email_field.val())){
submit_flag = false;
}else{
email_field.css("border", "2px solid red");
scrollIntoView('#ask_question_mail');
alert("<%=t('ask.please_check_email_format')%>");
email_field.one("input",function(){
email_field.css("border", "");
})
submit_flag = false;
return false;
}