From 1cca61a0c4a7d999f39151c02e47784fee690c93 Mon Sep 17 00:00:00 2001 From: chiu Date: Sat, 4 Jul 2020 21:36:32 +0800 Subject: [PATCH] add category setting and print setting --- app/controllers/admin/asks_controller.rb | 194 +++++++++++++++- app/controllers/asks_controller.rb | 218 ++++++++++++++---- app/helpers/admin/asks_helper.rb | 116 +++++++--- app/models/ask_category_print_setting.rb | 7 + app/models/ask_category_setting.rb | 29 +++ app/models/ask_category_setting_index.rb | 6 + app/models/ask_print_setting.rb | 6 + app/models/ask_question.rb | 1 + app/models/ask_setting.rb | 23 +- app/views/admin/asks/_ask_setting.html.erb | 142 ++++++++++++ .../asks/_category_print_setting.html.erb | 26 +++ .../asks/_category_setting_field.html.erb | 8 + app/views/admin/asks/_form.html.erb | 16 +- app/views/admin/asks/_index.html.erb | 1 + .../admin/asks/_print_format_explain.html.erb | 126 ++++++++++ .../admin/asks/category_setting.html.erb | 173 ++++++++++++++ app/views/admin/asks/print.html.erb | 48 ++++ .../admin/asks/print_format_explain.html.erb | 126 ++++++++++ app/views/admin/asks/print_setting.html.erb | 36 +++ app/views/admin/asks/setting.html.erb | 132 +---------- app/views/asks/index.html.erb | 63 ++++- app/views/asks/published_index.erb | 4 +- app/views/asks/show.html.erb | 2 +- config/locales/en.yml | 33 ++- config/locales/zh_tw.yml | 33 ++- config/routes.rb | 12 + lib/ask/engine.rb | 60 +++-- modules/ask/_ask_widget_form.html.erb | 52 +++-- modules/ask/_ask_widget_list.html.erb | 3 +- 29 files changed, 1408 insertions(+), 288 deletions(-) create mode 100644 app/models/ask_category_print_setting.rb create mode 100644 app/models/ask_category_setting.rb create mode 100644 app/models/ask_category_setting_index.rb create mode 100644 app/models/ask_print_setting.rb create mode 100644 app/views/admin/asks/_ask_setting.html.erb create mode 100644 app/views/admin/asks/_category_print_setting.html.erb create mode 100644 app/views/admin/asks/_category_setting_field.html.erb create mode 100644 app/views/admin/asks/_print_format_explain.html.erb create mode 100644 app/views/admin/asks/category_setting.html.erb create mode 100644 app/views/admin/asks/print.html.erb create mode 100644 app/views/admin/asks/print_format_explain.html.erb create mode 100644 app/views/admin/asks/print_setting.html.erb diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index 917c79e..4b2a932 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -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 - 'back_end_with_jquery_first' + 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(//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 = AskSetting.first - ask_setting = AskSetting.create() if ask_setting.nil? + 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 diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index 490325f..5e9b07b 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -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_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'=>"#{@categories[0].title rescue ''}"+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 ''))}] + 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 - 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'] = " - " - 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'] = "
#{text_field_tag(field_name,placeholder:t("#{tmp}.#{field}"))}
" - end - f1 + 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 - 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 @@ -130,7 +107,19 @@ class AsksController < ActionController::Base if @layout_type == 'index' module_app = ModuleApp.where(:key => "ask").first categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all'] - categories = module_app.categories if categories.include? '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 = AskSetting.first - ask_setting = AskSetting.create() if ask_setting.nil? + 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'=>"#{(categories[0].title rescue '')}"+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'] = " + " + 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'] = "
#{text_field_tag(field_name,placeholder:t("#{tmp}.#{field}"))}
" + 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'] + "
+ #{label} +
+ #{content} +
+
" + end.join + "
+ #{token_tag} +
+ #{tmp} +
+
+ + #{submit_tag} + #{close_tag} +
+
" + end + def script_text + "" + 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 \ No newline at end of file diff --git a/app/helpers/admin/asks_helper.rb b/app/helpers/admin/asks_helper.rb index c5dd961..31eb728 100644 --- a/app/helpers/admin/asks_helper.rb +++ b/app/helpers/admin/asks_helper.rb @@ -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,24 +25,39 @@ 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 - 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| - 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 - if !index1.nil? - self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options) - else - self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{field}][#{locale}]",value_locale,custom_options) - 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(/\]/,'') + 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 + if !index1.nil? + self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{index1}][#{field}][#{locale}]",value_locale,custom_options) + else + self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{field}][#{locale}]",value_locale,custom_options) end - end.join + create_lang_panel(all_field)).html_safe + combine_element + 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 + ("" +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('  ') + 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| - "#{radio_button_tag(field_name,index1,value==index1,{:required => v['required']=='true'})}#{option[I18n.locale]}" - end.join + 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 - 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 + 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
" end rescue => e - debug [e.inspect,e.backtrace] + "
#{e.inspect}
#{e.backtrace.to_yaml}
" 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 = "
#{multiple_lang_tag(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word')})}
" require_ask_tag = "
#{t('ask.required')}:  #{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')}
" - tmp = "
#{all_new_options}
" + tmp = "
#{all_new_options}
" field_html = " #{multi_lang_tag} diff --git a/app/models/ask_category_print_setting.rb b/app/models/ask_category_print_setting.rb new file mode 100644 index 0000000..4cb0f7f --- /dev/null +++ b/app/models/ask_category_print_setting.rb @@ -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 diff --git a/app/models/ask_category_setting.rb b/app/models/ask_category_setting.rb new file mode 100644 index 0000000..7acfba8 --- /dev/null +++ b/app/models/ask_category_setting.rb @@ -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 diff --git a/app/models/ask_category_setting_index.rb b/app/models/ask_category_setting_index.rb new file mode 100644 index 0000000..05a4995 --- /dev/null +++ b/app/models/ask_category_setting_index.rb @@ -0,0 +1,6 @@ +class AskCategorySettingIndex + include Mongoid::Document + include Mongoid::Timestamps + field :key,type: Integer,default: 0 + field :category_id +end diff --git a/app/models/ask_print_setting.rb b/app/models/ask_print_setting.rb new file mode 100644 index 0000000..4cc4ab4 --- /dev/null +++ b/app/models/ask_print_setting.rb @@ -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 diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb index ce88b31..b224979 100644 --- a/app/models/ask_question.rb +++ b/app/models/ask_question.rb @@ -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 diff --git a/app/models/ask_setting.rb b/app/models/ask_setting.rb index 81f7677..f0c4ca1 100644 --- a/app/models/ask_setting.rb +++ b/app/models/ask_setting.rb @@ -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 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 - if custom_fields.class != Hash - custom_fields = {} - end - self.save 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 diff --git a/app/views/admin/asks/_ask_setting.html.erb b/app/views/admin/asks/_ask_setting.html.erb new file mode 100644 index 0000000..68b1da5 --- /dev/null +++ b/app/views/admin/asks/_ask_setting.html.erb @@ -0,0 +1,142 @@ + + + + +
+ + + + + + + + + <% ask_setting.default_setting.each do |k,v| %> + + + + + <% end %> + + + + + <% ask_setting.custom_fields.each do |k,v| %> + <%= custom_field_block(k,v).html_safe %> + <% end %> + + + + + + + +
+ <%= t('ask.field') %> + + <%= t('ask.whether_open') %> +
+ <%= ['agree_show','agree_usage'].include?(k.to_s) ? t("ask.#{k}_checkbox") : t("mongoid.attributes.ask_question.#{k}") %> + + <%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %> +
+ <%= t("ask.usage_rule") %> + + <%= f.text_area "usage_rule",class: 'ckeditor' %> +
+ +
+ <%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %> + <%= f.hidden_field :id, value: ask_setting.id %> + +
+
\ No newline at end of file diff --git a/app/views/admin/asks/_category_print_setting.html.erb b/app/views/admin/asks/_category_print_setting.html.erb new file mode 100644 index 0000000..77b6777 --- /dev/null +++ b/app/views/admin/asks/_category_print_setting.html.erb @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + +
+ <%= label_tag t('ask.save_name') %> + + <%= text_field_tag "save_name",print_setting.save_name %> +
+ <%= label_tag t('ask.print_format') %> + + <%= text_area_tag "print_format",print_setting.print_format,class: 'ckeditor' %> +
diff --git a/app/views/admin/asks/_category_setting_field.html.erb b/app/views/admin/asks/_category_setting_field.html.erb new file mode 100644 index 0000000..5b5b891 --- /dev/null +++ b/app/views/admin/asks/_category_setting_field.html.erb @@ -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 %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/asks/_form.html.erb b/app/views/admin/asks/_form.html.erb index a8d321e..bcf6a1e 100644 --- a/app/views/admin/asks/_form.html.erb +++ b/app/views/admin/asks/_form.html.erb @@ -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 @@ - - + - + - + diff --git a/app/views/admin/asks/_index.html.erb b/app/views/admin/asks/_index.html.erb index 6d5e714..de7c428 100644 --- a/app/views/admin/asks/_index.html.erb +++ b/app/views/admin/asks/_index.html.erb @@ -31,6 +31,7 @@
  • <%= t(:edit) %>
  • <%= t(:delete_) %>
  • <% end %> +
  • <%= t('ask.print') %>
  • diff --git a/app/views/admin/asks/_print_format_explain.html.erb b/app/views/admin/asks/_print_format_explain.html.erb new file mode 100644 index 0000000..741693a --- /dev/null +++ b/app/views/admin/asks/_print_format_explain.html.erb @@ -0,0 +1,126 @@ +<% trans = 'mongoid.attributes.ask_question' %> +
    + <%= t('ask.explanation') %>: +
    + {ask_time} -> <%= t('ask.ask_time') %> +
    + {title} -> <%= t('title') %> +
    + {category} -> <%= t("#{trans}.ask_category_id") %> +
    + {name} -> <%= t("#{trans}.name") %> +
    + {name|mask} -> <%= t("ask.name_mask") %> +
    + {sex} -> <%= t("#{trans}.sex") %> + (<%= t("#{trans}.male") %>/<%= t("#{trans}.female") %>) +
    + {mail} -> <%= t("#{trans}.mail") %> +
    + {phone} -> <%= t("#{trans}.phone") %> +
    + {appointment} -> <%= t("#{trans}.appointment") %> +
    + {agree_show} -> <%= t("#{trans}.agree_show_explain") %> +
    + {custom1} -> <%= t("ask.custom1") %> +
    + {custom2} -> <%= t("ask.custom2") %> +
    + {custom3} -> <%= t("ask.custom3") %> +
    + <%= t("ask.and_so_on") %> +
    + {custom} -><%= t("ask.custom_explain") %> +
    + {custom|format} -><%= t("ask.custom_format_explain") %> +
    + {?_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") %> +
    +
    + <%= t("ask.example") %>: +
    + <%= t("ask.example_explain") %> +
    + <%= t('ask.print_format') %>: +
    +
    <%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %> <%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %> <%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %>
    <%= t('title') %>:<%= f.text_field :title %>
    <%= AskQuestion.human_attribute_name(:appointment) %>:<%= @ask_question.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %>
    + + + + + +
    <%= t("ask.example") %>
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {title_title}{title}
    {category_title}{category}
    {name_title}{name}
    {mail_title}{mail}
    {custom_title}{custom}
    {custom1_title}{custom1}
    +
    +
    + <%= t('ask.output_result') %>: +
    + + + + + + +
    <%= t("ask.example") %>
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t('title') %>example
    <%= t("#{trans}.ask_category_id") %>測試
    <%= t("#{trans}.name") %>工程師1號
    <%= t("#{trans}.mail") %>test@rulingcom.com
    test2b
    test3c
    test1a
    + \ No newline at end of file diff --git a/app/views/admin/asks/category_setting.html.erb b/app/views/admin/asks/category_setting.html.erb new file mode 100644 index 0000000..cbf88ba --- /dev/null +++ b/app/views/admin/asks/category_setting.html.erb @@ -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" %> + +
    + + <% + set_input_name('ask_category_setting[custom_fields]') + %> + + <% 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| %> +
    + <% 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')} %> +
    + <% end %> + <% end %> + <% index1 = 0 %> + <% first_category_added = nil %> +
    + <% @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 %> + <%= name1.blank? ? "no name" : name1 %> + <% end %> + <% end %> +
    + <% if !first_category_added.nil? %> + <%= render partial: 'category_setting_field',locals: {ask_setting: first_category_added} %> + <% end %> +
    + + +
    + <% if @category_print_not_add.length != 0 %> +
    + <%= hidden_field_tag :authenticity_token, form_authenticity_token %> +
    + <% 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} %> + + <%= render partial: 'print_format_explain' %> +
    +
    + <% else %> + <%= render partial: 'print_format_explain' %> + <% end %> + <% index1 = 0 %> + <% categories = []%> +
    + <% @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 %> + <%= name1.blank? ? "no name" : name1 %> + <% end %> + <% end %> +
    + <% index2 = 0 %> + <% @category_print_added.each_with_index do |category_print_added,index1| %> + <% if !categories[index1].nil? %> + <% index2 = index2 + 1 %> +
    " 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} %> + + +
    + <% end %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/admin/asks/print.html.erb b/app/views/admin/asks/print.html.erb new file mode 100644 index 0000000..633f50c --- /dev/null +++ b/app/views/admin/asks/print.html.erb @@ -0,0 +1,48 @@ + + +<%= javascript_include_tag "jspdf.min" %> + + +
    + +
    + \ No newline at end of file diff --git a/app/views/admin/asks/print_format_explain.html.erb b/app/views/admin/asks/print_format_explain.html.erb new file mode 100644 index 0000000..741693a --- /dev/null +++ b/app/views/admin/asks/print_format_explain.html.erb @@ -0,0 +1,126 @@ +<% trans = 'mongoid.attributes.ask_question' %> +
    + <%= t('ask.explanation') %>: +
    + {ask_time} -> <%= t('ask.ask_time') %> +
    + {title} -> <%= t('title') %> +
    + {category} -> <%= t("#{trans}.ask_category_id") %> +
    + {name} -> <%= t("#{trans}.name") %> +
    + {name|mask} -> <%= t("ask.name_mask") %> +
    + {sex} -> <%= t("#{trans}.sex") %> + (<%= t("#{trans}.male") %>/<%= t("#{trans}.female") %>) +
    + {mail} -> <%= t("#{trans}.mail") %> +
    + {phone} -> <%= t("#{trans}.phone") %> +
    + {appointment} -> <%= t("#{trans}.appointment") %> +
    + {agree_show} -> <%= t("#{trans}.agree_show_explain") %> +
    + {custom1} -> <%= t("ask.custom1") %> +
    + {custom2} -> <%= t("ask.custom2") %> +
    + {custom3} -> <%= t("ask.custom3") %> +
    + <%= t("ask.and_so_on") %> +
    + {custom} -><%= t("ask.custom_explain") %> +
    + {custom|format} -><%= t("ask.custom_format_explain") %> +
    + {?_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") %> +
    +
    + <%= t("ask.example") %>: +
    + <%= t("ask.example_explain") %> +
    + <%= t('ask.print_format') %>: +
    + + + + + + +
    <%= t("ask.example") %>
    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {title_title}{title}
    {category_title}{category}
    {name_title}{name}
    {mail_title}{mail}
    {custom_title}{custom}
    {custom1_title}{custom1}
    +
    +
    + <%= t('ask.output_result') %>: +
    + + + + + + +
    <%= t("ask.example") %>
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t('title') %>example
    <%= t("#{trans}.ask_category_id") %>測試
    <%= t("#{trans}.name") %>工程師1號
    <%= t("#{trans}.mail") %>test@rulingcom.com
    test2b
    test3c
    test1a
    +
    \ No newline at end of file diff --git a/app/views/admin/asks/print_setting.html.erb b/app/views/admin/asks/print_setting.html.erb new file mode 100644 index 0000000..c2a964f --- /dev/null +++ b/app/views/admin/asks/print_setting.html.erb @@ -0,0 +1,36 @@ +<%= form_for @set,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %> +
    + + + + + + + + + + + + + + + + + + + + +
    + <%= label_tag t('ask.save_name') %> + + <%= f.text_field :save_name %> +
    + <%= label_tag t('ask.print_format') %> + + <%= f.text_area :print_format,class: 'ckeditor' %> +
    + +
    +
    +<% end %> +<%= render partial: 'print_format_explain' %> \ No newline at end of file diff --git a/app/views/admin/asks/setting.html.erb b/app/views/admin/asks/setting.html.erb index c639523..1650f6a 100644 --- a/app/views/admin/asks/setting.html.erb +++ b/app/views/admin/asks/setting.html.erb @@ -1,89 +1,7 @@ <% set_input_name('ask_setting[custom_fields]') %> - - + <%= form_for @ask_setting,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %> -
    - - - - - - - - - <% @ask_setting.default_setting.each do |k,v| %> - - - - - <% end %> - <% @ask_setting.custom_fields.each do |k,v| %> - <%= custom_field_block(k,v).html_safe %> - <% end %> - - - - - - - -
    - <%= t('ask.field') %> - - <%= t('ask.whether_open') %> -
    - <%= t("mongoid.attributes.ask_question.#{k}") %> - - <%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %> -
    - -
    - <%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %> - <%= f.hidden_field :id, value: @ask_setting.id %> - -
    -
    + <%= render partial: 'ask_setting',locals:{ask_setting: @ask_setting,f: f,submit_text: t('submit')} %> <% end %> \ No newline at end of file diff --git a/app/views/asks/index.html.erb b/app/views/asks/index.html.erb index 4df2aae..45e62db 100644 --- a/app/views/asks/index.html.erb +++ b/app/views/asks/index.html.erb @@ -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 %>