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

162 lines
5.0 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;
}
td{
padding: 0.5em;
}
.tab-content{
display: none;
}
.tab-content.active{
display: block;
}
.tab-panel{
display: flex;
flex-wrap: wrap;
}
tr.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(-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)
%>
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 == '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').remove()
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.find('.disabled_field').val('true')
parent_div.hide()
}
</script>
<style type="text/css">
.border {
padding: 0.5em 0;
border-top: 0.1em solid #099700;
}
</style>
<% tmp_get_input_name = get_input_name
form_type = tmp_get_input_name.split('[')[0]
set_input_name("#{form_type}")
%>
<fieldset>
<table>
<thead>
<tr>
<th>
<%= t('ask.field') %>
</th>
<th>
<%= t('ask.whether_open') %>
</th>
<% if form_type=='ask_setting' %>
<th>
<%= t('ask.field_name') %>
</td>
<% end %>
</tr>
</thead>
<tbody>
<% locale = I18n.locale.to_s %>
<% ask_setting.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}[default_setting][#{k}]",options_for_select([[t('yes'),'true'],[t('no'),false]],v) %>
</td>
<% if form_type=='ask_setting' %>
<td>
<%= multiple_lang_tag(nil,'text_field',"default_setting_field_name][#{k}",ask_setting.field_name_translations(k),{placeholder: tmp}) %>
</td>
<% end %>
</tr>
<% end %>
<% set_input_name(tmp_get_input_name) %>
<tr>
<td>
<%= t("ask.usage_rule") %>
</td>
<td>
<%= 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 %>
<input class="btn btn-primary" type="submit" value="<%= submit_text %>">
</td>
</tr>
</tbody>
</table>
</fieldset>