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

385 lines
15 KiB
Plaintext

<style type="text/css">
thead th {
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;
}
thead th:last-child{
text-align: left;
padding-left: 10em;
}
td.center:last-child {
padding-left: 0;
}
td:last-child {
text-align: left;
padding-left: 2.5em;
}
td{
padding: 0.5em;
}
.tab-content{
display: none;
}
.tab-content.active{
display: block;
}
.tab-panel{
display: flex;
flex-wrap: wrap;
}
.center .tab-panel{
justify-content: start;
}
tr.custom_field, tbody.custom_field {
border: 0.1em solid #8e00ff;
}
tr.custom_field > td >div {
padding: 0.5em 0;
}
input[type=text] {
height: 30px;
}
.small_sort_number{
width: 4em;
}
</style>
<script type="text/javascript">
<%
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()
var parent_div = $(ele).parents('.custom_field').eq(0)
if (tmp != 'date' && tmp != 'radio_button' && tmp!='checkbox'){
parent_div.find('.prompt_word').addClass('active');
}else{
parent_div.find('.prompt_word').removeClass('active');
}
if (tmp == 'select' || tmp == 'radio_button' || tmp=='checkbox'){
parent_div.find('.add_new_options').addClass('active');
}else{
parent_div.find('.add_new_options').removeClass('active');
}
if (tmp == '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');
}
if (tmp == 'date'){
parent_div.find('.time_setting_block').addClass('active');
}else{
parent_div.find('.time_setting_block').removeClass('active');
}
}
function delete_field_func(ele){
$(ele).parents('tr').hide()
var all_delete_field = $('.delete_field').val()
all_delete_field = all_delete_field + ',' + $(ele).parents('tr').find('.key').val()
$('.delete_field').val(all_delete_field)
}
function add_new_options_for_field(ele,key){
var add_html = "<%= option_multi_lang_tag.inspect %>"
add_html = add_html.replace(/-1/g,key)
var parent_div = $(ele).parents('.add_new_options')
var tab_panel = parent_div.eq(0).find('.tab-panel')
var tab_panel_length = tab_panel.length
add_html = add_html.replace(/icons-list-2/g,'icons-list-3')
add_html = add_html.replace(/-2/g,tab_panel_length)
add_html = add_html.replace(/icons-list-3/g,'icons-list-2')
parent_div.find('input[type="button"]').eq(-1).before($('<div/>').html(add_html).text().slice(1,-2))
}
function delete_added_select_option(ele){
var parent_div = $(ele).parents('.tab-panel')
parent_div.remove();
}
</script>
<style type="text/css">
.border {
padding: 0.5em 0;
border-top: 0.1em solid #099700;
}
</style>
<% tmp_get_input_name = get_input_name_for_ask
form_type = tmp_get_input_name.split('[')[0]
set_input_name_for_ask("#{form_type}")
%>
<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 %>
<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>
<% 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>
<% end %>
<table class="table layoutfix_table">
<thead>
<tr>
<th>
<%= t('ask.field') %>
</th>
<th>
<%= t('ask.whether_open') %>
</th>
<% if form_type=='ask_setting' %>
<th>
<%= t('ask.field_name') %>
</th>
<th>
<%= t('ask.prompt_word') %>
</th>
<% end %>
<th>
<%= t('ask.required') %>
</th>
</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| %>
<tr>
<td>
<%= 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_for_ask}[default_setting][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
<% if form_type=='ask_setting' %>
<td class="center">
<%= 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_for_ask(nil,'text_field',"default_setting_prompt_word][#{k}",ask_setting.prompt_word_translations(k),{placeholder: tmp}) %>
<% end %>
</td>
<% end %>
<% v = ask_setting.default_setting_required[k] %>
<td>
<%= 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_for_ask(tmp_get_input_name) %>
<tr>
<td>
<%= t("ask.usage_rule") %>
</td>
<td colspan="2">
<%= f.text_area "usage_rule",class: 'ckeditor' %>
</td>
</tr>
<% ask_setting.custom_fields.each do |k,v| %>
<%= custom_field_block_for_ask(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 %>
<input class="btn btn-primary" type="submit" value="<%= submit_text %>">
</td>
</tr>
<% 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 %>
</tbody>
<% 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_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_for_ask(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 %>
</table>
<style>
.layoutfix_table{
table-layout: fixed;
}
.layoutfix_table th,.layoutfix_table td {
word-wrap: break-word;
}
</style>
</fieldset>