Conflicts:

	vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/show.html.erb
This commit is contained in:
iCross 2013-05-20 17:16:06 +08:00
parent 531cee70d2
commit 7ba0977e16
8 changed files with 147 additions and 108 deletions

View File

@ -10,13 +10,18 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
end
def show
redirect_standalone panel_survey_front_end_survey_path(params[:id], :standalone => 'true') do
@survey = ::Survey.find params[:id]
@questions = @survey.survey_questions.all
if @survey.jump_mode
@jumpable_questions = @questions.all.select{ |q| q.jumpable? && q.can_set_jump? }
@survey = ::Survey.find params[:id]
if @survey.redirect_mode
@redirect_url = @survey.redirect_url
render :redirect_standalone
else
redirect_standalone panel_survey_front_end_survey_path(params[:id], :standalone => 'true') do
@questions = @survey.survey_questions.all
if @survey.jump_mode
@jumpable_questions = @questions.all.select{ |q| q.jumpable? && q.can_set_jump? }
@jump_tos_map = @jumpable_questions.map(&:get_jump_tos).inject(:merge)
@jump_tos_map = @jumpable_questions.map(&:get_jump_tos).inject(:merge)
end
end
end
end

View File

@ -29,6 +29,9 @@ class Survey
field :jump_mode, :type => Boolean, :default => false
field :redirect_mode, :type => Boolean, :default => false
field :redirect_url, :type => String
validates :title, :at_least_one => true
has_many :survey_questions, :autosave => true, :dependent => :destroy

View File

@ -18,6 +18,22 @@
</div>
</div>
</div>
<div id="widget-redirect" class="widget-box widget-size-300">
<div class="widget-action clear tip">
<a href="#" class="action"><i class="icon-exclamation-sign icon-white"></i></a>
</div>
<h3 class="widget-title"><i class="icons-calendar"></i><%= t('survey.redirect') %></h3>
<div class="widget-content clear">
<div class="control-group">
<%= f.label :redirect_mode, t('survey.redirect_mode')%>
<%= f.check_box :redirect_mode %>
</div>
<div class="control-group">
<%= f.label :redirect_url, t('survey.redirect_url') %>
<%= f.text_field :redirect_url %>
</div>
</div>
</div>
</div>
<div id="post-body">

View File

@ -13,7 +13,6 @@
<li><%= link_to t('survey.duplicate_it'), duplicate_it_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
<li><%= link_to t('survey.jump'), jump_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
<li><%= link_to t('survey.set_answers'), set_answers_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
<li><%= link_to t('survey.answers_list'), panel_survey_back_end_survey_answers_path(survey, :page => params[:page]) %></li>
<li><%= link_to t('survey.export_csv'), export_panel_survey_back_end_survey_path(survey, :format => :csv), :target => '_blank' %></li>
<li><%= link_to t('survey.chart'), result_panel_survey_front_end_survey_path(survey, :force_chart => true, :standalone => true), :target => '_blank' %></li>
<li><%= link_to t(:delete_), panel_survey_back_end_survey_path(survey), :confirm => t('sure?'), :method => :delete, :remote => true %></li>

View File

@ -6,7 +6,7 @@
<section>
<div class="o-question">
<div class="o-question-description">
<%= t 'survey.results_count' %>: <%= @survey_questions.count %>
<%= t 'survey.results_count' %>: <%= @survey.survey_answers.count %>
</div>
<ol class="o-question-list">
<% @survey_questions.each do |question| %>

View File

@ -1,109 +1,117 @@
<% # encoding: utf-8 %>
<h1><%= @survey.title %></h1>
<div>
<section>
<div class="o-question">
<%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :inner => true), :html => {:class => 'clear'} do |f| %>
<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 %>
<% label += ' (' + t('survey_question.required') + ')' if question.is_required %>
<%= f.label question.id, label, :class => "o-question-title" %>
<div class="o-question-description">
<%= question.description %>
</div>
<% 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 %>
<% question.survey_question_options.each do |option| %>
<p>
<%= f.radio_button question.id, option.id %>
<%= f.label "#{question.id}_#{option.id}", option.name, :style => "display:inline" %>
</p>
<% end %>
<% if question.custom_option %>
<p>
<%= f.radio_button question.id, 'custom_option' %>
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %>
<%= f.text_field "#{question.id}_custom_option" %>
</p>
<% end %>
<% when ::SurveyQuestion::Check %>
<%= f.fields_for "#{question.id}" do |cf| %>
<% question.survey_question_options.each do |option| %>
<p>
<%= cf.check_box option.id %>
<%= cf.label option.id, option.name, :style => "display:inline" %>
</p>
<% end %>
<% if question.custom_option %>
<p>
<%= cf.check_box 'custom_option' %>
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %>
<%= f.text_field "#{question.id}_custom_option" %>
</p>
<% 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 %>
<% 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>
<% 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>
<% 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 class="o-question-action">
<%= f.submit t('submit'), :class => 'survey-submit' %>
</div>
<% end %>
</div>
</section>
<div class="o-question">
<%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :standalone => true), :html => {:class => 'survey clear'} do |f| %>
<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 %>
<% label += ' (*)' if question.is_required %>
<%= f.label question.id, label, :class => "o-question-title" %>
<div class="o-question-description">
<%= question.description %>
</div>
<% 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>
<% 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>
<% 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>
<% 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 class="o-question-action">
<%= f.submit t('submit'), :class => 'survey-submit' %>
</div>
<% end %>
</div>
<% content_for :page_stylesheets do %>
<link href='/assets/questionnaire.css' rel='stylesheet' type='text/css' />
<% end %>
<script type="text/javascript" src="/assets/jquery.form.js"></script>
<script type="text/javascript">
$('form.survey').ajaxForm({
beforeSubmit: function(a,f,o) {
o.dataType = 'script';
},
success: function(data) {
}
});
<% if @survey.jump_mode %>
var jump_tos_map = <%== @jump_tos_map.to_json %>;
var $current_question = $('.question-item').eq(0);

View File

@ -36,6 +36,10 @@ en:
not_jump: Not Jump
jump_to_end: End of Survey
redirect: Redirect
redirect_mode: Redirect Mode
redirect_url: Redirect Url
must_answer: Must be Answered
default_widget:

View File

@ -37,6 +37,10 @@ zh_tw:
not_jump: 依據試卷列出所有問題數
jump_to_end: 結束問題
redirect: 問卷跳轉
redirect_mode: 設爲跳轉模式
redirect_url: 跳轉地址
must_answer: 必須回答這個問題
default_widget: