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

145 lines
4.5 KiB
Plaintext

<%
set_input_name('ask_setting[custom_fields]')
%>
<style type="text/css">
thead td {
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;
}
</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("ask_setting[custom_fields][-1][options][-2][disabled]",nil,{'class' => 'disabled_field'}))
%>
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(/-2/g,tab_panel_length)
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()
}
function add_new_field(){
$.ajax({
url : "<%= get_new_setting_index_admin_asks_path %>",
dataType : "json",
type : "post",
error: function(){
alert('init process failed, please try again later.')
},
success: function(data){
var add_field_html = "<%= custom_field_block(-1).inspect %>"
add_field_html = add_field_html.replace(/-1/g,data['key'])
$('.add_field').before($('<div/>').html(add_field_html).text().slice(1,-2))
}
})
}
</script>
<%= form_for @ask_setting,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
<fieldset>
<table>
<thead>
<tr>
<td>
<%= t('ask.field') %>
</td>
<td>
<%= t('ask.whether_open') %>
</td>
</tr>
</thead>
<tbody>
<% @ask_setting.default_setting.each do |k,v| %>
<tr>
<td>
<%= t("mongoid.attributes.ask_question.#{k}") %>
</td>
<td>
<%= f.select "default_setting[#{k}]",[[t('yes'),'true'],[t('no'),false]] ,selected: v %>
</td>
</tr>
<% end %>
<% @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()">
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<%= hidden_field_tag :delete_field, nil,{'class'=> 'delete_field' } %>
<%= f.hidden_field :id, value: @ask_setting.id %>
<input class="btn btn-primary" type="submit" value="<%= t('submit')%>">
</td>
</tr>
</tbody>
</table>
</fieldset>
<% end %>