<% # encoding: utf-8 %> <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> <%= javascript_include_tag "survey-front-form" %> <% data = action_data @survey = data["survey"] @questions = data["questions"] @sections = @survey.survey_sections start_paginations = @survey.survey_paginations.pluck(:start_section) end_paginations = @survey.survey_paginations.pluck(:end_section) qnum_start = 1 qnums = [-1]*@questions.count s = 0 @sections.collect do |section| e = section.end_question mode = section.qnum_mode len = e-s case mode when 0 v = (qnum_start...(qnum_start+len)).to_a qnum_start += len when 1 v = [nil]*len when 2 qnum_start = len+1 v = (1..len).to_a end qnums[s,len] = v s = e end if qnums.index(-1) s = qnums.index(-1) e = @questions.count len = e-s qnum_start = qnums[0...s].compact[-1] + 1 rescue nil if qnum_start qnums[s,len] = (qnum_start...(qnum_start+len)).to_a else qnums[s,len] = (s+1..s+len).to_a end end headers = @survey.survey_sections.pluck(:start_question) footers = @survey.survey_sections.pluck(:end_question) @jump_tos_map = data["jump_tos_map"] @answers = data["answers"] answer_present = data['answer_present'] @redirect_url = data["redirect_url"] section_index_tmp = -1 section_index = "[other]" pagination_index = 0 qnum = 0 show_page_url = data["show_page_url"] %> <% if @survey.needs_login && current_user.nil? %> <% elsif answer_present %> <% end %> <% if !@redirect_url.blank? %> <% else %> <% unless @survey.deadline && Time.now > @survey.deadline %>
<%= form_for :answer, :method => :put, :url => survey_path(@survey), :html => {:class => 'survey clear'} do |f| %>

<%= @survey.title %>

<%= nl2br(@survey.description) %>
    <% if @survey.enable_consent_feature %>
  1. <% end %> <% end %> <% @questions.each_with_index do |question, i| %> <% header_count = i + 1 %> <% if headers.include?(header_count) %> <% section_index_tmp += 1 section_index = [section_index_tmp] %>
    <% section = @sections.where(:start_question => header_count).first %>
    <%= section.section_title %>
    <%= section.section_description %>
    <% end %>
  2. <% if question.is_selectable_radio %> <%= radio_button_tag "answer[select_question]#{section_index}[]", question.id, nil, :class=> 'question-checkbox' %> <% elsif question.is_selectable_check %> <%= check_box_tag "answer[select_question]#{section_index}[]", question.id, false, :class=> 'question-checkbox' %> <% end %> <%= qnums[i].nil? ? '' : "#{qnums[i]}. " %> <% label = question.title %> <% if question.is_required %> (*) <% end %> <%= f.label question.id, label, :class => "o-question-title" %> <% if !question.description.blank? %>
    <%= question.description %>
    <% 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 %> <% class_ul = question.layout_float ? ' float-left' : '' %> <%= content_tag :ul, :class => "o-question-group view-list#{class_ul}" do %> <% question.survey_question_options.each do |option| %>
  3. <%= f.radio_button question.id, option.id %> <%= f.label "#{question.id}_#{option.id}", option.name, :class => 'o-question-option' %> <% if question.custom_option_each_option %> <%= f.text_field "#{question.id}_#{option.id}_custom_option",placeholder: question.custom_option_title %> <% end %>
  4. <% end %> <% if question.custom_option_new_option %>
  5. <%= f.radio_button question.id, 'custom_option' %> <%= f.label "#{question.id}_custom_option", question.custom_option_title + ': ', :class => 'o-question-option custom_option' %> <%= f.text_field "#{question.id}_custom_option", class: 'custom_option_input' %>
  6. <% end %> <% end %> <% 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 %> <% when SurveyQuestion::Check %> <% class_ul = question.layout_float ? ' float-left' : '' %> <%= content_tag :ul, :class => "o-question-group view-list#{class_ul}" do %> <%= f.fields_for "#{question.id}" do |cf| %> <% question.survey_question_options.each do |option| %>
  7. <%= cf.check_box option.id %> <%= cf.label option.id, option.name, :class => 'o-question-option' %> <% if question.custom_option_each_option %> <%= f.text_field "#{question.id}_#{option.id}_custom_option",placeholder: question.custom_option_title %> <% end %>
  8. <% end %> <% if question.custom_option_new_option %>
  9. <%= cf.check_box 'custom_option' %> <%= f.label "#{question.id}_custom_option", question.custom_option_title + ': ', :class => 'o-question-option custom_option' %> <%= f.text_field "#{question.id}_custom_option", class: 'custom_option_input' %>
  10. <% end %> <% end %> <% end %> <% 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| %> <% if question.custom_option_each_option %> <% end %> <% question.survey_question_radiogroups.each do |radiogroup| %> <% end %> <% colspan = question.survey_question_radiogroups.count + (question.custom_option_each_option ? 1 : 0) + 1 %> <% question.survey_question_options.each_with_index do |option, j| %> > <% if question.custom_option_each_option %> <%= f.fields_for "#{option.id}" do |oid| %> <% end %> <% end %> <% question.survey_question_radiogroups.each do |radiogroup| %> <% end %> <% end %> <% if question.custom_option_new_option %> <% end %>
    <%= question.custom_option_title %> <%= radiogroup.name %>
    <%= option.name %> <%= oid.text_field "custom_group_field" %> <%= rgf.radio_button option.id, radiogroup.id %>
    <%= question.custom_option_title %>
    <%= f.text_area "#{question.id}_custom_option" %>
    <% end %> <% when SurveyQuestion::DoubleLevelOption %> <%= content_tag :table, :class => "o-question-group view-list double-level" do %> <% question.survey_question_options.each do |option| %> <%= f.label "#{question.id}_#{option.id}", :class => 'o-question-option' do %> <% if question.level1_radio %> <%= f.radio_button question.id, option.id, multiple: true %> <% elsif question.level1_check %> <%= f.check_box question.id, {multiple: true}, option.id, nil %> <% else %> <%= f.hidden_field question.id, :multiple => true, :value => option.id %> <% end %> <%= option.name %> <% end %> <% if option.level2.count>0 %> <% option.level2.each do |level2| %> <% end %> <% if question.custom_option_each_option %> <%= f.text_field "#{question.id}_#{option.id}_custom_option",placeholder: question.custom_option_title %> <% end %> <% end %> <% end %> <% if question.custom_option_new_option %> <% if question.level1_radio %> <%= f.radio_button question.id, 'custom_option', multiple: true %> <% elsif question.level1_check %> <%= f.check_box question.id, {multiple: true}, 'custom_option', nil %> <% else %> <%= f.hidden_field question.id, :multiple => true, :value => 'custom_option' %> <% end %> <%= f.label "#{question.id}_custom_option", question.custom_option_title + ': ', :class => 'o-question-option custom_option' %> <%= f.text_field "#{question.id}_custom_option", class: 'custom_option_input' %> <% end %> <% end %> <% end %> <% if (footers.include?(header_count) && end_paginations.include?(section_index_tmp+1)) || @questions.count == (i+1) %>
    <% pagination_index +=1 %> <% if pagination_index>1 %> <%= f.button t('survey.prev_page'), type: 'button', class: 'btn btn-success prev_page', 'data-pagination' => pagination_index-2 %> <% end %> <% if @questions.count != i+1 %> <%= f.button t('survey.next_page'), type: 'button', class: 'btn btn-success next_page', 'data-pagination' => pagination_index %> <% end %>
    <% end %> <% if footers.include?(header_count) %> <% section_index = "[other]" %>
    <% end %> <% end %>
<%= f.hidden_field_tag "show_page_url", show_page_url %> <%= f.submit t('submit'), :class => "survey-submit btn btn-primary#{' hide' if pagination_index>1 }" %>
<% end %>
<%= stylesheet_link_tag "questionnaire" %> <%= javascript_include_tag "lib/jquery.form"%> <% else %> the end <% end %> <% end %>