This commit is contained in:
BoHung Chiu 2022-09-22 16:06:12 +08:00
parent 177539cc39
commit 4ade4273e2
8 changed files with 39 additions and 40 deletions

View File

@ -18,7 +18,7 @@ class Admin::AsksController < OrbitAdminController
end
def print_setting
@set = nil
@cats_relations = get_categories_info
@cats_relations = get_categories_info_for_ask
@category_id = (params[:category] || @cats_relations[0][0] rescue nil)
if @category_id.blank?
@set = AskPrintSetting.first
@ -123,7 +123,7 @@ class Admin::AsksController < OrbitAdminController
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])
view_context.custom_field_block_for_ask("default@#{k}", custom_fields[k])
end.join("\n")
else
ask_setting.delete_customs_func(apply_fields, true)
@ -426,7 +426,7 @@ class Admin::AsksController < OrbitAdminController
@ask_question = AskQuestion.find(params[:id])
end
def order_fields
@cats_relations = get_categories_info
@cats_relations = get_categories_info_for_ask
@category_id = (params[:category] || @cats_relations[0][0] rescue nil)
@disp_fields_infos = AskSetting.get_disp_fields_infos(false,@category_id)
end

View File

@ -10,7 +10,7 @@ module Admin::AsksHelper
extend ActionView::Helpers::UrlHelper
extend OrbitFormHelper
extend Ckeditor::Helpers::FormHelper
def get_categories_info
def get_categories_info_for_ask
current_user = OrbitHelper.current_user
OrbitHelper.set_params(params,current_user)
OrbitHelper.set_this_module_app("ask")
@ -41,7 +41,7 @@ module Admin::AsksHelper
def get_input_name_for_ask
@input_name
end
def create_lang_panel(field)
def create_lang_panel_for_ask(field)
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
I18n.available_locales.collect do |key|
link_entry_ary = ["##{field}","_#{key}"]
@ -50,7 +50,7 @@ module Admin::AsksHelper
end.join.html_safe
end
end
def multiple_lang_show_tag(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false)
def multiple_lang_show_tag_for_ask(field_name, index1,field,value=nil,combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name_for_ask + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
@ -62,7 +62,7 @@ module Admin::AsksHelper
value_locale = value[locale.to_s] rescue nil
"<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
end.join + create_lang_panel_for_ask(all_field)).html_safe + combine_element
if sortable
if exteral_options['style'].nil?
@ -82,7 +82,7 @@ module Admin::AsksHelper
end
tmp = "<tr><td>#{field_name}".html_safe + ":</td><td>".html_safe + tmp + "</td></tr>".html_safe
end
def multiple_lang_tag(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
def multiple_lang_tag_for_ask(index1,type_of_tag,field,value=nil,custom_options={},combine_element='',exteral_options={},sortable=false)
if !index1.nil?
all_field = (get_input_name_for_ask + "[#{index1}][#{field}][parant]").gsub(/[\[@]/,'_').gsub(/\]/,'')
else
@ -98,7 +98,7 @@ module Admin::AsksHelper
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
end.join + create_lang_panel_for_ask(all_field)).html_safe + combine_element
if sortable
if exteral_options['style'].nil?
@ -123,8 +123,8 @@ module Admin::AsksHelper
range_selected = (value['type'] != 'date') ? nil : value['range_flag']
options1 = [['YYYY / MM / DD HH:mm','format1'],['YYYY / MM / DD','format2'],['YYYY / MM','format3'],['YYYY','format4']]
options2 = [[t('yes'),'true'],[t('no'),'false']]
format_setting_tag = field_select_tag(key,'format',options1,format_selected)
range_setting_tag = field_select_tag(key,'range_flag',options2,range_selected)
format_setting_tag = field_select_tag_for_ask(key,'format',options1,format_selected)
range_setting_tag = field_select_tag_for_ask(key,'range_flag',options2,range_selected)
"<div class=\"#{class_block}\">
<table>
<tbody>
@ -138,7 +138,7 @@ module Admin::AsksHelper
</table>
</div>"
end
def field_select_tag(index1,field,options,selected=nil,custom_options={})
def field_select_tag_for_ask(index1,field,options,selected=nil,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={})
@ -313,18 +313,18 @@ module Admin::AsksHelper
"<pre>#{e.inspect}<br>#{e.backtrace.to_yaml}</pre>"
end
end
def custom_field_block(k,v={},show_only=false, other_first_rows="",extra_class="")
def custom_field_block_for_ask(k,v={},show_only=false, other_first_rows="",extra_class="")
markups = LIST[:markups].select{|k,v| k != 'member_relationship' && k != 'address'}.collect{|key,val| [t("lists.markups."+key),key]} +[[t('ask.file_field'),'file'],[t('ask.image_field'),'image'],[t('ask.instructions'),'instructions']]
if show_only
multi_lang_tag = multiple_lang_show_tag(t('ask.field_name'),k,'field',v['field'])
multi_lang_tag = multiple_lang_show_tag_for_ask(t('ask.field_name'),k,'field',v['field'])
require_ask_tag = "<tr><td>#{t('ask.required')}:</td><td>#{v['required']=='true' ? t('ask.yes') : t('ask.no')}</td></tr>"
markups = markups.map{|k,v| [v,k]}.to_h
tmp = markups[v['type']]
tmp = markups.values[0] if tmp.nil?
field_select_tag = "<tr><td>#{t('ask.setting_type')}:</td><td><div id=\"#{get_input_name_for_ask}[#{k}][type]\">#{tmp}</div></td></tr>"
tmp_field_select_tag_for_ask = "<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'])
multi_lang_prompt_tag = multiple_lang_show_tag_for_ask(t('ask.prompt_word'),k,'prompt_word',v['prompt_word'])
field_html = "
<style>
.show_field {
@ -339,7 +339,7 @@ module Admin::AsksHelper
#{other_first_rows}
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}
#{tmp_field_select_tag_for_ask}
#{multi_lang_prompt_tag}
</tbody>"
else
@ -348,18 +348,18 @@ module Admin::AsksHelper
if not_editable
hint_text = "<div style=\"font-weight: bold;\">" + t('ask.this_field_is_default_custom_fields') + "</div>"
end
multi_lang_tag = multiple_lang_tag(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), disabled: (not_editable ? 'disabled' : nil)})
field_select_tag = field_select_tag(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)', :disabled=>(not_editable ? 'disabled' : nil)})
multi_lang_tag = multiple_lang_tag_for_ask(k,'text_field','field',v['field'],{placeholder: t('ask.field_name'), disabled: (not_editable ? 'disabled' : nil)})
tmp_field_select_tag_for_ask = field_select_tag_for_ask(k,'type',markups,v['type'],{:onchange=>'check_available_setting_block(this)', :disabled=>(not_editable ? 'disabled' : nil)})
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_for_ask}[#{k}][options][#{key}][disabled]",value['disabled'],{'class' => 'disabled_field'})
tmp = create_delete_button_for_ask('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)}"
"#{multiple_lang_tag_for_ask(k,'text_field',"options][#{key}",value,{placeholder: t('ask.option_name'), :disabled=>(not_editable ? 'disabled' : nil)},tmp,hidden_style,true)}"
end.join
active_class = ['select','radio_button','checkbox'].include?(v['type']) ? ' active' : ''
active_prompt_class = ['date','radio_button','checkbox'].exclude?(v['type']) ? ' active' : ''
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word'), disabled: (not_editable ? 'disabled' : nil)})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag(k,'text_area','instructions',v['instructions'],{placeholder: t('ask.prompt_word'), class: 'ckeditor', disabled: 'disabled'})}</div>"
multi_lang_prompt_tag = "<div class=\"prompt_word#{active_prompt_class}\">#{multiple_lang_tag_for_ask(k,'text_field','prompt_word',v['prompt_word'],{placeholder: t('ask.prompt_word'), disabled: (not_editable ? 'disabled' : nil)})}</div>"
instructions_text_area = "<div class=\"instructions_text_area#{v['type'] == 'instructions' ? '' : ' hide'}\">#{multiple_lang_tag_for_ask(k,'text_area','instructions',v['instructions'],{placeholder: t('ask.prompt_word'), class: 'ckeditor', disabled: 'disabled'})}</div>"
require_ask_tag = "<div>#{t('ask.required')}:&nbsp;&nbsp;#{field_radio_button_tag(k,'required','true',v['required']=='true',{disabled: (not_editable ? 'disabled' : nil)})}#{t('ask.yes')}#{field_radio_button_tag(k,'required','false',v['required']!='true',{disabled: (not_editable ? 'disabled' : nil)})}#{t('ask.no')}</div>"
tmp = "<div class=\"add_new_options#{active_class}\">#{all_new_options}<input class=\"btn btn-info\" type=\"button\" value=\"#{t('ask.add_new_options')}\" onclick=\"add_new_options_for_field(this,#{k})\"></div>"
field_html = "<tr class=\"custom_field #{extra_class}\" data-key=\"#{k}\">
@ -368,7 +368,7 @@ module Admin::AsksHelper
#{hint_text}
#{multi_lang_tag}
#{require_ask_tag}
#{field_select_tag}<br>
#{tmp_field_select_tag_for_ask}<br>
#{multi_lang_prompt_tag}
#{instructions_text_area}
#{time_setting_block(k,v)}
@ -376,12 +376,12 @@ module Admin::AsksHelper
#{key}
</td>
<td>
#{create_delete_button('delete_field_func')}
#{create_delete_button_for_ask('delete_field_func')}
</td>
</tr>"
end
end
def create_delete_button(func_name)
def create_delete_button_for_ask(func_name)
"<input class=\"btn btn-danger\" type=\"button\" value=\"#{t('delete_')}\" onclick=\"#{func_name}(this)\">"
end
def page_for_askquestion(askquestion)

View File

@ -75,7 +75,7 @@ class AskCategorySetting
end
def delete_customs_func(delete_custom_fields, add_to_reject=false)
if delete_custom_fields.count != 0
delete_custom_fields = delete_custom_fields.map{|f| f.sub('default@', '')}
delete_custom_fields = delete_custom_fields.map{|f| f.sub(/^default@/, '')}
self.need_check_customs -= delete_custom_fields
self.agree_customs -= delete_custom_fields
if add_to_reject
@ -84,7 +84,7 @@ class AskCategorySetting
else
self.reject_customs -= delete_custom_fields
delete_custom_fields.each do |f|
self.custom_fields.delete(f)
self.custom_fields.delete("default@#{f}")
end
end
@skip_callback = true

View File

@ -13,8 +13,7 @@
<%= form_for @ask_acknowledgements, url: @url, html: { class: 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :content, t('ask.acknowledgements'), class: 'control-label' %>
<%=
multiple_lang_tag(nil,'text_area','content',@ask_acknowledgements.content,{:class=>'ckeditor',placeholder: t('ask.acknowledgements'),rows:10},nil,{'class' => 'controls','style'=>'display: flex;flex-direction: column-reverse;'})
<%= multiple_lang_tag_for_ask(nil,'text_area','content',@ask_acknowledgements.content,{:class=>'ckeditor',placeholder: t('ask.acknowledgements'),rows:10},nil,{'class' => 'controls','style'=>'display: flex;flex-direction: column-reverse;'})
%>
</div>
<div class="form-actions">

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_for_ask}[-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}),{},true)
option_multi_lang_tag = multiple_lang_tag_for_ask(-1,'text_field','options][-2',nil,{placeholder: t('ask.option_name')},create_delete_button_for_ask('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()
@ -219,13 +219,13 @@
</td>
<% if form_type=='ask_setting' %>
<td class="center">
<%= multiple_lang_tag(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
<%= multiple_lang_tag_for_ask(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
</td>
<td class="center">
<% if AskSetting::No_prompt_word.include?(k) %>
<%= t('ask.the_same_as_field_name') %>
<% else %>
<%= multiple_lang_tag(nil,'text_field',"default_setting_prompt_word][#{k}",ask_setting.prompt_word_translations(k),{placeholder: tmp}) %>
<%= multiple_lang_tag_for_ask(nil,'text_field',"default_setting_prompt_word][#{k}",ask_setting.prompt_word_translations(k),{placeholder: tmp}) %>
<% end %>
</td>
<% end %>
@ -245,7 +245,7 @@
</td>
</tr>
<% ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block(k,v).html_safe %>
<%= custom_field_block_for_ask(k,v).html_safe %>
<% end %>
<tr class="add_field">
<td colspan="2" style="text-align: center;">
@ -284,10 +284,10 @@
<% (ask_setting.need_check_customs + ask_setting.reject_customs).sort_by{|k| k.to_i}.each do |k| %>
<% if ask_setting.reject_customs.include?(k) %>
<% other_first_rows = "<tr><td colspan=\"2\"><a class=\"apply_default_customs btn btn-success\" title=\"#{t('ask.apply')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.apply')}</a></td></tr>" %>
<%= custom_field_block(k, @default_ask_setting.custom_fields[k], true, other_first_rows, "discard_fields hide").html_safe %>
<%= custom_field_block_for_ask(k, @default_ask_setting.custom_fields[k], true, other_first_rows, "discard_fields hide").html_safe %>
<% else %>
<% other_first_rows = "<tr><td colspan=\"2\"><a class=\"apply_default_customs btn btn-success\" title=\"#{t('ask.apply')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.apply')}</a><a class=\"discard_default_customs btn btn-danger\" title=\"#{t('ask.discard')}\" data-category=\"#{ask_setting.category_id}\" data-apply-field=\"#{k}\">#{t('ask.discard')}</a></td></tr>" %>
<%= custom_field_block(k, @default_ask_setting.custom_fields[k], true, other_first_rows).html_safe %>
<%= custom_field_block_for_ask(k, @default_ask_setting.custom_fields[k], true, other_first_rows).html_safe %>
<% end %>
<% end %>
<script>

View File

@ -71,7 +71,7 @@
</tr>
</tbody>
<% @default_ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block(k,v,true).html_safe %>
<%= custom_field_block_for_ask(k,v,true).html_safe %>
<% end %>
</table>
</fieldset>

View File

@ -186,7 +186,7 @@
%>
<script type="text/javascript">
function add_new_field(ele){
var category_id = $(ele).parents('form').eq(0).data('cat-id')
var category_id = window.ask_cateogry_id;
$.ajax({
url : "<%= "/#{I18n.locale}/admin/asks/get_new_category_setting_index" %>",
dataType : "json",
@ -196,7 +196,7 @@
alert('init process failed, please try again later.')
},
success: function(data){
var add_field_html = "<%= custom_field_block(-1).inspect %>"
var add_field_html = "<%= custom_field_block_for_ask(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
var add_field = $(ele).parents('.add_field');
add_field.before($('<div/>').html(add_field_html).text().slice(1,-2))

View File

@ -11,7 +11,7 @@
alert('init process failed, please try again later.')
},
success: function(data){
var add_field_html = "<%= custom_field_block(-1).inspect %>"
var add_field_html = "<%= custom_field_block_for_ask(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$(ele).parents('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
var new_item = add_field.prev();