This commit is contained in:
BoHung Chiu 2022-09-21 18:07:01 +08:00
parent 6d1b494a4a
commit 850ac0e318
13 changed files with 37 additions and 36 deletions

View File

@ -120,8 +120,8 @@ class Admin::AsksController < OrbitAdminController
if is_agree
ask_setting.agree_customs_func(apply_fields)
custom_fields = AskSetting.first.custom_fields
set_input_name('ask_category_setting[custom_fields]')
view_context.set_input_name('ask_category_setting[custom_fields]') #prevent not setting variables
set_input_name_for_ask('ask_category_setting[custom_fields]')
view_context.set_input_name_for_ask('ask_category_setting[custom_fields]') #prevent not setting variables
html = apply_fields.map do |k|
view_context.custom_field_block("default@#{k}", custom_fields[k])
end.join("\n")

View File

@ -6,6 +6,7 @@ class AsksController < ApplicationController
helper ActionView::Helpers::UrlHelper
include ActionController::RequestForgeryProtection
include RuCaptcha::ViewHelpers
FrontendMethods = ["thank", "sorry"]
def widget
subpart = OrbitHelper.get_current_widget
case subpart.widget_type
@ -335,7 +336,7 @@ class AsksController < ApplicationController
defalt_fields = []
tmp_type = (ask_setting.class == AskSetting) ? 0 : 1
tmp_ask_cat_id = (tmp_type == 1) ? ask_setting.id.to_s : ""
set_input_name("ask_question")
set_input_name_for_ask("ask_question")
disp_fields_infos.each do |field, info|
if field.start_with?("default@")
k = field[8..-1]

View File

@ -35,10 +35,10 @@ module Admin::AsksHelper
end
cats_relations
end
def set_input_name(input_name)
def set_input_name_for_ask(input_name)
@input_name = input_name
end
def get_input_name
def get_input_name_for_ask
@input_name
end
def create_lang_panel(field)
@ -52,15 +52,15 @@ module Admin::AsksHelper
end
def multiple_lang_show_tag(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
all_field = (get_input_name_for_ask + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
all_field = (get_input_name_for_ask + "[#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
end
tmp = (I18n.available_locales.collect do |locale|
active_flag = ((locale == I18n.locale) ? ' active' : '')
content_tag(:div,:class => "tab-content#{active_flag}",:id=>"#{all_field}_#{locale}") do
value_locale = value[locale.to_s] rescue nil
"<div class=\"show_field\" id=\"#{index1 ? "#{get_input_name}[#{index1}][#{field}][#{locale}]" : "#{get_input_name}[#{field}][#{locale}]"}\">#{value_locale}</div>".html_safe
"<div class=\"show_field\" id=\"#{index1 ? "#{get_input_name_for_ask}[#{index1}][#{field}][#{locale}]" : "#{get_input_name_for_ask}[#{field}][#{locale}]"}\">#{value_locale}</div>".html_safe
end
end.join + create_lang_panel(all_field)).html_safe + combine_element
@ -84,18 +84,18 @@ module Admin::AsksHelper
end
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
all_field = (get_input_name_for_ask + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
all_field = (get_input_name + "[#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
all_field = (get_input_name_for_ask + "[#{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)
self.__send__("#{type_of_tag}_tag","#{get_input_name_for_ask}[#{index1}][#{field}][#{locale}]",value_locale,custom_options)
else
self.__send__("#{type_of_tag}_tag","#{get_input_name}[#{field}][#{locale}]",value_locale,custom_options)
self.__send__("#{type_of_tag}_tag","#{get_input_name_for_ask}[#{field}][#{locale}]",value_locale,custom_options)
end
end
end.join + create_lang_panel(all_field)).html_safe + combine_element
@ -139,10 +139,10 @@ module Admin::AsksHelper
</div>"
end
def field_select_tag(index1,field,options,selected=nil,custom_options={})
select_tag("#{get_input_name}[#{index1}][#{field}]",options_for_select(options,selected: selected),custom_options)
select_tag("#{get_input_name_for_ask}[#{index1}][#{field}]",options_for_select(options,selected: selected),custom_options)
end
def field_radio_button_tag(index1,field,show_value,checked,custom_options={})
radio_button_tag("#{get_input_name}[#{index1}][#{field}]",show_value,checked,custom_options)
radio_button_tag("#{get_input_name_for_ask}[#{index1}][#{field}]",show_value,checked,custom_options)
end
def render_date_block(field_name,v,i,value)
case v['format']
@ -208,7 +208,7 @@ module Admin::AsksHelper
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}]"
field_name = "#{get_input_name_for_ask}[custom_values][#{k}]"
begin
case v['type']
when 'text_field'
@ -321,7 +321,7 @@ module Admin::AsksHelper
markups = markups.map{|k,v| [v,k]}.to_h
tmp = markups[v['type']]
tmp = markups.values[0] if tmp.nil?
field_select_tag = "<tr><td>#{t('ask.setting_type')}:</td><td><div id=\"#{get_input_name}[#{k}][type]\">#{tmp}</div></td></tr>"
field_select_tag = "<tr><td>#{t('ask.setting_type')}:</td><td><div id=\"#{get_input_name_for_ask}[#{k}][type]\">#{tmp}</div></td></tr>"
active_prompt_class = ['date','radio_button','checkbox'].exclude?(v['type']) ? ' active' : ''
active_class = ['select','radio_button','checkbox'].include?(v['type']) ? ' active' : ''
multi_lang_prompt_tag = multiple_lang_show_tag(t('ask.prompt_word'),k,'prompt_word',v['prompt_word'])
@ -350,9 +350,9 @@ module Admin::AsksHelper
end
multi_lang_tag = multiple_lang_tag(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), disabled: (not_editable ? 'disabled' : nil)})
field_select_tag = field_select_tag(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)', :disabled=>(not_editable ? 'disabled' : nil)})
key = hidden_field_tag "#{get_input_name}[#{k}][key]",k,{'class' => 'key'}
key = hidden_field_tag "#{get_input_name_for_ask}[#{k}][key]",k,{'class' => 'key'}
all_new_options = Array(v['options']).collect do |key,value|
tmp = create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name}[#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
tmp = create_delete_button('delete_added_select_option').html_safe+hidden_field_tag("#{get_input_name_for_ask}[#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
hidden_style = value['disabled'] == 'true' ? {style: 'display:none;'} : {}
"#{multiple_lang_tag(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name'), :disabled=>(not_editable ? 'disabled' : nil)},tmp,hidden_style,true)}"
end.join

View File

@ -126,9 +126,9 @@ class AskCategorySetting
field :default_setting_prompt_word, type: Hash,default: {}
field :use_default, type: Boolean, default: false
field :custom_fields, type: Hash,default: {}
field :usage_rule
field :usage_rule, type: String, default: ''
field :category_id
field :title_layout, type: Integer
field :title_layout, type: Integer, default: 0
field :email_regex_enable, type: Boolean, default: false
field :email_regex, type: String, default: '\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z'
field :need_check_customs, type: Array, default: [] #From AskSetting

View File

@ -89,9 +89,9 @@ class AskSetting
field :default_setting_field_name, type: Hash,default: {}
field :default_setting_prompt_word, type: Hash,default: {}
field :custom_fields, type: Hash,default: {}
field :usage_rule
field :title_layout, type: Integer
field :custom_fields, type: Hash, default: {}
field :usage_rule, type: String, default: ''
field :title_layout, type: Integer, default: 0
field :last_ticket_key, type: Integer, default: 0
field :last_serial_number, type: Integer, default: 0
def get_attrs

View File

@ -1,5 +1,5 @@
<%
set_input_name('ask_acknowledgement')
set_input_name_for_ask('ask_acknowledgement')
%>
<style type="text/css">
.tab-content{

View File

@ -58,7 +58,7 @@
</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)
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_for_ask}[-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}),{},true)
%>
function check_available_setting_block(ele){
var tmp = $(ele).val()
@ -114,9 +114,9 @@
border-top: 0.1em solid #099700;
}
</style>
<% tmp_get_input_name = get_input_name
<% tmp_get_input_name = get_input_name_for_ask
form_type = tmp_get_input_name.split('[')[0]
set_input_name("#{form_type}")
# set_input_name_for_ask("#{form_type}")
%>
<fieldset>
<% if @has_switch_button %>
@ -215,7 +215,7 @@
<%= tmp = (form_type=='ask_setting' ? ask_setting.default_field_name(k,locale, true) : @default_ask_setting.field_name(k,locale, true)) %>
</td>
<td>
<%= select_tag "#{get_input_name}[default_setting][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
<%= select_tag "#{get_input_name_for_ask}[default_setting][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
<% if form_type=='ask_setting' %>
<td class="center">
@ -231,11 +231,11 @@
<% end %>
<% v = ask_setting.default_setting_required[k] %>
<td>
<%= select_tag "#{get_input_name}[default_setting_required][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
<%= select_tag "#{get_input_name_for_ask}[default_setting_required][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
</tr>
<% end %>
<% set_input_name(tmp_get_input_name) %>
<% set_input_name_for_ask(tmp_get_input_name) %>
<tr>
<td>
<%= t("ask.usage_rule") %>

View File

@ -1,5 +1,5 @@
<%
set_input_name('ask_category_setting[custom_fields]')
set_input_name_for_ask('ask_category_setting[custom_fields]')
%>
<%= form_for ask_setting,method: 'post',url: category_setting_save_admin_asks_path ,html: { class: "form-horizontal fade-in active detail", 'id' => ask_setting.id.to_s ,:id => ask_setting.id} do |f| %>
<%= render partial: 'ask_setting',locals:{ask_setting: ask_setting,f: f,submit_text: t('ask.modify')} %>

View File

@ -1,6 +1,6 @@
<%
ask_setting = @ask_setting
set_input_name('ask_question')
set_input_name_for_ask('ask_question')
%>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>

View File

@ -66,7 +66,7 @@
<%= t("ask.usage_rule") %>
</td>
<td colspan="2">
<%= @default_ask_setting.usage_rule.html_safe %>
<%= @default_ask_setting.usage_rule.to_s.html_safe %>
</td>
</tr>
</tbody>

View File

@ -182,7 +182,7 @@
}
</style>
<%
set_input_name('ask_category_setting[custom_fields]')
set_input_name_for_ask('ask_category_setting[custom_fields]')
%>
<script type="text/javascript">
function add_new_field(ele){

View File

@ -1,5 +1,5 @@
<%
set_input_name('ask_setting[custom_fields]')
set_input_name_for_ask('ask_setting[custom_fields]')
%>
<script>
function add_new_field(ele){

View File

@ -5,7 +5,7 @@
@module_app = data["module_app"]
@switch_form = data["switch_form"]
ask_setting = data["ask_setting"]
set_input_name('ask_question')
set_input_name_for_ask('ask_question')
@default_ask_setting = data['default_ask_setting']
email_regex = data['email_regex']
%>