add category setting and print setting

This commit is contained in:
chiu 2020-07-04 21:36:32 +08:00
parent 8b3361360b
commit 1cca61a0c4
29 changed files with 1408 additions and 288 deletions

View File

@ -2,16 +2,37 @@
class Admin::AsksController < OrbitAdminController
helper Admin::AsksHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_askquestion, only: [:edit, :destroy, :update]
before_action :set_askquestion, only: [:edit, :destroy, :update, :print]
layout :compute_layout
def compute_layout
if action_name=='print'
false
else
'back_end_with_jquery_first'
end
end
def initialize
super
@app_title = "ask"
end
def print_setting
@set = AskPrintSetting.first
@set = AskPrintSetting.create if @set.nil?
@url = print_setting_save_admin_asks_path
end
def print_setting_save
locale = I18n.locale
set = AskPrintSetting.first
set.update_attributes(print_format: params[:ask_print_setting][:print_format],save_name: params[:ask_print_setting][:save_name])
redirect_to "/#{locale}/admin/asks"
end
def category_print_setting_save
locale = I18n.locale
set = AskCategoryPrintSetting.where(category_id: params['category_id']).first
set = AskCategoryPrintSetting.create if set.nil?
set.update_attributes(print_format: params['print_format'],save_name: params['save_name'],category_id: params['category_id'])
redirect_to "/#{locale}/admin/asks/category_setting"
end
def filter_fields(categories, tags)
{
:situation=>[{:title=>"ask.is_waiting",:id=>"is_waiting"},{:title=>"ask.is_processed",:id=>"is_processed"},{:title=>"ask.is_referral",:id=>"is_referral"},{:title=>"ask.is_published",:id=>"is_published"}],
@ -30,10 +51,19 @@ class Admin::AsksController < OrbitAdminController
end
end
def setting_save
locale = I18n.locale
ask_setting = AskSetting.first
p1 = ask_setting_params
p1 = ask_setting_params(ask_setting,'ask_setting')
ask_setting.update_attributes(p1)
redirect_to '/admin/asks'
redirect_to "/#{locale}/admin/asks"
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)
redirect_to "/#{locale}/admin/asks/category_setting"
end
def setting
@ask_setting = AskSetting.first
@ -47,7 +77,15 @@ class Admin::AsksController < OrbitAdminController
ask_setting_index.save
render :json => {key: ask_setting_index.key.to_i}
end
def get_new_category_setting_index
ask_setting_index = AskCategorySettingIndex.where(category_id: params['category_id']).first
ask_setting_index = AskCategorySettingIndex.create(category_id: params['category_id']) if ask_setting_index.nil?
ask_setting_index.key = ask_setting_index.key + 1
ask_setting_index.save
render :json => {key: ask_setting_index.key.to_i}
end
def index
AskPrintSetting.create() if AskPrintSetting.first.nil?
@ask_setting = AskSetting.first
@ask_setting = AskSetting.create() if @ask_setting.nil?
@tags = @module_app.tags
@ -85,8 +123,140 @@ class Admin::AsksController < OrbitAdminController
def search_tag(tag)
Tag.find(tag).name_translations{}
end
def category_setting
@categories = @module_app.categories
@category_ids = @categories.pluck(:id)
@category_titles = @categories.pluck(:title).collect{|v| v[I18n.locale]}
@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))
end
def get_category_setting_field
ask_setting = AskCategorySetting.find(params['id'])
render partial: 'category_setting_field',locals: {ask_setting: ask_setting}
end
def category_print_setting_delete
print_setting = AskCategoryPrintSetting.find(params['id'])
print_setting.destroy
locale = I18n.locale
redirect_to "/#{locale}/admin/asks/category_setting"
end
def category_setting_delete
ask_setting = AskCategorySetting.find(params['id'])
ask_setting.destroy
locale = I18n.locale
redirect_to "/#{locale}/admin/asks/category_setting"
end
def process_format_text(text,custom_fields)
customs = text.scan(/<tr.*{custom}.*<\/tr>/m).uniq
if customs.length != 0
custom_exist_nums = []
custom_exists = text.scan(/{custom\d+}/)
custom_exists.each do |custom_exist|
k = custom_exist[6...-1]
custom_exist_nums << k
end
customs.each do |custom|
tmp = custom_fields.keys.select{|key| custom_exist_nums.exclude? key}.collect do |k|
tp = custom.gsub(/{custom}/,"{custom#{k}}")
tp = tp.gsub(/{custom_title}/,"{custom#{k}_title}")
tp
end.join
text = text.gsub(custom,tmp)
end
end
format_texts = text.scan(/{\w+\|*\w+}/).uniq
format_texts.each do |format_text|
if format_text[-7...-1] == '_title'
case format_text[1...-7]
when /custom\d+/
i = format_text.scan(/\d+/)[0].to_i
k = custom_fields.keys[i-1]
if !k.blank?
text_tp = custom_fields[k]['field'][I18n.locale] rescue ''
text = text.gsub(format_text,text_tp)
end
when 'title'
text = text.gsub(format_text,I18n.t('title'))
when 'ask_time'
text = text.gsub(format_text,I18n.t('ask.ask_time'))
when 'category'
text = text.gsub(format_text,I18n.t('mongoid.attributes.ask_question.ask_category_id'))
when 'name','sex','mail','phone','appointment','agree_show'
text = text.gsub(format_text,I18n.t("mongoid.attributes.ask_question.#{format_text[1...-7]}"))
end
else
case format_text[1...-1]
when 'ask_time'
text = text.gsub(format_text,@ask_question.created_at.strftime('%Y/%m/%d %H:%M'))
when 'title','name','mail','phone','appointment'
text = text.gsub(format_text,@ask_question.send(format_text[1...-1]).to_s)
when 'category'
cat = Category.find(@ask_question.ask_category_id).title rescue ''
text = text.gsub(format_text,cat)
when 'name|mask'
name_tp = @ask_question.name.to_s
if name_tp.length>1
name_tp = name_tp[0] + '*'*(name_tp.length-1)
end
text = text.gsub(format_text,name_tp)
when 'sex'
sex = @ask_question.sex
if ['male','female'].include? sex.to_s
sex = I18n.t("mongoid.attributes.ask_question.#{sex}")
else
sex = ''
end
text = text.gsub(format_text,sex)
when 'agree_show'
if @ask_question.agree_show
text = text.gsub(format_text,I18n.t('ask.yes'))
else
text = text.gsub(format_text,I18n.t('ask,no'))
end
when /custom\d+\|format/
i = format_text.scan(/\d+/)[0].to_i
k = custom_fields.keys[i-1]
if !k.blank?
v = custom_fields[k] rescue {}
text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true,true)
text = text.gsub(format_text,text_tp.to_s)
end
when /custom\d+/
i = format_text.scan(/\d+/)[0].to_i
k = custom_fields.keys[i-1]
if !k.blank?
v = custom_fields[k] rescue {}
text_tp = Admin::AsksHelper.show_on_front(k,v,@ask_question.custom_values[k],true)
text = text.gsub(format_text,text_tp.to_s)
end
end
end
end
text
end
def print
@print_setting = AskCategoryPrintSetting.where(category_id: @ask_question.category_id.to_s).first
@print_setting = AskPrintSetting.first if @print_setting.nil?
@save_name = @print_setting.save_name rescue ''
@print_text = @print_setting.print_format rescue ''
ask_setting = AskCategorySetting.where(category_id: @ask_question.category_id.to_s).first
ask_setting = AskSetting.first if ask_setting.nil?
custom_fields = ask_setting.custom_fields
@print_text = process_format_text(@print_text,custom_fields)
@save_name = process_format_text(@save_name,custom_fields)
end
def edit
@ask_setting = AskCategorySetting.where(category_id: @ask_question.category_id.to_s).first
@ask_setting = AskSetting.first if @ask_setting.nil?
@url = admin_ask_path(@ask_question)
end
@ -101,8 +271,11 @@ class Admin::AsksController < OrbitAdminController
temp_params = params.require(:ask_question).permit!
all_to_save = []
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
ask_setting.custom_fields.select{|k,v| v['type']=='file' || v['type']=='image'}.each do |k,v|
file = temp_params['custom_values'][k]
if !file.blank?
@ -203,14 +376,13 @@ class Admin::AsksController < OrbitAdminController
@ask_question = AskQuestion.find(params[:id])
end
private
def ask_setting_params
param = params.require('ask_setting').permit!
def ask_setting_params(ask_setting,collection_name)
param = params.require(collection_name).permit!
param_clone = param.clone
param_clone['default_setting'].each { |k, v| param_clone['default_setting'][k] = (v == 'true'? true : false) }
param_clone.delete('custom_fields')
ask_setting = AskSetting.first
custom_fields = ask_setting['custom_fields'].clone
params_custom_fields = (params.require('ask_setting').require('custom_fields') rescue {})
params_custom_fields = (params.require(collection_name).require('custom_fields') rescue {})
params_custom_fields.each do |k,v|
custom_fields[k] = v
end

View File

@ -10,61 +10,34 @@ class AsksController < ActionController::Base
case subpart.widget_type
when /.*_form/
module_app = ModuleApp.where(:key => "ask").first
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
categories = Array(Category.find(OrbitHelper.widget_categories)) rescue ['all']
categories = module_app.categories if categories.include? 'all'
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
if ask_settings.count != 0 && 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?
categories = Array(Category.find(OrbitHelper.widget_categories)) rescue ['all']
categories = module_app.categories if categories.include? 'all'
tmp = 'mongoid.attributes.ask_question'
defalt_fields = [{'label'=>ask_label(t('title'),'true'),'content'=>text_field_tag('ask_question[title]',nil,placeholder: t('title'),required: true)}]
if ask_setting.default_setting['ask_category_id']
if categories.count > 1
defalt_fields = defalt_fields + [{'label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}]
else
defalt_fields = defalt_fields + [{'label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>"<span>#{@categories[0].title rescue ''}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
end
else
defalt_fields = defalt_fields + [{'label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
end
defalt_fields = defalt_fields + ['name','sex','mail','phone','appointment'].select{|v| ask_setting.default_setting[v]}.collect do |field|
required = ['phone','appointment'].exclude?(field) ? 'true' : 'false'
f1 = {'label'=>ask_label(t("#{tmp}.#{field}"),required)}
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:t("#{tmp}.#{field}"))
when 'sex'
f1['content'] = "<label class=\"radio-inline\">
#{radio_button(field_name,'male')}#{I18n.t('users.male')}
</label>
<label class=\"radio-inline\">
#{radio_button(field_name,'female')}#{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:t("#{tmp}.#{field}"))
when 'phone'
f1['content'] = text_field_tag(field_name,nil,placeholder:t("#{tmp}.#{field}"))
when 'appointment'
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,placeholder:t("#{tmp}.#{field}"))}</div>"
end
f1
end
defalt_fields = defalt_fields + ask_setting.custom_fields.collect{|k,v| {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}}
defalt_fields << {'label'=>ask_label(t("#{tmp}.agree_show")),'content'=>check_box_tag('ask_question[agree_show]')}
defalt_fields = cal_form_from_setting(ask_setting,categories)
request = OrbitHelper.request
csrf_value = OrbitHelper.request.session[:_csrf_token] || SecureRandom.base64(32)
token_tag = hidden_field_tag('authenticity_token',csrf_value)
switch_form = cal_switch_form(ask_settings,categories,token_tag)
{
'fields' => defalt_fields,
'extras'=>{
'token_tag' => hidden_field_tag('authenticity_token',csrf_value),
'token_tag' => token_tag,
'form_url' => "/#{I18n.locale.to_s}/asks",
'submit_tag' => submit_tag(t('submit'), :class=> 'btn btn-primary', :id => 'button-mail'),
'close_tag' => button_tag(t('cancel'), type: 'reset', :class=> 'btn'),
'referer_url' => ''
'referer_url' => '',
'switch_form' => switch_form
}
}
else
@ -74,7 +47,7 @@ class AsksController < ActionController::Base
else
ask_questions = AskQuestion.where(situation: 'is_published')
end
ask_index_page = Page.where(:module=>'ask').first.url rescue nil
ask_index_page = OrbitHelper.widget_more_url rescue nil
ask_questions = ask_questions.collect do |v|
url = ((ask_index_page+"?item=#{v.id}") rescue "javascript:alert('#{t('ask.no_index_page')}')")
{'td'=> [
@ -85,7 +58,9 @@ class AsksController < ActionController::Base
end
{
'ask_questions' => ask_questions,
'th'=>[{'td'=>t('categories')},{'td'=>t('title')}]
'th' => [{'td'=>t('categories')},{'td'=>t('title')}],
'extras' => {'more_title'=>I18n.t('ask.more_title'),
'more_href'=>ask_index_page}
}
end
end
@ -118,7 +93,9 @@ class AsksController < ActionController::Base
end
def show
ask_question = AskQuestion.where(id: @params['item']).first
{'ask_question' => ask_question,'layout_type'=>'show'}
ask_setting = AskCategorySetting.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
def index
@params = OrbitHelper.params
@ -131,6 +108,18 @@ class AsksController < ActionController::Base
module_app = ModuleApp.where(:key => "ask").first
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
categories = module_app.categories if categories.include? 'all'
ask_settings = AskCategorySetting.where(:category_id.in=> categories.collect{|v| v.id.to_s}).to_a
if ask_settings.count != 0 && 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?
end
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)
tags = module_app.tags
ask_question = AskQuestion.new
{
@ -138,7 +127,9 @@ class AsksController < ActionController::Base
'ask_question' => ask_question,
'categories' => categories,
'tags' => tags,
'module_app' => module_app
'module_app' => module_app,
'switch_form' => switch_form,
'ask_setting' => ask_setting
}
elsif @layout_type == 'published_index'
page_number = OrbitHelper.page_number.to_i
@ -163,8 +154,11 @@ class AsksController < ActionController::Base
@ask_question = AskQuestion.new()
temp_params = create_params
all_to_save = []
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
ask_setting.custom_fields.select{|k,v| v['type']=='file' || v['type']=='image'}.each do |k,v|
file = temp_params['custom_values'][k]
if !file.blank?
@ -240,4 +234,132 @@ class AsksController < ActionController::Base
def create_params
params.require(:ask_question).permit!
end
private
def cal_form_from_setting(ask_setting,categories,show_categories=false)
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)}]
if show_categories || ask_setting.default_setting['ask_category_id']
if categories.count > 1
defalt_fields = defalt_fields + [{'style_html'=>'','label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}]
else
defalt_fields = defalt_fields + [{'style_html'=>'','label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>"<span>#{(categories[0].title rescue '')}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
end
else
defalt_fields = defalt_fields + [{'style_html'=>'display: none;','label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
end
defalt_fields = defalt_fields + ['name','sex','mail','phone','appointment'].select{|v| ask_setting.default_setting[v]}.collect do |field|
required = ['phone','appointment'].exclude?(field) ? 'true' : 'false'
f1 = {'style_html'=>'','label'=>ask_label(t("#{tmp}.#{field}"),required)}
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:t("#{tmp}.#{field}"))
when 'sex'
f1['content'] = "<label class=\"radio-inline\">
#{radio_button(field_name,'male')}#{I18n.t('users.male')}
</label>
<label class=\"radio-inline\">
#{radio_button(field_name,'female')}#{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:t("#{tmp}.#{field}"))
when 'phone'
f1['content'] = text_field_tag(field_name,nil,placeholder:t("#{tmp}.#{field}"))
when 'appointment'
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,placeholder:t("#{tmp}.#{field}"))}</div>"
end
f1
end
defalt_fields = defalt_fields + ask_setting.custom_fields.collect{|k,v| {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}}
if !ask_setting.usage_rule.blank?
defalt_fields << {'style_html'=>'','label'=>ask_label(t("ask.usage_rule")),'content'=>ask_setting.usage_rule}
end
if ask_setting.default_setting['agree_usage']
defalt_fields << {'style_html'=>'','label'=>ask_label(t("#{tmp}.agree_usage")),'content'=>check_box_tag('ask_question[agree_usage]')}
end
if ask_setting.default_setting['agree_show']
defalt_fields << {'style_html'=>'','label'=>ask_label(t("#{tmp}.agree_show")),'content'=>check_box_tag('ask_question[agree_show]')}
end
defalt_fields
end
def cal_html(fields,token_tag,form_id)
form_url = "/#{I18n.locale.to_s}/asks"
submit_tag = submit_tag(t('submit'), :class=> 'btn btn-primary', :id => 'button-mail')
close_tag = button_tag(t('cancel'), type: 'reset', :class=> 'btn')
referer_url = ''
tmp = fields.collect do |field|
style_html = field['style_html']
label = field['label']
content = field['content']
"<div class=\"control-group\" style=\"#{style_html}\">
#{label}
<div class=\"controls\">
#{content}
</div>
</div>"
end.join
"<form id=\"#{form_id}\" action=\"#{form_url}\" enctype=\"multipart/form-data\" method=\"post\" class=\"form-horizontal\" accept-charset=\"UTF-8\" style=\"display: none;\">
#{token_tag}
<div data-level=\"0\" data-list=\"fields\">
#{tmp}
</div>
<div class=\"form-actions\">
<input type=\"hidden\" name=\"referer_url\" value=\"#{referer_url}\">
#{submit_tag}
#{close_tag}
</div>
</form>"
end
def script_text
"<script type=\"text/javascript\">
$(document).ready(function(){
$('select[name=\"ask_question[category_id]\"]').change(function(){
var category_id = $(this).val()
$(this).parents('.ask-question').eq(0).find('select[name=\"ask_question[category_id]\"]').val(category_id)
var id
if ($('form#'+category_id).length != 0){
id = category_id
}
else{
id = 'ask-default-form'
}
if (id != $(this).parents('form').eq(0).attr('id')){
var self = $(this)
var old_controls = self.parents('form').eq(0).find('.control-group')
var old_inputs = old_controls.find('label').map(function(){
return $.trim($(this).text().replace(/\\\*/g,''));
}).get()
var new_controls = self.parents('.ask-question').eq(0).find('form#'+id).find('.control-group')
var new_inputs = new_controls.find('label').map(function(){
return $.trim($(this).text().replace(/\\\*/g,''));
}).get()
$(new_inputs).each(function(i,v){
var i0 = old_inputs.indexOf(v)
if (i0 != -1 && new_controls.eq(i).find('select#ask_question_category_id').length==0){
new_controls.eq(i).find('.controls').eq(0).before(old_controls.eq(i0).find('.controls').clone())
new_controls.eq(i).find('.controls').eq(-1).remove()
}
})
self.parents('.ask-question').eq(0).find('form').hide()
self.parents('.ask-question').eq(0).find('form#'+id).show()
}
})
})
</script>"
end
def cal_switch_form(ask_settings,categories,token_tag)
switch_form = ''
if ask_settings.count > 1
switch_form = script_text + ask_settings.collect do |ask_setting|
fields = cal_form_from_setting(ask_setting,categories,true)
if ask_setting.class == AskSetting
form_id = 'ask-default-form'
else
form_id = ask_setting.category_id
end
cal_html(fields,token_tag,form_id)
end.join
end
switch_form
end
end

View File

@ -1,4 +1,15 @@
module Admin::AsksHelper
extend self
extend ActionView::Helpers::FormTagHelper
extend ActionView::Helpers::FormOptionsHelper
extend ActionView::Helpers::DateHelper
extend ActionView::Helpers::TagHelper
extend ActionView::Helpers::RenderingHelper
extend ActionView::Context
extend OrbitBasis::RenderAnywhere
extend ActionView::Helpers::UrlHelper
extend OrbitFormHelper
extend Ckeditor::Helpers::FormHelper
def set_input_name(input_name)
@input_name = input_name
end
@ -14,14 +25,13 @@ module Admin::AsksHelper
end.join.html_safe
end
end
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={})
content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
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(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/\[/,'_').gsub(/\]/,'')
end
(I18n.available_locales.collect do |locale|
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
@ -32,6 +42,22 @@ module Admin::AsksHelper
end
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
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
content_tag(:div,{:class => "tab-panel"}.merge(exteral_options)) do
tmp
end
end
end
def time_setting_block(key,value={})
@ -107,7 +133,24 @@ module Admin::AsksHelper
def ask_label(value,required='false')
label_tag(nil,value,{:class=>"control-label#{required=='true' ? ' required' : ''}"})
end
def show_on_front(k,v,value=nil,readonly=false)
def format_checkbox(options,value,multple_choose=false)
Array(options).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
if multple_choose
if value[index1]==index1
"#{option[I18n.locale]}"
else
"#{option[I18n.locale]}"
end
else
if index1 == value
"#{option[I18n.locale]}"
else
"#{option[I18n.locale]}"
end
end
end.join('&nbsp;&nbsp;')
end
def show_on_front(k,v,value=nil,readonly=false,lock=false)
field_name = "#{get_input_name}[custom_values][#{k}]"
begin
case v['type']
@ -116,7 +159,11 @@ module Admin::AsksHelper
when 'select'
prompt_hash = v['prompt_word'][I18n.locale].blank? ? {} : {prompt: v['prompt_word'][I18n.locale]}
prompt_hash.merge(:required => v['required']=='true')
readonly ? value : select_tag(field_name,options_for_select(Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect{|index1,option| [option[I18n.locale],index1]},selected: value),prompt_hash)
if lock
format_checkbox(v['options'],value)
else
readonly ? (v['options'][value.to_s][I18n.locale] rescue '') : select_tag(field_name,options_for_select(Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect{|index1,option| [option[I18n.locale],index1]},selected: value),prompt_hash)
end
when 'date'
if value.nil?
value = {}
@ -137,16 +184,24 @@ module Admin::AsksHelper
if value.nil?
value = {}
end
readonly ? v['options'][value.to_i] : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
if lock
format_checkbox(v['options'],value)
else
readonly ? (v['options'][value.to_s][I18n.locale] rescue '') : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
"#{radio_button_tag(field_name,index1,value==index1,{:required => v['required']=='true'})}#{option[I18n.locale]}"
end.join
end
when 'checkbox'
if value.nil?
value = {}
end
if lock
format_checkbox(v['options'],value,true)
else
readonly ? value.collect{|k1,v1| Array(v['options'])[v1.to_i][1][I18n.locale]}.join(', ') : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option|
"#{check_box_tag("#{field_name}[#{index1}]",index1,value[index1]==index1)}#{option[I18n.locale]}"
end.join
end
when 'file'
file_value = value[0] rescue nil
file_path = value[1] rescue nil
@ -165,25 +220,24 @@ module Admin::AsksHelper
</label><div class=\"filename\"></div></div>"
end
rescue => e
debug [e.inspect,e.backtrace]
"<pre>#{e.inspect}<br>#{e.backtrace.to_yaml}</pre>"
end
end
def custom_field_block(k,v={})
set_input_name('ask_setting[custom_fields]')
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 "ask_setting[custom_fields][#{k}][key]",k,{'class' => 'key'}
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("ask_setting[custom_fields][#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
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)}"
"#{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 type=\"button\" value=\"#{t('ask.add_new_options')}\" onclick=\"add_new_options_for_field(this,#{k})\"></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}

View File

@ -0,0 +1,7 @@
class AskCategoryPrintSetting
include Mongoid::Document
include Mongoid::Timestamps
field :print_format, type: String,default: ''
field :save_name, type: String,default: 'ask_{title}'
field :category_id
end

View File

@ -0,0 +1,29 @@
class AskCategorySetting
include Mongoid::Document
include Mongoid::Timestamps
after_initialize do
if !self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
if self.default_setting[:agree_show].nil?
self.default_setting[:agree_show] = true
end
if self.default_setting[:agree_usage].nil?
self.default_setting[:agree_usage] = false
end
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.save
end
end
def custom_fields
tmp = super
tmp.select{|k,v| v['delete'] != true}
end
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 :custom_fields, type: Hash,default: {}
field :usage_rule
field :category_id
end

View File

@ -0,0 +1,6 @@
class AskCategorySettingIndex
include Mongoid::Document
include Mongoid::Timestamps
field :key,type: Integer,default: 0
field :category_id
end

View File

@ -0,0 +1,6 @@
class AskPrintSetting
include Mongoid::Document
include Mongoid::Timestamps
field :print_format, type: String,default: ''
field :save_name, type: String,default: 'ask_{title}'
end

View File

@ -23,6 +23,7 @@ class AskQuestion
field :email_id
field :custom_values, type: Hash,default: {}
field :agree_show,type: Boolean,default: false
field :agree_usage,type: Boolean,default: false
# validates_presence_of :name, :identity, :mail, :title, :content
def email

View File

@ -2,18 +2,27 @@ class AskSetting
include Mongoid::Document
include Mongoid::Timestamps
after_initialize do
if default_setting.class != Hash
default_setting = {}
if !self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
if custom_fields.class != Hash
custom_fields = {}
if self.default_setting[:agree_show].nil?
self.default_setting[:agree_show] = true
end
if self.default_setting[:agree_usage].nil?
self.default_setting[:agree_usage] = false
end
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.save
end
end
def custom_fields
tmp = super
tmp.select{|k,v| v['delete'] != true}
end
field :default_setting, type: Hash,default: {ask_category_id: true,name: true,sex: false,mail: true,phone: false,appointment: false,recaptcha: false}
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 :custom_fields, type: Hash,default: {}
field :usage_rule
end

View File

@ -0,0 +1,142 @@
<style type="text/css">
thead td {
text-align: center;
color: blueviolet;
}
.add_new_options,.prompt_word,.time_setting_block{
display: none;
}
.add_new_options.active,.prompt_word.active,.time_setting_block.active{
display: block;
}
tr td {
text-align: center;
}
tr.custom_field td:nth-child(1){
text-align: left;
}
td{
padding: 0.5em;
}
.tab-content{
display: none;
}
.tab-content.active{
display: block;
}
.tab-panel{
display: flex;
flex-wrap: wrap;
}
tr.custom_field {
border: 0.1em solid #8e00ff;
}
tr.custom_field > td >div {
padding: 0.5em 0;
}
input[type=text] {
height: 30px;
}
</style>
<script type="text/javascript">
<%
option_multi_lang_tag = multiple_lang_tag(-1,'text_field','options][-2',nil,{placeholder: t('ask.option_name')},create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name}[-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}),{},true)
%>
function check_available_setting_block(ele){
var tmp = $(ele).val()
var parent_div = $(ele).parents('.custom_field').eq(0)
if (tmp != 'date' && tmp != 'radio_button' && tmp!='checkbox'){
parent_div.find('.prompt_word').addClass('active')
}else{
parent_div.find('.prompt_word').removeClass('active')
}
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
parent_div.find('.add_new_options').addClass('active')
}else{
parent_div.find('.add_new_options').removeClass('active')
}
if (tmp == 'date'){
parent_div.find('.time_setting_block').addClass('active')
}else{
parent_div.find('.time_setting_block').removeClass('active')
}
}
function delete_field_func(ele){
$(ele).parents('tr').remove()
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)
}
function add_new_options_for_field(ele,key){
var add_html = "<%= option_multi_lang_tag.inspect %>"
add_html = add_html.replace(/-1/g,key)
var parent_div = $(ele).parents('.add_new_options')
var tab_panel = parent_div.eq(0).find('.tab-panel')
var tab_panel_length = tab_panel.length
add_html = add_html.replace(/icons-list-2/g,'icons-list-3')
add_html = add_html.replace(/-2/g,tab_panel_length)
add_html = add_html.replace(/icons-list-3/g,'icons-list-2')
parent_div.find('input[type="button"]').eq(-1).before($('<div/>').html(add_html).text().slice(1,-2))
}
function delete_added_select_option(ele){
var parent_div = $(ele).parents('.tab-panel')
parent_div.find('.disabled_field').val('true')
parent_div.hide()
}
</script>
<style type="text/css">
.border {
padding: 0.5em 0;
border-top: 0.1em solid #099700;
}
</style>
<fieldset>
<table>
<thead>
<tr>
<td>
<%= t('ask.field') %>
</td>
<td>
<%= t('ask.whether_open') %>
</td>
</tr>
</thead>
<tbody>
<% ask_setting.default_setting.each do |k,v| %>
<tr>
<td>
<%= ['agree_show','agree_usage'].include?(k.to_s) ? t("ask.#{k}_checkbox") : t("mongoid.attributes.ask_question.#{k}") %>
</td>
<td>
<%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %>
</td>
</tr>
<% end %>
<tr>
<td>
<%= t("ask.usage_rule") %>
</td>
<td>
<%= f.text_area "usage_rule",class: 'ckeditor' %>
</td>
</tr>
<% ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block(k,v).html_safe %>
<% end %>
<tr class="add_field">
<td colspan="2" style="text-align: center;">
<input class="btn btn-info" type="button" value="<%= t('add')%>" onclick="add_new_field(this)">
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %>
<%= f.hidden_field :id, value: ask_setting.id %>
<input class="btn btn-primary" type="submit" value="<%= submit_text %>">
</td>
</tr>
</tbody>
</table>
</fieldset>

View File

@ -0,0 +1,26 @@
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%= label_tag t('ask.save_name') %>
</td>
<td>
<%= text_field_tag "save_name",print_setting.save_name %>
</td>
</tr>
<tr>
<td>
<%= label_tag t('ask.print_format') %>
</td>
<td>
<%= text_area_tag "print_format",print_setting.print_format,class: 'ckeditor' %>
</td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,8 @@
<%
set_input_name('ask_category_setting[custom_fields]')
%>
<%= form_for ask_setting,method: 'post',url: "/#{I18n.locale}/admin/asks/category_setting_save",html: { class: "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

@ -1,5 +1,5 @@
<%
ask_setting = AskSetting.first
ask_setting = @ask_setting
set_input_name('ask_question')
%>
<% content_for :page_specific_css do %>
@ -43,24 +43,24 @@
<table class="table">
<tr>
<td><%= AskQuestion.human_attribute_name(:name) %><%= @ask_question.name %></td>
<!-- <td><%= AskQuestion.human_attribute_name(:identity) %>
<% Tag.where({:id => @ask_question[:identity]}).each do |tag| %>
<%= tag.name %>
<% end %>
<!-- <td><%# AskQuestion.human_attribute_name(:identity) %>
<%# Tag.where({:id => @ask_question[:identity]}).each do |tag| %>
<%# tag.name %>
<%# end %>
</td> -->
<td><%= AskQuestion.human_attribute_name(:mail) %><%= @ask_question.mail %></td>
<td><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></td>
<!-- <td><%= AskQuestion.human_attribute_name(:fax) %><%= @ask_question.fax %></td> -->
<!-- <td><%# AskQuestion.human_attribute_name(:fax) %><%# @ask_question.fax %></td> -->
</tr>
<tr>
<td colspan="5"><%= t('title') %><%= f.text_field :title %></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"><%# AskQuestion.human_attribute_name(:name) %><%# @ask_question.name %></td> -->
</tr>
<tr>
<!-- <td colspan="5"><%= AskQuestion.human_attribute_name(:name) %><br/><%= @ask_question.name.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td> -->
<!-- <td colspan="5"><%# AskQuestion.human_attribute_name(:name) %><br/><%# @ask_question.name.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td> -->
</tr>
<tr>

View File

@ -31,6 +31,7 @@
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/asks/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/print" target="_blank"><%= t('ask.print') %></a></li>
</ul>
</div>
</td>

View File

@ -0,0 +1,126 @@
<% trans = 'mongoid.attributes.ask_question' %>
<div style="font-size: 1.5em;">
<%= t('ask.explanation') %>:
<br>
{ask_time} -> <%= t('ask.ask_time') %>
<br>
{title} -> <%= t('title') %>
<br>
{category} -> <%= t("#{trans}.ask_category_id") %>
<br>
{name} -> <%= t("#{trans}.name") %>
<br>
{name|mask} -> <%= t("ask.name_mask") %>
<br>
{sex} -> <%= t("#{trans}.sex") %>
(<%= t("#{trans}.male") %>/<%= t("#{trans}.female") %>)
<br>
{mail} -> <%= t("#{trans}.mail") %>
<br>
{phone} -> <%= t("#{trans}.phone") %>
<br>
{appointment} -> <%= t("#{trans}.appointment") %>
<br>
{agree_show} -> <%= t("#{trans}.agree_show_explain") %>
<br>
{custom1} -> <%= t("ask.custom1") %>
<br>
{custom2} -> <%= t("ask.custom2") %>
<br>
{custom3} -> <%= t("ask.custom3") %>
<br>
<%= t("ask.and_so_on") %>
<br>
{custom} -><%= t("ask.custom_explain") %>
<br>
{custom|format} -><%= t("ask.custom_format_explain") %>
<br>
{?_title} -> ?<%= t("ask.can_be_filled_with") %>ask_time、title、category、name、sex、mail、phone、appointment、agree_show、custom、custom1、custom2、custom3 ...,<%= t("ask.show_title_trans") %>, <%= t("ask.like") %>{sex_title}-><%= t("#{trans}.sex") %>
<br>
<br>
<%= t("ask.example") %>:
<br>
<%= t("ask.example_explain") %>
<br>
<%= t('ask.print_format') %>:
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td style="text-align: center;"><%= t("ask.example") %></td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td>{title_title}</td>
<td>{title}</td>
</tr>
<tr>
<td>{category_title}</td>
<td>{category}</td>
</tr>
<tr>
<td>{name_title}</td>
<td>{name}</td>
</tr>
<tr>
<td>{mail_title}</td>
<td>{mail}</td>
</tr>
<tr>
<td>{custom_title}</td>
<td>{custom}</td>
</tr>
<tr>
<td>{custom1_title}</td>
<td>{custom1}</td>
</tr>
</tbody>
</table>
<br>
<br>
<%= t('ask.output_result') %>:
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td style="text-align: center;"><%= t("ask.example") %></td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td><%= t('title') %></td>
<td>example</td>
</tr>
<tr>
<td><%= t("#{trans}.ask_category_id") %></td>
<td>測試</td>
</tr>
<tr>
<td><%= t("#{trans}.name") %></td>
<td>工程師1號</td>
</tr>
<tr>
<td><%= t("#{trans}.mail") %></td>
<td>test@rulingcom.com</td>
</tr>
<tr>
<td>test2</td>
<td>b</td>
</tr>
<tr>
<td>test3</td>
<td>c</td>
</tr>
<tr>
<td>test1</td>
<td>a</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,173 @@
<%= t('ask.setting_type') %>: <%= select_tag "setting_type", options_for_select([[t('ask.field_setting'),'field'],[t('ask.print_setting'),'print']]), :class => "category-selector" %>
<script type="text/javascript">
$('#setting_type').change(function(){
if ($(this).val()=='field'){
$('#field').attr('class','fade-in active')
$('#print').attr('class','fade-in')
}
else{
$('#field').attr('class','fade-in')
$('#print').attr('class','fade-in active')
}
})
$(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])
}
})
}
});
})
</script>
<div class="fade-in active" id="field">
<style type="text/css">
.category-set-page input[type="submit"],.category-set-page input[type="button"]{
visibility: hidden;
}
.fade-in{
display: none;
}
.fade-in.active{
display: block;
}
form.fade-in.active{
border: 0.3em solid #132e8b;
padding: 1em;
}
a.toggle_tag{
outline: 0;
background: #cad0da;
padding: 1em;
display: inline-block;
}
a.toggle_tag.active_in{
color: white;
background: #495c7a;
}
a.toggle_tag:not(:first-child){
border-left: 0.1em solid #9d3874;
}
.toggle_tag_group{
display: flex;
flex-wrap: wrap;
}
</style>
<%
set_input_name('ask_category_setting[custom_fields]')
%>
<script type="text/javascript">
function add_new_field(ele){
var category_id = $(ele).parents('form').eq(0).data('cat-id')
$.ajax({
url : "<%= "/#{I18n.locale}/admin/asks/get_new_category_setting_index" %>",
dataType : "json",
type : "post",
data: {category_id: category_id},
error: function(){
alert('init process failed, please try again later.')
},
success: function(data){
var add_field_html = "<%= custom_field_block(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
$('.add_new_options').sortable({'handle':'.icons-list-2'})
}
})
}
</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: "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 %>
<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 %>
<% end %>
</div>
<% if !first_category_added.nil? %>
<%= render partial: 'category_setting_field',locals: {ask_setting: first_category_added} %>
<% end %>
</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='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="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>

View File

@ -0,0 +1,48 @@
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js">
</script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
<%= javascript_include_tag "jspdf.min" %>
<style>
input[type="button"],button,input[type="submit"] {
outline: 0;
border-radius: 1.3em;
background: #d9e4f7;
font-weight: bold;
outline: 0;
}
input[type="button"]:hover,button:hover,input[type="submit"]:hover {
background: #be8a8a;
}
.print_text{
padding: 2em;
width: 650px;
margin: auto;
}
@media print
{
.no-print, .no-print *
{
display: none !important;
}
}
</style>
<script type="text/javascript">
function save_data(){
var filename = '<%= @save_name %>.pdf';
$('div.print_text').find('input[type=button]').hide()
html2canvas($('div.print_text')[0]).then(canvas => {
var pdf = new jsPDF('px', 'mm', 'a4');
var width = pdf.internal.pageSize.getWidth()-3;
var height = pdf.internal.pageSize.getHeight();
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0,width ,height );
pdf.save(filename);
});
$('div.print_text').find('input[type=button]').show()
}
</script>
<div class="no-print" style="text-align: center;">
<input onclick="save_data()" value="<%= I18n.t('ask.save_data') %>" type="button">
</div>
<div class="print_text">
<%= @print_text.html_safe %>
</div>

View File

@ -0,0 +1,126 @@
<% trans = 'mongoid.attributes.ask_question' %>
<div style="font-size: 1.5em;">
<%= t('ask.explanation') %>:
<br>
{ask_time} -> <%= t('ask.ask_time') %>
<br>
{title} -> <%= t('title') %>
<br>
{category} -> <%= t("#{trans}.ask_category_id") %>
<br>
{name} -> <%= t("#{trans}.name") %>
<br>
{name|mask} -> <%= t("ask.name_mask") %>
<br>
{sex} -> <%= t("#{trans}.sex") %>
(<%= t("#{trans}.male") %>/<%= t("#{trans}.female") %>)
<br>
{mail} -> <%= t("#{trans}.mail") %>
<br>
{phone} -> <%= t("#{trans}.phone") %>
<br>
{appointment} -> <%= t("#{trans}.appointment") %>
<br>
{agree_show} -> <%= t("#{trans}.agree_show_explain") %>
<br>
{custom1} -> <%= t("ask.custom1") %>
<br>
{custom2} -> <%= t("ask.custom2") %>
<br>
{custom3} -> <%= t("ask.custom3") %>
<br>
<%= t("ask.and_so_on") %>
<br>
{custom} -><%= t("ask.custom_explain") %>
<br>
{custom|format} -><%= t("ask.custom_format_explain") %>
<br>
{?_title} -> ?<%= t("ask.can_be_filled_with") %>ask_time、title、category、name、sex、mail、phone、appointment、agree_show、custom、custom1、custom2、custom3 ...,<%= t("ask.show_title_trans") %>, <%= t("ask.like") %>{sex_title}-><%= t("#{trans}.sex") %>
<br>
<br>
<%= t("ask.example") %>:
<br>
<%= t("ask.example_explain") %>
<br>
<%= t('ask.print_format') %>:
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td style="text-align: center;"><%= t("ask.example") %></td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td>{title_title}</td>
<td>{title}</td>
</tr>
<tr>
<td>{category_title}</td>
<td>{category}</td>
</tr>
<tr>
<td>{name_title}</td>
<td>{name}</td>
</tr>
<tr>
<td>{mail_title}</td>
<td>{mail}</td>
</tr>
<tr>
<td>{custom_title}</td>
<td>{custom}</td>
</tr>
<tr>
<td>{custom1_title}</td>
<td>{custom1}</td>
</tr>
</tbody>
</table>
<br>
<br>
<%= t('ask.output_result') %>:
<br>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td style="text-align: center;"><%= t("ask.example") %></td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td><%= t('title') %></td>
<td>example</td>
</tr>
<tr>
<td><%= t("#{trans}.ask_category_id") %></td>
<td>測試</td>
</tr>
<tr>
<td><%= t("#{trans}.name") %></td>
<td>工程師1號</td>
</tr>
<tr>
<td><%= t("#{trans}.mail") %></td>
<td>test@rulingcom.com</td>
</tr>
<tr>
<td>test2</td>
<td>b</td>
</tr>
<tr>
<td>test3</td>
<td>c</td>
</tr>
<tr>
<td>test1</td>
<td>a</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,36 @@
<%= form_for @set,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
<fieldset>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%= label_tag t('ask.save_name') %>
</td>
<td>
<%= f.text_field :save_name %>
</td>
</tr>
<tr>
<td>
<%= label_tag t('ask.print_format') %>
</td>
<td>
<%= f.text_area :print_format,class: 'ckeditor' %>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input class="btn btn-primary" type="submit" value="<%= t('submit')%>">
</td>
</tr>
</tbody>
</table>
</fieldset>
<% end %>
<%= render partial: 'print_format_explain' %>

View File

@ -1,89 +1,7 @@
<%
set_input_name('ask_setting[custom_fields]')
%>
<style type="text/css">
thead td {
text-align: center;
color: blueviolet;
}
.add_new_options,.prompt_word,.time_setting_block{
display: none;
}
.add_new_options.active,.prompt_word.active,.time_setting_block.active{
display: block;
}
tr td {
text-align: center;
}
tr.custom_field td:nth-child(1){
text-align: left;
}
td{
padding: 0.5em;
}
.tab-content{
display: none;
}
.tab-content.active{
display: block;
}
.tab-panel{
display: flex;
flex-wrap: wrap;
}
tr.custom_field {
border: 0.1em solid #8e00ff;
}
tr.custom_field > td >div {
padding: 0.5em 0;
}
input[type=text] {
height: 30px;
}
</style>
<script type="text/javascript">
<%
option_multi_lang_tag = multiple_lang_tag(-1,'text_field','options][-2',nil,{placeholder: t('ask.option_name')},create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("ask_setting[custom_fields][-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}))
%>
function check_available_setting_block(ele){
var tmp = $(ele).val()
var parent_div = $(ele).parents('.custom_field').eq(0)
if (tmp != 'date' && tmp != 'radio_button' && tmp!='checkbox'){
parent_div.find('.prompt_word').addClass('active')
}else{
parent_div.find('.prompt_word').removeClass('active')
}
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
parent_div.find('.add_new_options').addClass('active')
}else{
parent_div.find('.add_new_options').removeClass('active')
}
if (tmp == 'date'){
parent_div.find('.time_setting_block').addClass('active')
}else{
parent_div.find('.time_setting_block').removeClass('active')
}
}
function delete_field_func(ele){
$(ele).parents('tr').remove()
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)
}
function add_new_options_for_field(ele,key){
var add_html = "<%= option_multi_lang_tag.inspect %>"
add_html = add_html.replace(/-1/g,key)
var parent_div = $(ele).parents('.add_new_options')
var tab_panel = parent_div.eq(0).find('.tab-panel')
var tab_panel_length = tab_panel.length
add_html = add_html.replace(/-2/g,tab_panel_length)
parent_div.find('input[type="button"]').eq(-1).before($('<div/>').html(add_html).text().slice(1,-2))
}
function delete_added_select_option(ele){
var parent_div = $(ele).parents('.tab-panel')
parent_div.find('.disabled_field').val('true')
parent_div.hide()
}
<script>
function add_new_field(){
$.ajax({
url : "<%= get_new_setting_index_admin_asks_path %>",
@ -96,50 +14,16 @@
var add_field_html = "<%= custom_field_block(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
$('.add_new_options').sortable({'handle':'.icons-list-2'})
}
})
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$('.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| %>
<fieldset>
<table>
<thead>
<tr>
<td>
<%= t('ask.field') %>
</td>
<td>
<%= t('ask.whether_open') %>
</td>
</tr>
</thead>
<tbody>
<% @ask_setting.default_setting.each do |k,v| %>
<tr>
<td>
<%= t("mongoid.attributes.ask_question.#{k}") %>
</td>
<td>
<%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %>
</td>
</tr>
<% end %>
<% @ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block(k,v).html_safe %>
<% end %>
<tr class="add_field">
<td colspan="2" style="text-align: center;">
<input class="btn btn-info" type="button" value="<%= t('add')%>" onclick="add_new_field()">
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %>
<%= f.hidden_field :id, value: @ask_setting.id %>
<input class="btn btn-primary" type="submit" value="<%= t('submit')%>">
</td>
</tr>
</tbody>
</table>
</fieldset>
<%= render partial: 'ask_setting',locals:{ask_setting: @ask_setting,f: f,submit_text: t('submit')} %>
<% end %>

View File

@ -3,8 +3,8 @@
@categories = data["categories"]
@tags = data["tags"]
@module_app = data["module_app"]
ask_setting = AskSetting.first
ask_setting = AskSetting.create() if ask_setting.nil?
@switch_form = data["switch_form"]
ask_setting = data["ask_setting"]
set_input_name('ask_question')
%>
<% if data['layout_type'] != 'index' %>
@ -12,7 +12,7 @@
<% else %>
<style type="text/css">
#new-ask-question .form-horizontal .control-group > *{
font-size: 1.5em;
font-size: 1.125em;
}
.default_picker label{
display: none;
@ -65,6 +65,26 @@
<%= stylesheet_link_tag "custom_field" %>
<%# stylesheet_link_tag "jquery-ui-timepicker-addon" %>
<script type="text/javascript">
$(document).ready(function(){
$('select[name="ask_question[category_id]"]').change(function(){
var category_id = $(this).val()
$(this).parents('.ask-question').eq(0).find('select[name="ask_question[category_id]"]').val(category_id)
var id
if ($('form#'+category_id).length != 0){
id = category_id
}
else{
id = 'ask-default-form'
}
if (id != $(this).parents('form').eq(0).attr('id')){
$(this).parents('.ask-question').eq(0).find('form').hide()
$(this).parents('.ask-question').eq(0).find('form#'+id).show()
}
})
})
var datepicker_fn = $.fn.datepicker
var datepicker = $.datepicker
$(document).ready(function(){
@ -76,7 +96,6 @@
</script>
<%# javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%# javascript_include_tag "jquery.ui.datepicker.monthyearpicker" %>
<%= javascript_include_tag 'validator' %>
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<div id="new-ask-question" class="ask-question">
@ -200,18 +219,37 @@
</div>
</div>
<% end %>
<% if !ask_setting.usage_rule.blank? %>
<div class="control-group">
<%= label_tag :usage_rule,t('ask.usage_rule'), class: 'control-label' %>
<div class="controls">
<%= ask_setting.usage_rule.html_safe %>
</div>
</div>
<% end %>
<% if ask_setting.default_setting['agree_usage'] %>
<div class="control-group">
<%= f.label :agree_usage, class: 'control-label' %>
<div class="controls">
<%= f.check_box :agree_usage %>
</div>
</div>
<% end %>
<% if ask_setting.default_setting['agree_show'] %>
<div class="control-group">
<%= f.label :agree_show, class: 'control-label' %>
<div class="controls">
<%= f.check_box :agree_show %>
</div>
</div>
<% end %>
<div class="form-actions">
<input type="hidden" name="referer_url" value="<%= request.original_url.split(request.env["HTTP_HOST"]).last %>">
<%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>
<% end %>
<%= @switch_form.html_safe %>
</div>
<script type='text/javascript'>
@ -228,8 +266,11 @@
// if( $("#ask_question_content").val()=='' ) $("#ask_question_content").css('border','1px solid #F00');
// });
$('#new-ask-question .required').each(function() {
$(this).text('*' + $(this).text());
$('.ask-question .required').each(function() {
var text = $(this).text()
if (text[0]!='*'){
$(this).text('*' + text);
}
});
// $('#new-ask-question form') .submit(function() {

View File

@ -14,3 +14,5 @@
<% end %>
</tbody>
</table>
<% total_pages = data['ask_questions'].total_pages %>
<%= create_pagination(total_pages).html_safe if total_pages > 1 %>

View File

@ -1,7 +1,7 @@
<% ask = data['ask_question'] %>
<style type="text/css">
.ask-question .form-horizontal .control-group > *{
font-size: 1.5em;
font-size: 1.125em;
}
.default_picker label{
display: none;

View File

@ -2,6 +2,35 @@ en:
situation: Situation
sex: Sex
ask:
more_title: See more ask history
save_name: Save FileName
usage_rule: Usage rule
agree_show_checkbox: Agree reply content display on website checkbox
agree_usage_checkbox: Agree related usage rule checkbox
setting_type: Setting Type
field_setting: Field Setting
modify: Modify
select_category: '-----Select a category-----'
save_data: Save as pdf
print: Print
ask_time: Ask Time
custom_format_explain: use checkbox format to show custom-field's value
output_result: Output result
example: Example
example_explain: 'When custom field is test1、test2、test3, and being filled with a、b、c'
like: 'Like '
and_so_on: and so on
custom1: the first custom field
custom2: the second custom field
custom3: the third custom field
can_be_filled_with: can be filled with
show_title_trans: which will show the title's label being translated on now local
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
print_setting: Print Format Setting
print_format: Print Format
file_field: File Field
image_field: Image Field
upload_file: Upload File
@ -46,6 +75,7 @@ en:
mongoid:
attributes:
ask_question:
agree_usage: Agree related usage rule
ask_category_id: Ask Category
recaptcha: Recaptcha
sex: Sex
@ -65,3 +95,4 @@ en:
status: Status
send_email: Whether to reply email
agree_show: Do you agree on displaying your request and our reply on the webpage without your personal information?
agree_show_explain: Whether to agree on displaying your request and our reply on the webpage without your personal information?

View File

@ -8,6 +8,35 @@ zh_tw:
errors:
verification_failed: 驗證碼錯誤
ask:
more_title: 查看更多發問紀錄
save_name: 檔案儲存名稱
usage_rule: 使用規範
agree_show_checkbox: 同意回覆內容刊載於網站勾選框
agree_usage_checkbox: 同意相關使用規範勾選框
setting_type: 設定類型
field_setting: 欄位設定
modify: 修改
select_category: '-----選擇類別-----'
save_data: 存為pdf
print: 列印
ask_time: 詢問時間
custom_format_explain: 使用checkbox樣式來呈現單選或多選的欄位
output_result: 輸出結果
example: 範例
example_explain: '當客製化欄位為: test1、test2、test3被填入: a、b、c'
like:
and_so_on: 以此類推
custom1: 客製化欄位的第一個欄位
custom2: 客製化欄位的第二個欄位
custom3: 客製化欄位的第三個欄位
custom_explain: 客製化欄位(會自動將所有新增的客製欄位帶入表格,但排除已使用數字加入的欄位)
can_be_filled_with: 可填入
show_title_trans: 會顯示當前語言的標籤翻譯
explanation: 說明
name_mask: 姓名只顯示第一個字,如蔡**
category_setting: 類別管理設定
print_setting: 列印格式設定
print_format: 列印格式
file_field: 檔案欄位
image_field: 照片欄位
upload_file: 上傳檔案
@ -59,6 +88,7 @@ zh_tw:
mongoid:
attributes:
ask_question:
agree_usage: 同意相關使用規範
ask_category_id: 諮詢類別
recaptcha: 驗證碼
sex: 性別
@ -78,3 +108,4 @@ zh_tw:
status: 狀態
send_email: 是否回信
agree_show: 是否同意您提出之需求及回覆內容以不呈現發問者資訊方式刊載於網站供他人參考?
agree_show_explain: 是否同意刊載於網站給他人參考

View File

@ -5,10 +5,22 @@ Rails.application.routes.draw do
namespace :admin do #backend
resources :asks do
collection do
get ':id/print', to: 'asks#print'
get 'export'
get 'setting'
get 'category_setting'
post 'get_category_setting_field'
post 'category_setting_save'
get 'category_setting_delete'
get 'category_print_setting_delete'
post 'category_print_setting_save'
get 'category_print_setting_save'
get 'get_new_category_setting_index'
get 'print_setting'
post 'print_setting_save'
post 'setting_save'
post 'get_new_setting_index'
post 'get_new_category_setting_index'
post 'export', to: 'asks#do_export'
end
end

View File

@ -27,11 +27,23 @@ module Ask
begin
require File.expand_path('../../../app/models/ask_setting', __FILE__)
require File.expand_path('../../../app/models/ask_setting_index', __FILE__)
if defined? AskSetting && AskSetting.first.nil?
if defined?(AskSetting)
if AskSetting.first.nil?
AskSetting.create()
elsif AskSetting.count > 1
AskSetting.all[1..-1].each do |ask_setting|
ask_setting.destroy
end
if defined? AskSettingIndex && AskSettingIndex.first.nil?
end
end
if defined?(AskSettingIndex)
if AskSettingIndex.first.nil?
AskSettingIndex.create()
elsif AskSettingIndex.count > 1
AskSettingIndex.all[1..-1].each do |ask_setting_index|
ask_setting_index.destroy
end
end
end
rescue => e
puts ['AskSetting not found',e]
@ -63,11 +75,6 @@ module Ask
:priority=>1,
:active_for_action=>{'admin/asks'=>'index'},
:available_for => 'users'
context_link 'ask.setting',
:link_path=>"setting_admin_asks_path" ,
:priority=>5,
:active_for_action=>{'admin/asks'=>'setting'},
:available_for => 'managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
@ -80,16 +87,6 @@ module Ask
:priority=>3,
:active_for_action=>{'admin/asks'=>'acknowledgements'},
:available_for => 'managers'
context_link 'ask.admins',
:link_path=>"admin_ask_admins_path" ,
:priority=>4,
:active_for_action=>{'admin/asks'=>'admins'},
:available_for => 'managers'
context_link 'ask.exports',
:link_path=>"export_admin_asks_path" ,
:priority=>5,
:active_for_action=>{'admin/asks'=>'exports'},
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
@ -97,6 +94,31 @@ module Ask
: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,
:active_for_action=>{'admin/asks'=>'admins'},
:available_for => 'managers'
context_link 'ask.exports',
:link_path=>"export_admin_asks_path" ,
:priority=>6,
:active_for_action=>{'admin/asks'=>'exports'},
:available_for => '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 => 'managers'
context_link 'ask.print_setting',
:link_path=>"print_setting_admin_asks_path" ,
:priority=>8,
:active_for_action=>{'admin/asks'=>'print_setting'},
:available_for => 'managers'
# context_link 'new_',
# :link_path=>"new_admin_ask_path" ,
# :priority=>2,

View File

@ -1,7 +1,7 @@
<div class="widget-ask widget1">
<style type="text/css">
#new-ask-question .form-horizontal .control-group > *{
font-size: 1.2em;
font-size: 1.125em;
}
.default_picker label{
display: none;
@ -51,9 +51,34 @@
<link href="/assets/custom_field.css" media="screen" rel="stylesheet">
<script src="/assets/validator"></script>
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<h3 class="widget-title">
<span>{{widget-title}}</span>
</h3>
<div id="new-ask-question" class="ask-question">
<form action="{{form_url}}" enctype="multipart/form-data" method="post" class="form-horizontal" accept-charset="UTF-8">
{{token_tag}}
<div data-level="0" data-list="fields">
<div class="control-group" style="{{style_html}}">
{{label}}
<div class="controls">
{{content}}
</div>
</div>
</div>
<div class="form-actions">
<input type="hidden" name="referer_url" value="{{referer_url}}">
{{submit_tag}}
{{close_tag}}
</div>
</form>
{{switch_form}}
</div>
<script type='text/javascript'>
$('#new-ask-question .required').each(function() {
$(this).text('*' + $(this).text());
$('.ask-question .required').each(function() {
var text = $(this).text()
if (text[0]!='*'){
$(this).text('*' + text);
}
});
$(function(){
var fv = new FormValidator($("#new_ask_question"));
@ -67,25 +92,4 @@
}
})
</script>
<h3 class="widget-title">
<span>{{widget-title}}</span>
</h3>
<div id="new-ask-question" class="ask-question">
<form action="{{form_url}}" enctype="multipart/form-data" method="post" class="form-horizontal" accept-charset="UTF-8">
{{token_tag}}
<div data-level="0" data-list="fields">
<div class="control-group">
{{label}}
<div class="controls">
{{content}}
</div>
</div>
</div>
<div class="form-actions">
<input type="hidden" name="referer_url" value="{{referer_url}}">
{{submit_tag}}
{{close_tag}}
</div>
</form>
</div>
</div>

View File

@ -14,4 +14,5 @@
</tr>
</tbody>
</table>
<div style="background: #337ab7; border: 1px solid rgb(204, 204, 204); padding: 5px 10px; text-align: right;"><span style="color:inherit;"><a href="{{more_href}}" title="{{more_title}}"><span style="color:#FFFFFF;">{{more_title}}</span></a></span></div>
</div>