2014-10-06 05:55:25 +00:00
|
|
|
<% # encoding: utf-8 %>
|
2017-03-03 13:00:52 +00:00
|
|
|
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
|
|
|
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
2014-10-06 05:55:25 +00:00
|
|
|
<%
|
|
|
|
data = action_data
|
|
|
|
@survey = data["survey"]
|
|
|
|
@questions = data["questions"]
|
|
|
|
@jump_tos_map = data["jump_tos_map"]
|
|
|
|
@answers = data["answers"]
|
2015-11-30 10:11:58 +00:00
|
|
|
answer_present = data['answer_present']
|
2014-10-06 05:55:25 +00:00
|
|
|
@redirect_url = data["redirect_url"]
|
|
|
|
%>
|
|
|
|
|
|
|
|
|
2015-11-27 11:55:47 +00:00
|
|
|
<% if @survey.needs_login && current_user.nil? %>
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.location.href = "<%= new_session_path %>";
|
|
|
|
</script>
|
2015-11-30 10:11:58 +00:00
|
|
|
<% elsif answer_present %>
|
|
|
|
<script type="text/javascript">
|
|
|
|
alert("Survey already taken.");
|
|
|
|
window.location.href = "<%= data['link_to_answer_set'] %>"
|
|
|
|
</script>
|
2015-11-27 11:55:47 +00:00
|
|
|
<% end %>
|
|
|
|
|
|
|
|
|
2014-10-06 05:55:25 +00:00
|
|
|
<% if !@redirect_url.blank? %>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.location.href = "<%= @redirect_url %>";
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<% else %>
|
|
|
|
|
|
|
|
<% unless @survey.deadline && Time.now > @survey.deadline %>
|
|
|
|
|
|
|
|
<div class="o-question">
|
2015-11-27 11:55:47 +00:00
|
|
|
<%= form_for :answer, :method => :put, :url => survey_path(@survey), :html => {:class => 'survey clear'} do |f| %>
|
2014-10-06 05:55:25 +00:00
|
|
|
<h3 class="o-question-topic"><%= @survey.title %></h3>
|
|
|
|
<div class="o-question-description">
|
|
|
|
<%= @survey.description %>
|
|
|
|
</div>
|
|
|
|
<ol class="o-question-list">
|
|
|
|
<% @questions.each_with_index do |question, i| %>
|
|
|
|
<li class="question-item question-<%= question.id.to_s %> hide" data-index="<%= i %>" data-type="<%= question.type%>" data-custom="<%= question.custom_option.to_s %>">
|
|
|
|
<% label = question.title %>
|
|
|
|
<% if question.is_required %>
|
|
|
|
<span class="required-star">(*)</span>
|
|
|
|
<% end %>
|
|
|
|
<%= f.label question.id, label, :class => "o-question-title" %>
|
|
|
|
<% if !question.description.blank? %>
|
|
|
|
<div class="o-question-description">
|
|
|
|
<%= question.description %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
<% case question.type %>
|
|
|
|
<% when SurveyQuestion::Oneline %>
|
|
|
|
<%= f.text_field question.id, :required => question.is_required %>
|
|
|
|
<% when SurveyQuestion::Multiline %>
|
|
|
|
<%= f.text_area question.id, :rows => 5, :required => question.is_required %>
|
|
|
|
<% when SurveyQuestion::Radio %>
|
|
|
|
<ul class="o-question-group view-list">
|
|
|
|
<% question.survey_question_options.each do |option| %>
|
|
|
|
<li>
|
|
|
|
<%= f.radio_button question.id, option.id %>
|
|
|
|
<%= f.label "#{question.id}_#{option.id}", option.name, :class => 'o-question-option' %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
<% if question.custom_option %>
|
|
|
|
<li>
|
|
|
|
<%= f.radio_button question.id, 'custom_option' %>
|
|
|
|
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :class => 'o-question-option' %>
|
|
|
|
<%= f.text_field "#{question.id}_custom_option" %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
2017-03-03 13:00:52 +00:00
|
|
|
<% when SurveyQuestion::DateTime %>
|
|
|
|
<%= f.datetime_picker question.id, :no_label => true, :new_record => true, :format => question.datetime_type, :placeholder => question.datetime_type.upcase, :required => question.is_required %>
|
2014-10-06 05:55:25 +00:00
|
|
|
<% when SurveyQuestion::Check %>
|
|
|
|
<ul class="o-question-group view-list">
|
|
|
|
<%= f.fields_for "#{question.id}" do |cf| %>
|
|
|
|
<% question.survey_question_options.each do |option| %>
|
|
|
|
<li>
|
|
|
|
<%= cf.check_box option.id %>
|
|
|
|
<%= cf.label option.id, option.name, :class => 'o-question-option' %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
<% if question.custom_option %>
|
|
|
|
<li>
|
|
|
|
<%= cf.check_box 'custom_option' %>
|
|
|
|
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :class => 'o-question-option' %>
|
|
|
|
<%= f.text_field "#{question.id}_custom_option" %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
</ul>
|
|
|
|
<% when SurveyQuestion::Select %>
|
|
|
|
<% options = question.survey_question_options.collect {|o| [ o.name, o.id ] } %>
|
|
|
|
<% if question.custom_option %>
|
|
|
|
<% options.push [t('survey_question.use_custom_option'), 'custom_option'] %>
|
|
|
|
<% end %>
|
|
|
|
<%= f.select question.id, options, {}, :class => 'o-question-group view-dropdown' %>
|
|
|
|
<% if question.custom_option %>
|
|
|
|
<%= f.text_field "#{question.id}_custom_option", :class => 'custom_option' %>
|
|
|
|
<% end %>
|
|
|
|
<% when SurveyQuestion::Radiogroup %>
|
|
|
|
<%= f.fields_for "#{question.id}" do |rgf| %>
|
|
|
|
<table class="o-question-group view-grid">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th></th>
|
2016-11-15 11:33:12 +00:00
|
|
|
<% if question.custom_option %>
|
|
|
|
<th></th>
|
|
|
|
<% end %>
|
2014-10-06 05:55:25 +00:00
|
|
|
<% question.survey_question_radiogroups.each do |radiogroup| %>
|
|
|
|
<th>
|
|
|
|
<%= radiogroup.name %>
|
|
|
|
</th>
|
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<% question.survey_question_options.each_with_index do |option, j| %>
|
|
|
|
<tr<%= (' class="odd"').html_safe if (j % 2 == 0) %>>
|
|
|
|
<th class="o-question-title">
|
|
|
|
<%= option.name %>
|
|
|
|
</th>
|
2016-11-15 11:33:12 +00:00
|
|
|
<% if question.custom_option %>
|
|
|
|
<%= f.fields_for "#{option.id}" do |oid| %>
|
|
|
|
<td>
|
|
|
|
<%= oid.text_field "custom_group_field" %>
|
|
|
|
</td>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
2014-10-06 05:55:25 +00:00
|
|
|
<% question.survey_question_radiogroups.each do |radiogroup| %>
|
|
|
|
<td>
|
|
|
|
<%= rgf.radio_button option.id, radiogroup.id %>
|
|
|
|
</td>
|
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
<% end %>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
</li>
|
|
|
|
<% end %>
|
|
|
|
</ol>
|
|
|
|
<div>
|
|
|
|
<%= f.submit t('submit'), :class => 'survey-submit' %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<%= stylesheet_link_tag "questionnaire" %>
|
|
|
|
|
|
|
|
<%= javascript_include_tag "lib/jquery.form"%>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2016-08-18 13:18:02 +00:00
|
|
|
|
2014-10-06 05:55:25 +00:00
|
|
|
<% if @survey.jump_mode %>
|
2016-11-15 11:33:12 +00:00
|
|
|
var answers = <%= @answers.to_json %>;
|
|
|
|
var jump_tos_map = <%= @jump_tos_map.to_json %>;
|
2014-10-06 05:55:25 +00:00
|
|
|
var $current_question = $('.question-item').eq(0);
|
|
|
|
var current_index = parseInt($current_question.attr('data-index'));
|
|
|
|
$current_question.removeClass('hide');
|
|
|
|
$('.survey-submit').click(function(){
|
|
|
|
$current_question.addClass('hide');
|
|
|
|
if ( $current_question.attr('data-type') == '<%= SurveyQuestion::Radio %>' || $current_question.attr('data-type') == '<%= SurveyQuestion::Select %>' ) {
|
|
|
|
if ( $current_question.attr('data-type') == '<%= SurveyQuestion::Radio %>' ) {
|
|
|
|
value = $current_question.find('input[type=radio]:checked').val();
|
|
|
|
} else if ( $current_question.attr('data-type') == '<%= SurveyQuestion::Select %>') {
|
|
|
|
value = $current_question.find('select option:selected').val();
|
|
|
|
}
|
|
|
|
if ( value == undefined ) {
|
|
|
|
alert("<%= t('survey.must_answer') %>");
|
|
|
|
} else {
|
|
|
|
jump_to = jump_tos_map[value];
|
|
|
|
if (jump_to == '1') {
|
|
|
|
return true;
|
|
|
|
} else if ( jump_to != '0' && jump_to != undefined ) {
|
|
|
|
$current_question = $('.question-item.question-' + jump_to);
|
|
|
|
} else {
|
|
|
|
$current_question = $('.question-item[data-index=' + (current_index + 1) + ']');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$current_question = $('.question-item[data-index=' + (current_index + 1) + ']');
|
|
|
|
}
|
|
|
|
if ( $current_question[0] ) {
|
|
|
|
$current_question.removeClass('hide');
|
|
|
|
current_index = parseInt($current_question.attr('data-index'));
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
<% else %>
|
|
|
|
$('.question-item').removeClass('hide');
|
|
|
|
<% end %>
|
|
|
|
$('.question-item[data-type=<%= SurveyQuestion::Select %>][data-custom=true]').each(function(){
|
|
|
|
$(this).change(function(){
|
|
|
|
if ( $(this).find('option:selected').val() == 'custom_option' ) {
|
|
|
|
$(this).find('input.custom_option').removeClass('hide');
|
|
|
|
} else {
|
|
|
|
$(this).find('input.custom_option').addClass('hide');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(this).trigger('change');
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<% else %>
|
|
|
|
|
|
|
|
the end
|
|
|
|
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
<% end %>
|