ask/app/views/admin/asks/_ask_setting.html.erb

385 lines
15 KiB
Plaintext
Raw Normal View History

2020-07-04 13:36:32 +00:00
<style type="text/css">
thead th {
2020-07-04 13:36:32 +00:00
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;
}
2022-05-20 05:18:25 +00:00
thead th:last-child{
text-align: left;
padding-left: 10em;
}
2022-05-20 05:27:27 +00:00
td.center:last-child {
padding-left: 0;
}
td:last-child {
text-align: left;
padding-left: 2.5em;
}
2020-07-04 13:36:32 +00:00
td{
padding: 0.5em;
}
.tab-content{
display: none;
}
.tab-content.active{
display: block;
}
.tab-panel{
display: flex;
flex-wrap: wrap;
}
2022-05-19 08:47:29 +00:00
.center .tab-panel{
2022-05-20 05:18:25 +00:00
justify-content: start;
2022-05-19 08:47:29 +00:00
}
tr.custom_field, tbody.custom_field {
2020-07-04 13:36:32 +00:00
border: 0.1em solid #8e00ff;
}
tr.custom_field > td >div {
padding: 0.5em 0;
}
input[type=text] {
height: 30px;
}
.small_sort_number{
width: 4em;
}
2020-07-04 13:36:32 +00:00
</style>
<script type="text/javascript">
<%
2022-09-21 10:07:01 +00:00
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)
2020-07-04 13:36:32 +00:00
%>
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');
2020-07-04 13:36:32 +00:00
}else{
parent_div.find('.prompt_word').removeClass('active');
2020-07-04 13:36:32 +00:00
}
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
parent_div.find('.add_new_options').addClass('active');
2020-07-04 13:36:32 +00:00
}else{
parent_div.find('.add_new_options').removeClass('active');
}
if (tmp == 'instructions'){
parent_div.find('.instructions_text_area').removeClass('hide');
parent_div.find('.prompt_word').removeClass('active');
}else{
parent_div.find('.instructions_text_area').addClass('hide');
parent_div.find('.prompt_word').addClass('active');
2020-07-04 13:36:32 +00:00
}
if (tmp == 'date'){
parent_div.find('.time_setting_block').addClass('active');
2020-07-04 13:36:32 +00:00
}else{
parent_div.find('.time_setting_block').removeClass('active');
2020-07-04 13:36:32 +00:00
}
}
function delete_field_func(ele){
$(ele).parents('tr').hide()
2020-07-04 13:36:32 +00:00
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')
2022-09-08 02:12:53 +00:00
parent_div.remove();
2020-07-04 13:36:32 +00:00
}
</script>
<style type="text/css">
.border {
padding: 0.5em 0;
border-top: 0.1em solid #099700;
}
</style>
2022-09-21 10:07:01 +00:00
<% tmp_get_input_name = get_input_name_for_ask
2022-03-09 17:00:05 +00:00
form_type = tmp_get_input_name.split('[')[0]
2022-09-22 07:28:34 +00:00
set_input_name_for_ask("#{form_type}")
2022-03-09 17:00:05 +00:00
%>
2020-07-04 13:36:32 +00:00
<fieldset>
<% if @has_switch_button %>
<div class="control-group">
<div class="control-label">
<a href="#" class="btn btn-danger cancel_edit" data-parent=".default_ask_setting"><%= t("ask.cancel_edit") %></a>
</div>
<div class="controls">
</div>
</div>
<% elsif form_type!= 'ask_setting' %>
<div class="control-group">
<div class="control-label">
<a href="#" class="btn btn-success switch_to_default" data-id="<%=f.object.id%>" data-use-default="true"><%= t("ask.use_default") %></a>
<%= hidden_field_tag "#{f.object_name}[use_default]", false %>
</div>
<div class="controls">
</div>
</div>
<% end %>
2022-05-21 13:47:42 +00:00
<div class="control-group">
<div class="control-label">
<label for="ask_title_layout"><%= t("ask.title_layout") %>:</label>
</div>
<div class="controls">
<%= f.select :title_layout, ['single_column','two_column'].each_with_index.map{|v,i| [t("ask.#{v}"), i]} %>
</div>
</div>
2022-04-12 14:17:34 +00:00
<% if @has_email_regex %>
<div class="control-group">
<div class="control-label">
<label for="ask_email_regex"><%= t("ask.email_regex") %>:</label>
</div>
<div class="controls">
<%= f.check_box :email_regex_enable, {:id=>"email_regex_enable"} %><%= t("ask.enable") %>
<div style="clear: both;"></div>
<%= f.text_field :email_regex, {:id=>"ask_email_regex", :style => "width: 30em;"}.merge(f.object.email_regex_enable ? {} : {:disabled=>"disabled"}) %>
</div>
</div>
<script>
$("#email_regex_enable").click(function(){
if($(this).prop("checked")){
$("#ask_email_regex").removeAttr("disabled");
}else{
$("#ask_email_regex").attr("disabled","disabled");
}
})
</script>
<% else %>
<div class="control-group">
<div class="control-label">
<%= t("ask.email_regex") %>:
</div>
<div class="controls">
<%= check_box_tag :email_regex_enable, @default_ask_setting.email_regex_enable , nil , {:id=>"",:disabled=>'disabled'} %><%= t("ask.enable") %>
<div style="clear: both;"></div>
<div class="show_field">
<%= @default_ask_setting.email_regex %>
</div>
</div>
</div>
2022-04-12 14:17:34 +00:00
<% end %>
2022-08-18 03:07:45 +00:00
<table class="table layoutfix_table">
2020-07-04 13:36:32 +00:00
<thead>
<tr>
<th>
2020-07-04 13:36:32 +00:00
<%= t('ask.field') %>
</th>
<th>
2020-07-04 13:36:32 +00:00
<%= t('ask.whether_open') %>
</th>
2022-03-09 17:00:05 +00:00
<% if form_type=='ask_setting' %>
<th>
2022-03-09 17:00:05 +00:00
<%= t('ask.field_name') %>
</th>
2022-08-18 03:07:45 +00:00
<th>
<%= t('ask.prompt_word') %>
</th>
2022-03-09 17:00:05 +00:00
<% end %>
<th>
<%= t('ask.required') %>
</th>
2020-07-04 13:36:32 +00:00
</tr>
</thead>
<tbody>
<% locale = I18n.locale.to_s %>
<%
default_setting = ask_setting.default_setting
if default_setting.keys[0].to_s != 'title'
default_setting = {title: true}.merge(default_setting)
end
%>
<% default_setting.each do |k,v| %>
2020-07-04 13:36:32 +00:00
<tr>
<td>
<%= tmp = (form_type=='ask_setting' ? ask_setting.default_field_name(k,locale, true) : @default_ask_setting.field_name(k,locale, true)) %>
2020-07-04 13:36:32 +00:00
</td>
<td>
2022-09-21 10:07:01 +00:00
<%= select_tag "#{get_input_name_for_ask}[default_setting][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
2020-07-04 13:36:32 +00:00
</td>
2022-03-09 17:00:05 +00:00
<% if form_type=='ask_setting' %>
2022-05-19 08:47:29 +00:00
<td class="center">
2022-03-09 17:00:05 +00:00
<%= multiple_lang_tag(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
</td>
2022-08-18 03:07:45 +00:00
<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}) %>
<% end %>
</td>
2022-03-09 17:00:05 +00:00
<% end %>
<% v = ask_setting.default_setting_required[k] %>
<td>
2022-09-21 10:07:01 +00:00
<%= select_tag "#{get_input_name_for_ask}[default_setting_required][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
2020-07-04 13:36:32 +00:00
</tr>
<% end %>
2022-09-21 10:07:01 +00:00
<% set_input_name_for_ask(tmp_get_input_name) %>
2020-07-04 13:36:32 +00:00
<tr>
<td>
<%= t("ask.usage_rule") %>
</td>
2022-05-20 05:18:25 +00:00
<td colspan="2">
2020-07-04 13:36:32 +00:00
<%= 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' } %>
<% if !ask_setting.new_record? %>
<%= f.hidden_field :id, value: ask_setting.id %>
<% end %>
2020-07-04 13:36:32 +00:00
<input class="btn btn-primary" type="submit" value="<%= submit_text %>">
</td>
</tr>
2022-08-18 03:07:45 +00:00
<% has_need_check_customs = (ask_setting.class == AskCategorySetting && (ask_setting.need_check_customs.count + ask_setting.reject_customs.count) != 0)
org_hide = ask_setting.class == AskCategorySetting ? (ask_setting.need_check_customs.count == 0) : true;
%>
<% if has_need_check_customs %>
<tr class="ask_setting_clone_fields">
<td colspan="2" style="text-align: center;">
<%= t('ask.default_custom_fields') %>
</td>
<td>
<span style="margin-right: 1em; font-weight: bold;" class="<%='hide' if ask_setting.reject_customs.count == 0 %>" id="display_discard_fields_block">
<input type="checkbox" id="display_discard_fields" style="float: left;">
<label for="display_discard_fields" style="float: left;"><%= t('ask.display_discard_fields') %></label>
</span>
<a class="apply_default_customs btn btn-success <%= 'hide' if org_hide %>" title="<%=t('ask.apply_all')%>" data-category="<%=ask_setting.category_id%>" data-apply-all="true"><%=t('ask.apply_all')%></a>
<a class="discard_default_customs btn btn-danger <%= 'hide' if org_hide %>" title="<%=t('ask.discard_changes')%>" data-category="<%=ask_setting.category_id%>" data-apply-all="true"><%=t('ask.discard_changes')%></a>
</td>
</tr>
<% end %>
2020-07-04 13:36:32 +00:00
</tbody>
2022-08-18 03:07:45 +00:00
<% if has_need_check_customs %>
<% (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 %>
<% 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 %>
<% end %>
<% end %>
<script>
var show_customs_count = <%= ask_setting.need_check_customs.count %>;
$(".apply_default_customs, .discard_default_customs").off('click').on('click', function(){
var _this = $(this);
var category = _this.data('category');
var apply_all = _this.attr('data-apply-all') == 'true';
var apply_fields = _this.data('apply-field');
apply_fields = apply_fields ? [apply_fields] : [];
var agree = _this.hasClass('apply_default_customs');
var hint_text = "";
if(agree){
hint_text = '<%=t("ask.are_you_sure_to_apply")%>';
}else{
hint_text = '<%=t("ask.are_you_sure_to_discard")%>';
}
var display_discard_fields = $('#display_discard_fields').prop('checked');
if(window.confirm(hint_text)){
$.post('<%=apply_default_custom_fields_admin_asks_path%>', {
category: category, apply_all: apply_all,
apply_fields: apply_fields, agree: agree,
include_reject: display_discard_fields
}).done(function(data){
var table = _this.parents('table.layoutfix_table');
if(data["success"]){
if(!agree){
$('#display_discard_fields_block').removeClass('hide');
}
table.find('tr.add_field').before(data['html']);
if(apply_all){
show_customs_count = 0;
var find_target = 'tbody.custom_field';
if(!display_discard_fields){
find_target += ":not(.discard_default_customs)";
}
if(agree){
table.find(find_target).remove();
_this.parents('tr.ask_setting_clone_fields').remove();
}else{
var tmp = 'discard_fields';
if(!display_discard_fields){
tmp += ' hide';
}
table.find(find_target).addClass(tmp);
table.find('.discard_default_customs').remove();
}
}else{
show_customs_count -= 1;
if(agree){
_this.parents('tbody.custom_field').remove();
if(table.find('tbody.custom_field').length == 0)
table.find('.ask_setting_clone_fields').remove();
}else{
var tmp = 'discard_fields';
if(!display_discard_fields){
tmp += ' hide';
}
_this.parents('tbody.custom_field').addClass(tmp);
_this.remove();
}
}
}
})
}
})
$('#display_discard_fields').off('click').on('click', function(){
if($(this).prop('checked')){
$('tbody.custom_field.discard_fields').removeClass('hide');
var can_display = '.apply_default_customs';
if(show_customs_count > 0){
can_display += ', .discard_default_customs';
}
$('tr.ask_setting_clone_fields').find(can_display).removeClass('hide');
}else{
$('tbody.custom_field.discard_fields').addClass('hide');
if(show_customs_count > 0){
$('tr.ask_setting_clone_fields').find('.apply_default_customs, .discard_default_customs').removeClass('hide');
}else{
$('tr.ask_setting_clone_fields').find('.apply_default_customs, .discard_default_customs').addClass('hide');
}
}
})
</script>
<% end %>
2020-07-04 13:36:32 +00:00
</table>
2022-08-18 03:07:45 +00:00
<style>
.layoutfix_table{
table-layout: fixed;
}
.layoutfix_table th,.layoutfix_table td {
word-wrap: break-word;
}
</style>
2020-07-04 13:36:32 +00:00
</fieldset>