ask/app/views/asks/index.html.erb

297 lines
10 KiB
Plaintext

<% data = action_data
@ask_question = data["ask_question"]
@categories = data["categories"]
@tags = data["tags"]
@module_app = data["module_app"]
@switch_form = data["switch_form"]
ask_setting = data["ask_setting"]
set_input_name('ask_question')
%>
<% if data['layout_type'] != 'index' %>
<%= render template: "asks/#{data['layout_type']}",:locals => { :data => data, :ask_setting => ask_setting } %>
<% else %>
<style type="text/css">
#new-ask-question .form-horizontal .control-group > *{
font-size: 1.125em;
}
.default_picker label{
display: none;
}
.ask-question .control-group{
flex-wrap: wrap;
display: flex;
width: 100%;
align-items: center;
}
.ask-question .controls > *{
display: block;
}
.ask-question .controls > script{
display: none;
}
.ask-question .form-horizontal .control-label{
width: 24%;
max-width: 15em;
min-width: 7em;
padding: 0;
text-align: center;
}
.ask-question .form-horizontal .control-group .controls{
margin: 0;
display: inline-flex;
flex-wrap: wrap;
align-items: center;
overflow: hidden;
position: relative;
min-width: 10em;
max-width: 20em;
padding-left: 0;
width: 70%;
padding: 0.5em;
justify-content: center;
}
.ask-question .form-horizontal input[type="text"],.ask-question .form-horizontal select{
width: 97%;
max-width: 13.75em;
}
.ask-question .form-horizontal .form-actions{
position: relative;
padding: 1em 0 0 0;
text-align: center;
}
</style>
<%# javascript_include_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
<%# stylesheet_link_tag "/assets/lib/jquery-ui-1.12.1/jquery-ui.min" %>
<%= stylesheet_link_tag "custom_field" %>
<%# stylesheet_link_tag "jquery-ui-timepicker-addon" %>
<script type="text/javascript">
$(document).ready(function(){
$('select[name="ask_question[category_id]"]').change(function(){
var category_id = $(this).val()
$(this).parents('.ask-question').eq(0).find('select[name="ask_question[category_id]"]').val(category_id)
var id
if ($('form#'+category_id).length != 0){
id = category_id
}
else{
id = 'ask-default-form'
}
if (id != $(this).parents('form').eq(0).attr('id')){
$(this).parents('.ask-question').eq(0).find('form').hide()
$(this).parents('.ask-question').eq(0).find('form#'+id).show()
}
})
})
var datepicker_fn = $.fn.datepicker
var datepicker = $.datepicker
$(document).ready(function(){
$('input:file').change(function(e){
var fileName = e.target.files[0].name;
$(this).parents(".file-selector").eq(0).find('.filename').html(fileName);
})
})
</script>
<%# javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%# javascript_include_tag "jquery.ui.datepicker.monthyearpicker" %>
<%= javascript_include_tag 'validator' %>
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<div id="new-ask-question" class="ask-question">
<%= form_for @ask_question, url: asks_path, html: {class: 'form-horizontal',multipart: true} do |f| %>
<div class="control-group">
<%= f.label nil,t('title'), class: 'control-label required' %>
<div class="controls">
<%= f.text_field :title,placeholder: t('title'),required: true %>
</div>
</div>
<!-- Category -->
<% if ask_setting.default_setting['ask_category_id'] %>
<div class="control-group">
<%= f.label :ask_category_id, class: 'control-label required' %>
<div class="controls">
<% if @categories.count > 1 %>
<%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
<% else %>
<span>
<%= @categories[0].title rescue '' %>
</span>
<%= f.hidden_field :category_id, :value => (@categories[0].id.to_s rescue nil) %>
<% end %>
</div>
</div>
<% elsif @categories.count == 1 %>
<%= f.hidden_field :category_id, :value => (@categories[0].id.to_s rescue nil) %>
<% end %>
<!-- 姓名 -->
<% if ask_setting.default_setting['name'] %>
<div class="control-group">
<%= f.label :name, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :name, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
</div>
</div>
<% end %>
<!-- 性別 -->
<% if ask_setting.default_setting['sex'] %>
<div class="control-group">
<%= f.label :sex, class: 'control-label required' %>
<div class="controls">
<label class="radio-inline">
<%= f.radio_button :sex, "male" %><%= t('users.male')%>
</label>
<label class="radio-inline">
<%= f.radio_button :sex, "female" %><%= t('users.female')%>
</label>
</div>
</div>
<% end %>
<!-- 身分 -->
<!-- <div class="control-group">
<%# f.label :identity, class: 'control-label required' %>
<div class="controls">
<%# select_tag "ask_question[identity]", options_for_select(@tags.collect{|t| [ t.name, t.id ]}) if !@tags.nil? %>
</div>
</div> -->
<!-- Email -->
<div class="control-group">
<%= f.label :mail, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :mail, data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %>
</div>
</div>
<!-- 聯絡電話 -->
<% if ask_setting.default_setting['phone'] %>
<div class="control-group">
<%= f.label :phone, class: 'control-label' %>
<div class="controls">
<%= f.text_field :phone %>
</div>
</div>
<% end %>
<!-- 預約日期 -->
<% if ask_setting.default_setting['appointment'] %>
<div class="control-group">
<%= f.label :appointment, class: 'control-label' %>
<div class="controls">
<%= f.datetime_picker :appointment %>
</div>
</div>
<% end %>
<!-- 傳真 -->
<!-- <div class="control-group">
<%# f.label :fax, class: 'control-label' %>
<div class="controls">
<%# f.text_field :fax %>
</div>
</div> -->
<!-- 主旨 -->
<!-- <div class="control-group">
<%# f.label :title, class: 'control-label required' %>
<div class="controls">
<%# f.text_field :title, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
</div>
</div> -->
<!-- 內容 -->
<!-- <div class="control-group">
<%# f.label :content, class: 'control-label required' %>
<div class="controls">
<%# f.text_area :content, rows: 8, class: 'input-xlarge' %>
</div>
</div> -->
<!-- 驗證碼 -->
<%= ask_setting.custom_fields.collect do |k,v|
required_pattern = v['required']=='true' ? '*' : ''
"<div class=\"control-group\">
<label class=\"control-label\">#{required_pattern}#{v['field'][I18n.locale]}</label>
<div class=\"controls\">
#{show_on_front(k,v)}
</div>
</div>"
end.join.html_safe %>
<% if ask_setting.default_setting['recaptcha'] %>
<div class="control-group">
<%= f.label :recaptcha, class: 'control-label' %>
<div class="controls">
<%= gotcha_error %>
<%= gotcha %>
</div>
</div>
<% end %>
<% if !ask_setting.usage_rule.blank? %>
<div class="control-group">
<%= label_tag :usage_rule,t('ask.usage_rule'), class: 'control-label' %>
<div class="controls">
<%= ask_setting.usage_rule.html_safe %>
</div>
</div>
<% end %>
<% if ask_setting.default_setting['agree_usage'] %>
<div class="control-group">
<%= f.label :agree_usage, class: 'control-label' %>
<div class="controls">
<%= f.check_box :agree_usage %>
</div>
</div>
<% end %>
<% if ask_setting.default_setting['agree_show'] %>
<div class="control-group">
<%= f.label :agree_show, class: 'control-label' %>
<div class="controls">
<%= f.check_box :agree_show %>
</div>
</div>
<% end %>
<div class="form-actions">
<input type="hidden" name="referer_url" value="<%= request.original_url.split(request.env["HTTP_HOST"]).last %>">
<%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>
<% end %>
<%= @switch_form.html_safe %>
</div>
<script type='text/javascript'>
// $(function(){
// $("#button-mail").click(function(){
// if( $("#ask_question_name").val()!='' ) $("#ask_question_name").css('border','');
// if( $("#ask_question_email").val()!='' ) $("#ask_question_email").css('border','');
// if( $("#ask_question_title").val()!='' ) $("#ask_question_title").css('border','');
// if( $("#ask_question_content").val()!='' ) $("#ask_question_content").css('border','');
// if( $("#ask_question_name").val()=='' ) $("#ask_question_name").css('border','1px solid #F00');
// if( $("#ask_question_email").val()=='' ) $("#ask_question_email").css('border','1px solid #F00');
// if( $("#ask_question_title").val()=='' ) $("#ask_question_title").css('border','1px solid #F00');
// if( $("#ask_question_content").val()=='' ) $("#ask_question_content").css('border','1px solid #F00');
// });
$('.ask-question .required').each(function() {
var text = $(this).text()
if (text[0]!='*'){
$(this).text('*' + text);
}
});
// $('#new-ask-question form') .submit(function() {
// $.post($(this).attr('action'), $(this).serializeArray());
// return false;
// });
// });
$(function(){
var fv = new FormValidator($("#new_ask_question"));
fv.validate_functions.check_email = function(value){
reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
if (reg.test(value)) {
return true;
}else{
return false;
}
}
// fv.validate_functions.test_function = function(value, element){
// }
})
</script>
<% end %>