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 end
def show def show
redirect_standalone panel_survey_front_end_survey_path(params[:id], :standalone => 'true') do @survey = ::Survey.find params[:id]
@survey = ::Survey.find params[:id] if @survey.redirect_mode
@questions = @survey.survey_questions.all @redirect_url = @survey.redirect_url
if @survey.jump_mode render :redirect_standalone
@jumpable_questions = @questions.all.select{ |q| q.jumpable? && q.can_set_jump? } 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 end
end end

View File

@ -28,6 +28,9 @@ class Survey
mount_uploader :upload_file, AssetUploader mount_uploader :upload_file, AssetUploader
field :jump_mode, :type => Boolean, :default => false 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 validates :title, :at_least_one => true

View File

@ -18,6 +18,22 @@
</div> </div>
</div> </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>
<div id="post-body"> <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.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.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.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.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('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> <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> <section>
<div class="o-question"> <div class="o-question">
<div class="o-question-description"> <div class="o-question-description">
<%= t 'survey.results_count' %>: <%= @survey_questions.count %> <%= t 'survey.results_count' %>: <%= @survey.survey_answers.count %>
</div> </div>
<ol class="o-question-list"> <ol class="o-question-list">
<% @survey_questions.each do |question| %> <% @survey_questions.each do |question| %>

View File

@ -1,109 +1,117 @@
<% # encoding: utf-8 %> <% # encoding: utf-8 %>
<h1><%= @survey.title %></h1> <div class="o-question">
<div> <%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :standalone => true), :html => {:class => 'survey clear'} do |f| %>
<section> <h3 class="o-question-topic"><%= @survey.title %></h3>
<div class="o-question"> <div class="o-question-description">
<%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :inner => true), :html => {:class => 'clear'} do |f| %> <%= @survey.description %>
<div class="o-question-description"> </div>
<%= @survey.description %> <ol class="o-question-list">
</div> <% @questions.each_with_index do |question, i| %>
<ol class="o-question-list"> <li class="question-item question-<%= question.id.to_s %> hide" data-index="<%= i %>" data-type="<%= question.type%>" data-custom="<%= question.custom_option.to_s %>">
<% @questions.each_with_index do |question, i| %> <% label = question.title %>
<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 += ' (*)' if question.is_required %>
<% label = question.title %> <%= f.label question.id, label, :class => "o-question-title" %>
<% label += ' (' + t('survey_question.required') + ')' if question.is_required %> <div class="o-question-description">
<%= f.label question.id, label, :class => "o-question-title" %> <%= question.description %>
<div class="o-question-description"> </div>
<%= question.description %> <% case question.type %>
</div> <% when ::SurveyQuestion::Oneline %>
<% case question.type %> <%= f.text_field question.id, :required => question.is_required %>
<% when ::SurveyQuestion::Oneline %> <% when ::SurveyQuestion::Multiline %>
<%= f.text_field question.id, :required => question.is_required %> <%= f.text_area question.id, :rows => 5, :required => question.is_required %>
<% when ::SurveyQuestion::Multiline %> <% when ::SurveyQuestion::Radio %>
<%= f.text_area question.id, :rows => 5, :required => question.is_required %> <ul class="o-question-group view-list">
<% when ::SurveyQuestion::Radio %> <% question.survey_question_options.each do |option| %>
<% question.survey_question_options.each do |option| %> <li>
<p> <%= f.radio_button question.id, option.id %>
<%= f.radio_button question.id, option.id %> <%= f.label "#{question.id}_#{option.id}", option.name, :class => 'o-question-option' %>
<%= f.label "#{question.id}_#{option.id}", option.name, :style => "display:inline" %> </li>
</p> <% end %>
<% end %> <% if question.custom_option %>
<% if question.custom_option %> <li>
<p> <%= f.radio_button question.id, 'custom_option' %>
<%= f.radio_button question.id, 'custom_option' %> <%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :class => 'o-question-option' %>
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %> <%= f.text_field "#{question.id}_custom_option" %>
<%= f.text_field "#{question.id}_custom_option" %> </li>
</p> <% end %>
<% end %> </ul>
<% when ::SurveyQuestion::Check %> <% when ::SurveyQuestion::Check %>
<%= f.fields_for "#{question.id}" do |cf| %> <ul class="o-question-group view-list">
<% question.survey_question_options.each do |option| %> <%= f.fields_for "#{question.id}" do |cf| %>
<p> <% question.survey_question_options.each do |option| %>
<%= cf.check_box option.id %> <li>
<%= cf.label option.id, option.name, :style => "display:inline" %> <%= cf.check_box option.id %>
</p> <%= cf.label option.id, option.name, :class => 'o-question-option' %>
<% end %> </li>
<% if question.custom_option %> <% end %>
<p> <% if question.custom_option %>
<%= cf.check_box 'custom_option' %> <li>
<%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :style => "display:inline" %> <%= cf.check_box 'custom_option' %>
<%= f.text_field "#{question.id}_custom_option" %> <%= f.label "#{question.id}_custom_option", t('survey_question.use_custom_option') + ': ', :class => 'o-question-option' %>
</p> <%= f.text_field "#{question.id}_custom_option" %>
<% end %> </li>
<% end %> <% end %>
<% when ::SurveyQuestion::Select %> <% end %>
<% options = question.survey_question_options.collect {|o| [ o.name, o.id ] } %> </ul>
<% if question.custom_option %> <% when ::SurveyQuestion::Select %>
<% options.push [t('survey_question.use_custom_option'), 'custom_option'] %> <% options = question.survey_question_options.collect {|o| [ o.name, o.id ] } %>
<% end %> <% if question.custom_option %>
<%= f.select question.id, options %> <% options.push [t('survey_question.use_custom_option'), 'custom_option'] %>
<% if question.custom_option %> <% end %>
<%= f.text_field "#{question.id}_custom_option", :class => 'custom_option' %> <%= f.select question.id, options, {}, :class => 'o-question-group view-dropdown' %>
<% end %> <% if question.custom_option %>
<% when ::SurveyQuestion::Radiogroup %> <%= f.text_field "#{question.id}_custom_option", :class => 'custom_option' %>
<%= f.fields_for "#{question.id}" do |rgf| %> <% end %>
<table class="o-question-group view-grid"> <% when ::SurveyQuestion::Radiogroup %>
<thead> <%= f.fields_for "#{question.id}" do |rgf| %>
<tr> <table class="o-question-group view-grid">
<th></th> <thead>
<% question.survey_question_radiogroups.each do |radiogroup| %> <tr>
<th> <th></th>
<%= radiogroup.name %> <% question.survey_question_radiogroups.each do |radiogroup| %>
</th> <th>
<% end %> <%= radiogroup.name %>
</tr> </th>
</thead> <% end %>
<tbody> </tr>
<% question.survey_question_options.each_with_index do |option, j| %> </thead>
<tr<%= (' class="odd"').html_safe if (j % 2 == 0) %>> <tbody>
<th class="o-question-title"> <% question.survey_question_options.each_with_index do |option, j| %>
<%= option.name %> <tr<%= (' class="odd"').html_safe if (j % 2 == 0) %>>
</th> <th class="o-question-title">
<% question.survey_question_radiogroups.each do |radiogroup| %> <%= option.name %>
<td> </th>
<%= rgf.radio_button option.id, radiogroup.id %> <% question.survey_question_radiogroups.each do |radiogroup| %>
</td> <td>
<% end %> <%= rgf.radio_button option.id, radiogroup.id %>
</tr> </td>
<% end %> <% end %>
</tbody> </tr>
</table> <% end %>
<% end %> </tbody>
<% end %> </table>
</li> <% end %>
<% end %> <% end %>
</ol> </li>
<div class="o-question-action"> <% end %>
<%= f.submit t('submit'), :class => 'survey-submit' %> </ol>
</div> <div class="o-question-action">
<% end %> <%= f.submit t('submit'), :class => 'survey-submit' %>
</div> </div>
</section> <% end %>
</div> </div>
<% content_for :page_stylesheets do %> <% content_for :page_stylesheets do %>
<link href='/assets/questionnaire.css' rel='stylesheet' type='text/css' /> <link href='/assets/questionnaire.css' rel='stylesheet' type='text/css' />
<% end %> <% end %>
<script type="text/javascript" src="/assets/jquery.form.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$('form.survey').ajaxForm({
beforeSubmit: function(a,f,o) {
o.dataType = 'script';
},
success: function(data) {
}
});
<% if @survey.jump_mode %> <% if @survey.jump_mode %>
var jump_tos_map = <%== @jump_tos_map.to_json %>; var jump_tos_map = <%== @jump_tos_map.to_json %>;
var $current_question = $('.question-item').eq(0); var $current_question = $('.question-item').eq(0);

View File

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

View File

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