questionnaire stuff
Conflicts: vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb
This commit is contained in:
1 parent
32c259ac9e
commit
adc15951bb
34 files changed
+818
-1819
No files matched your search
@@ -1,99 +0,0 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
personal_journal (0.0.1)
|
||||
rails (~> 3.1.4)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.1.9)
|
||||
actionpack (= 3.1.9)
|
||||
mail (~> 2.3.3)
|
||||
actionpack (3.1.9)
|
||||
activemodel (= 3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
i18n (~> 0.6)
|
||||
rack (~> 1.3.6)
|
||||
rack-cache (~> 1.2)
|
||||
rack-mount (~> 0.8.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.0.4)
|
||||
activemodel (3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
builder (~> 3.0.0)
|
||||
i18n (~> 0.6)
|
||||
activerecord (3.1.9)
|
||||
activemodel (= 3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
arel (~> 2.2.3)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.1.9)
|
||||
activemodel (= 3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
activesupport (3.1.9)
|
||||
multi_json (>= 1.0, < 1.3)
|
||||
arel (2.2.3)
|
||||
builder (3.0.4)
|
||||
erubis (2.7.0)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.1)
|
||||
jquery-rails (2.1.4)
|
||||
railties (>= 3.0, < 5.0)
|
||||
thor (>= 0.14, < 2.0)
|
||||
json (1.7.6)
|
||||
mail (2.3.3)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mime-types (1.19)
|
||||
multi_json (1.2.0)
|
||||
polyglot (0.3.3)
|
||||
rack (1.3.6)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-mount (0.8.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.1.9)
|
||||
actionmailer (= 3.1.9)
|
||||
actionpack (= 3.1.9)
|
||||
activerecord (= 3.1.9)
|
||||
activeresource (= 3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.1.9)
|
||||
railties (3.1.9)
|
||||
actionpack (= 3.1.9)
|
||||
activesupport (= 3.1.9)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (~> 0.14.6)
|
||||
rake (10.0.3)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
sprockets (2.0.4)
|
||||
hike (~> 1.2)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.6)
|
||||
thor (0.14.6)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.12)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.35)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
jquery-rails
|
||||
personal_journal!
|
||||
sqlite3
|
||||
+81
@@ -1,3 +1,5 @@
|
||||
require 'csv'
|
||||
|
||||
class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
||||
|
||||
include AdminHelper
|
||||
@@ -82,5 +84,84 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
||||
end
|
||||
redirect_to panel_survey_back_end_surveys_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
|
||||
end
|
||||
|
||||
def export
|
||||
@survey = ::Survey.find(params[:id])
|
||||
@survey_questions = @survey.survey_questions.all
|
||||
|
||||
respond_to do |format|
|
||||
format.csv do
|
||||
|
||||
csv = CSV.generate do |csv|
|
||||
csv << @survey_questions.map(&:title)
|
||||
@survey.survey_answers.each do |answer|
|
||||
row = []
|
||||
@survey_questions.each do |question|
|
||||
row << answer[question.id.to_s]
|
||||
end
|
||||
csv << row
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
render :text => csv
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def chart
|
||||
@survey = ::Survey.find(params[:id])
|
||||
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
|
||||
end
|
||||
|
||||
def set_answers
|
||||
@survey = ::Survey.find(params[:id])
|
||||
end
|
||||
|
||||
def jump
|
||||
@survey = ::Survey.find(params[:id])
|
||||
@questions = @survey.survey_questions.all
|
||||
|
||||
@jump_to_options = [[ t('survey.not_jump'), 0 ], [t('survey.jump_to_end'), 1]]
|
||||
@jump_to_options += @questions.collect {|q| [ q.title, q.id.to_s ] }
|
||||
end
|
||||
|
||||
def duplicate_it
|
||||
@survey = ::Survey.find(params[:id])
|
||||
|
||||
@new_survey = ::Survey.new
|
||||
|
||||
@survey.attributes.each do |key, value|
|
||||
unless ['_id', 'created_at', 'updated_at', 'update_user_id'].include? key
|
||||
if @survey.respond_to?(key + '_translations')
|
||||
@new_survey.send(key + '_translations=', value)
|
||||
else
|
||||
@new_survey.write_attribute(key, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
@survey.survey_questions.all.each do |question|
|
||||
new_question = @new_survey.survey_questions.new
|
||||
question.attributes.each do |key, value|
|
||||
unless ['_id', 'created_at', 'updated_at'].include? key
|
||||
if @survey.respond_to?(key + '_translations')
|
||||
new_question.send(key + '_translations=', value)
|
||||
else
|
||||
new_question.write_attribute(key, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@new_survey.create_user_id = current_user.id
|
||||
@new_survey.update_user_id = current_user.id
|
||||
|
||||
@new_survey.save!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(panel_survey_back_end_surveys_url) }
|
||||
format.xml { render :xml => @survey, :status => :created, :location => @new_survey }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Vendored
+33
-4
@@ -1,4 +1,5 @@
|
||||
class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
||||
helper ApplicationHelper
|
||||
|
||||
def initialize
|
||||
super
|
||||
@@ -6,11 +7,18 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
@survey = ::Survey.find params[:id]
|
||||
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? }
|
||||
|
||||
@jump_tos_map = @jumpable_questions.map(&:get_jump_tos).inject(:merge)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -20,7 +28,7 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
||||
@answer_model = @survey.survey_answers.new
|
||||
@survey.survey_questions.each do |question|
|
||||
qid = question.id.to_s
|
||||
if question.is_required && answer[qid].blank?
|
||||
if question.is_required && answer[qid].blank? && !@survey.jump_mode #&& (! @survey.jump_mode || ( @survey.jump_mode && question.jumpable? ) )
|
||||
@answer_model.errors.add question.title, t('survey_question.required_error')
|
||||
else
|
||||
case question.type
|
||||
@@ -65,7 +73,6 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
||||
end
|
||||
end
|
||||
end
|
||||
p @answer_model
|
||||
if @answer_model.errors.empty?
|
||||
@answer_model.save!
|
||||
render :answer_success
|
||||
@@ -75,4 +82,26 @@ class Panel::Survey::FrontEnd::SurveysController < OrbitWidgetController
|
||||
end
|
||||
end
|
||||
|
||||
def result
|
||||
redirect_standalone result_panel_survey_front_end_survey_path(params[:id], :standalone => 'true') do
|
||||
@survey = ::Survey.find params[:id]
|
||||
case @survey.result_type
|
||||
when ::Survey::ResultChart
|
||||
@chart_data, @survey_questions, @survey_answers = @survey.generate_chart_data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_standalone url
|
||||
unless params[:standalone] == 'true'
|
||||
@redirect_url = url
|
||||
render :redirect_standalone
|
||||
else
|
||||
module_app = ModuleApp.first(:conditions => {:key => 'survey'})
|
||||
@item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first
|
||||
yield
|
||||
render :layout => 'standalone'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -5,6 +5,10 @@ class Survey
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
ResultChart = 0
|
||||
ResultExtern = 1
|
||||
ResultFile = 2
|
||||
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
scope :can_display, where(is_hidden: false)
|
||||
|
||||
@@ -18,6 +22,12 @@ class Survey
|
||||
field :deadline, :type => DateTime
|
||||
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
field :result_type, :type => Integer, :default => 0
|
||||
field :extern_link
|
||||
mount_uploader :upload_file, AssetUploader
|
||||
|
||||
field :jump_mode, :type => Boolean, :default => false
|
||||
|
||||
validates :title, :at_least_one => true
|
||||
|
||||
@@ -34,6 +44,43 @@ class Survey
|
||||
r
|
||||
end
|
||||
|
||||
def result
|
||||
I18n.t 'survey.view_result'
|
||||
end
|
||||
|
||||
def generate_chart_data
|
||||
survey_questions = self.survey_questions.all
|
||||
survey_answers = self.survey_answers.all
|
||||
|
||||
chart_data = {}
|
||||
|
||||
survey_questions.each do |question|
|
||||
qid = question.id.to_s
|
||||
case question.type
|
||||
when ::SurveyQuestion::Radio, ::SurveyQuestion::Select
|
||||
chart_data[qid] = {}
|
||||
answers = survey_answers.each do |answer|
|
||||
if answer[qid]
|
||||
chart_data[qid][answer[qid]] ||= 0
|
||||
chart_data[qid][answer[qid]] += 1
|
||||
end
|
||||
end
|
||||
when ::SurveyQuestion::Check
|
||||
chart_data[qid] = {}
|
||||
answers = survey_answers.each do |answer|
|
||||
if answer[qid]
|
||||
answer[qid].each do |option|
|
||||
chart_data[qid][option] ||= 0
|
||||
chart_data[qid][option] += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[chart_data, survey_questions, survey_answers]
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def check_deadline
|
||||
|
||||
@@ -24,4 +24,22 @@ class SurveyQuestion
|
||||
|
||||
accepts_nested_attributes_for :survey_question_options, :allow_destroy => true
|
||||
accepts_nested_attributes_for :survey_question_radiogroups, :allow_destroy => true
|
||||
|
||||
def jumpable?
|
||||
case type
|
||||
when SurveyQuestion::Radio, SurveyQuestion::Select
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def can_set_jump?
|
||||
( !custom_option )
|
||||
end
|
||||
|
||||
def get_jump_tos
|
||||
Hash[survey_question_options.select{ |o| !o.jump_to.blank? }.collect{ |o| [o.id.to_s, o.jump_to] }]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
class SurveyQuestionOneline < SurveyQuestion
|
||||
|
||||
end
|
||||
@@ -2,6 +2,7 @@ class SurveyQuestionOption
|
||||
include Mongoid::Document
|
||||
|
||||
field :name, :localize => true
|
||||
field :jump_to, :default => 0
|
||||
|
||||
embedded_in :survey_question
|
||||
end
|
||||
+1
-1
@@ -111,7 +111,7 @@
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="type-specify hide-type-<%= SurveyQuestion::Radiogroup%>">
|
||||
<div class="type-specify type-<%= SurveyQuestion::Radio%> type-<%= SurveyQuestion::Check%> type-<%= SurveyQuestion::Select%> hide-type-<%= SurveyQuestion::Radiogroup%>">
|
||||
<%= f.label :custom_option, t('survey_question.custom_option')%>
|
||||
<%= f.check_box :custom_option %>
|
||||
</div>
|
||||
|
||||
+6
-1
@@ -10,7 +10,12 @@
|
||||
<ul class="nav nav-pills hide">
|
||||
<%if at_least_module_manager %>
|
||||
<li><%= link_to t('edit'), edit_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
|
||||
<li><%= link_to t('survey.answers'), panel_survey_back_end_survey_answers_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.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'), chart_panel_survey_back_end_survey_path(survey, :page => params[:page]) %></li>
|
||||
<li><%= link_to t(:delete_), panel_survey_back_end_survey_path(survey), :confirm => t('sure?'), :method => :delete, :remote => true %></li>
|
||||
<% end -%>
|
||||
</ul>
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<h1><%= @survey.title %> <%= t('survey.chart') %></h1>
|
||||
|
||||
<% @survey_questions.each do |question| %>
|
||||
|
||||
<h3><%= question.title %></h3>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
<div id="question_chart_<%= question.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||||
<% else %>
|
||||
<p><%= t('survey_question.have_not_chart') %></p>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="form-actions form-fixed">
|
||||
<%= link_to t('back'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript">
|
||||
google.load("visualization", "1", {packages:["corechart"]});
|
||||
google.setOnLoadCallback(function(){
|
||||
<% @survey_questions.each do |question| %>
|
||||
<% qid = question.id.to_s %>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
var data_<%= qid %> = google.visualization.arrayToDataTable([
|
||||
['<%= t("survey_question.option") %>', ''],
|
||||
<% @chart_data[qid].each do |option, count| %>
|
||||
['<%= option %>', <%= count %>],
|
||||
<% end %>
|
||||
]);
|
||||
var chart_<%= qid %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>'));
|
||||
chart_<%= qid %>.draw(data_<%= qid %>, {title: '<%= question.title %>'});
|
||||
<% end %>
|
||||
<% end %>
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<h1><%= @survey.title %> <%= t('survey.jump') %></h1>
|
||||
|
||||
<%= form_for @survey, :url => panel_survey_back_end_survey_path(@survey), :html => {:class => 'clear'} do |f| %>
|
||||
<div id="post-body">
|
||||
<div id="post-body-content" class="clear">
|
||||
<div class="jump_mode">
|
||||
<%= f.label :jump_mode, t('survey.jump_mode')%>
|
||||
<%= f.check_box :jump_mode %>
|
||||
</div>
|
||||
|
||||
<% @questions.each_with_index do |question, i| %>
|
||||
|
||||
<%= f.fields_for :survey_questions, question do |f| %>
|
||||
|
||||
<div id="<%= "survey_question_#{question.id}"%>" class="survey_question_item clear">
|
||||
<div id="widget-question" class="widget-box">
|
||||
<h3 class="widget-title"><i class="icons-help"></i><%= question.title %></h3>
|
||||
<div class="widget-content">
|
||||
<% if question.jumpable? %>
|
||||
<% if question.can_set_jump? %>
|
||||
<ol>
|
||||
<% question.survey_question_options.each_with_index do |option, i| %>
|
||||
|
||||
<%= f.fields_for :survey_question_options, option do |f| %>
|
||||
|
||||
<li>
|
||||
<%= f.label :survey_question_options, option.name %>
|
||||
<%= f.select :jump_to, @jump_to_options %>
|
||||
</li>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</ol>
|
||||
<% else %>
|
||||
<%= t('survey.right_type_cant_jump') %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('survey.wrong_type_cant_jump') %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %>
|
||||
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
|
||||
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
<h1><%= @survey.title %> <%= t('survey.set_answers') %></h1>
|
||||
|
||||
<%= form_for @survey, :url => panel_survey_back_end_survey_path(@survey), :html => {:class => 'clear'} do |f| %>
|
||||
<div id="post-body">
|
||||
<div id="post-body-content" class="clear">
|
||||
<div class="type">
|
||||
<%= f.label :result_type, t('survey.result_type')%>
|
||||
<%= f.select :result_type, {
|
||||
t('survey.chart') => Survey::ResultChart,
|
||||
t('survey.extern_link') => Survey::ResultExtern,
|
||||
t('survey.upload_file') => Survey::ResultFile
|
||||
}, {}, :class => "tinput-medium" %>
|
||||
</div>
|
||||
<div class="extern_link">
|
||||
<%= f.label :extern_link, t('survey.extern_link') %>
|
||||
<%= f.text_field :extern_link, :style=>"width:98%;", :class=>'post-extern_link' %>
|
||||
</div>
|
||||
<div class="upload_file">
|
||||
<%= f.label :upload_file, t('survey.upload_file') %>
|
||||
<%= f.file_field :upload_file %>
|
||||
<% if @survey.upload_file? %>
|
||||
<%= link_to t(:view), @survey.upload_file.url, {:class => 'for_preview btn', :target => '_blank', :title => t(:view), "data-trigger" => :hover} %>
|
||||
<%= f.label :remove_upload_file, t('survey.remove_upload_file')%>
|
||||
<%= f.check_box :remove_upload_file %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %>
|
||||
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
|
||||
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
<script type="text/javascript">
|
||||
alert("<%= t('survey.answer_error')%>: <%= @survey_answer_error %>");
|
||||
window.location.href = "<%= panel_survey_front_end_survey_path(@survey, :clicked_field_name => 'title') %>";
|
||||
window.history.back();
|
||||
</script>
|
||||
vendor/built_in_modules/survey/app/views/panel/survey/front_end/surveys/redirect_standalone.html.erb
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
<script type="text/javascript">
|
||||
window.location.href = "<%= @redirect_url %>";
|
||||
</script>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<% case @survey.result_type %>
|
||||
<% when ::Survey::ResultChart %>
|
||||
|
||||
<h1><%= @survey.title %> <%= t('survey.chart') %></h1>
|
||||
<section>
|
||||
<% @survey_questions.each do |question| %>
|
||||
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
<div id="question_chart_<%= question.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
<script type="text/javascript">
|
||||
if (window.google) {
|
||||
window.google.load("visualization", "1", {packages:["corechart"]});
|
||||
window.google.setOnLoadCallback(function(){
|
||||
<% @survey_questions.each do |question| %>
|
||||
<% qid = question.id.to_s %>
|
||||
<% case question.type %>
|
||||
<% when ::SurveyQuestion::Radio, ::SurveyQuestion::Check, ::SurveyQuestion::Select %>
|
||||
var data_<%= qid %> = google.visualization.arrayToDataTable([
|
||||
['<%= t("survey_question.option") %>', ''],
|
||||
<% @chart_data[qid].each do |option, count| %>
|
||||
['<%= option %>', <%= count %>],
|
||||
<% end %>
|
||||
]);
|
||||
var chart_<%= qid %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>'));
|
||||
chart_<%= qid %>.draw(data_<%= qid %>, {title: '<%= question.title %>'});
|
||||
<% end %>
|
||||
<% end %>
|
||||
});
|
||||
} else {
|
||||
window.location.href = "<%= result_panel_survey_front_end_survey_path(@survey, :inner => 'true') %>";
|
||||
}
|
||||
</script>
|
||||
<% when ::Survey::ResultExtern %>
|
||||
<script type="text/javascript">
|
||||
window.location.href = "<%= @survey.extern_link %>";
|
||||
</script>
|
||||
<% when ::Survey::ResultFile %>
|
||||
<h1><%= @survey.title %> <%= t('survey.upload_file') %></h1>
|
||||
<section>
|
||||
<%= link_to t(:view), @survey.upload_file.url, {:class => 'for_preview btn', :target => '_blank', :title => t(:view), "data-trigger" => :hover} %>
|
||||
</section>
|
||||
<% end %>
|
||||
+154
-84
@@ -1,87 +1,157 @@
|
||||
<% # encoding: utf-8 %>
|
||||
<h1 class="h1"><%= @survey.title %></h1>
|
||||
<%= form_for :answer, :method => :put, :url => panel_survey_front_end_survey_path(@survey, :inner => true), :html => {:class => 'clear'} do |f| %>
|
||||
<% @survey.survey_questions.each do |question| %>
|
||||
<% label = question.title %>
|
||||
<% label += ' (' + t('survey_question.required') + ')' if question.is_required %>
|
||||
<%= f.label question.id, label %>
|
||||
<p><%= question.description %></p>
|
||||
<% 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" %>
|
||||
<% end %>
|
||||
<% when ::SurveyQuestion::Radiogroup %>
|
||||
<%= f.fields_for "#{question.id}" do |rgf| %>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<% question.survey_question_radiogroups.each do |radiogroup| %>
|
||||
<td>
|
||||
<%= rgf.label radiogroup.id, radiogroup.name %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% question.survey_question_options.each do |option| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= rgf.label option.id, option.name %>
|
||||
</td>
|
||||
<% question.survey_question_radiogroups.each do |radiogroup| %>
|
||||
<td>
|
||||
<%= rgf.radio_button option.id, radiogroup.id %>
|
||||
</td>
|
||||
<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 %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% 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 %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= f.submit t('submit') %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% content_for :page_stylesheets do %>
|
||||
<link href='/assets/questionnaire.css' rel='stylesheet' type='text/css' />
|
||||
<% end %>
|
||||
<script type="text/javascript">
|
||||
<% if @survey.jump_mode %>
|
||||
var jump_tos_map = <%== @jump_tos_map.to_json %>;
|
||||
var $current_question = $('.question-item').eq(0);
|
||||
var current_index = parseInt($current_question.attr('data-index'));
|
||||
$current_question.show();
|
||||
$('.survey-submit').click(function(){
|
||||
$current_question.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.show();
|
||||
current_index = parseInt($current_question.attr('data-index'));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
<% else %>
|
||||
$('.question-item').show();
|
||||
<% 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').show();
|
||||
} else {
|
||||
$(this).find('input.custom_option').hide();
|
||||
}
|
||||
});
|
||||
$(this).trigger('change');
|
||||
});
|
||||
</script>
|
||||
+54
-2
@@ -7,11 +7,63 @@ en:
|
||||
postdate: Start Date
|
||||
deadline: End Date
|
||||
no_postdate: No Start Date
|
||||
no_deadline: No Start Date
|
||||
no_deadline: No End Date
|
||||
results_count: Results Count
|
||||
update_user: Update User
|
||||
question: Question
|
||||
|
||||
result_type: Result Type (Frontend)
|
||||
extern_link: Extern Link
|
||||
upload_file: Uploaded File
|
||||
|
||||
remove_upload_file: Remove Uploaded File
|
||||
|
||||
answer_success: Successfully answered,jump back now
|
||||
answer_error: Unsuccessful answer
|
||||
|
||||
answers_list: Answers List
|
||||
export_csv: Export CSV
|
||||
chart: Chart
|
||||
set_answers: Set Answers
|
||||
duplicate_it: Duplicate It
|
||||
|
||||
view_result: View Result
|
||||
|
||||
jump: Jump-To
|
||||
jump_mode: Jump-To Mode
|
||||
wrong_type_cant_jump: Only radio or select can set jump-to
|
||||
right_type_cant_jump: Custom option allowed can't set jump-to
|
||||
not_jump: Not Jump
|
||||
jump_to_end: End of Survey
|
||||
|
||||
must_answer: Must be Answered
|
||||
|
||||
default_widget:
|
||||
title: Title
|
||||
time_range: Date Range
|
||||
result: Result
|
||||
|
||||
frontend:
|
||||
survey: Survey Frontend
|
||||
|
||||
survey_question:
|
||||
title: Question
|
||||
description: Description
|
||||
description: Description
|
||||
type: Type
|
||||
is_required: Is Required
|
||||
required: Required
|
||||
required_error: Can't not be empty
|
||||
oneline: Oneline
|
||||
multiline: Multi-line
|
||||
radio: Radio
|
||||
check: Check
|
||||
select: Select
|
||||
radiogroup: Radio Group
|
||||
options_lists: Options List
|
||||
radiogroup_label: Radio Group Label
|
||||
radiogroups_lists: Radio Groups List
|
||||
option: Option
|
||||
custom_option: Allow Custom Option
|
||||
use_custom_option: Other
|
||||
|
||||
have_not_chart: This type of question havn't chart
|
||||
+25
-1
@@ -13,14 +13,36 @@ zh_tw:
|
||||
update_user: 最後更新者
|
||||
question: 問題
|
||||
|
||||
result_type: 前端結果表示方式
|
||||
extern_link: 外部連結
|
||||
upload_file: 結果文件
|
||||
|
||||
remove_upload_file: 移除存在的結果文件
|
||||
|
||||
answer_success: 問卷填寫成功,現在跳回
|
||||
answer_error: 問卷填寫錯誤
|
||||
|
||||
answers: 結果
|
||||
answers_list: 結果清單
|
||||
export_csv: 匯出CSV
|
||||
chart: 結果圖表
|
||||
set_answers: 設定結果
|
||||
duplicate_it: 複製問卷
|
||||
|
||||
view_result: 查看結果
|
||||
|
||||
jump: 跳題
|
||||
jump_mode: 設爲跳題方式回答
|
||||
wrong_type_cant_jump: 不是單選或下拉無法使用跳題
|
||||
right_type_cant_jump: 允許自定回答的問題無法使用跳題
|
||||
not_jump: 依據試卷列出所有問題數
|
||||
jump_to_end: 結束問題
|
||||
|
||||
must_answer: 必須回答這個問題
|
||||
|
||||
default_widget:
|
||||
title: 問卷標題
|
||||
time_range: 問卷期間
|
||||
result: 結果
|
||||
|
||||
frontend:
|
||||
survey: 問卷調查前台
|
||||
@@ -44,3 +66,5 @@ zh_tw:
|
||||
option: 選項
|
||||
custom_option: 允許自定回答選項
|
||||
use_custom_option: 其他
|
||||
|
||||
have_not_chart: 此種類型問題不含結果圖表
|
||||
+12
-1
@@ -7,6 +7,13 @@ Rails.application.routes.draw do
|
||||
collection do
|
||||
get 'delete'
|
||||
end
|
||||
member do
|
||||
get 'export'
|
||||
get 'chart'
|
||||
get 'set_answers'
|
||||
get 'jump'
|
||||
get 'duplicate_it'
|
||||
end
|
||||
resources :answers, :controller => :surveys_answers do
|
||||
collection do
|
||||
get 'delete'
|
||||
@@ -15,7 +22,11 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
namespace :front_end do
|
||||
resources :surveys
|
||||
resources :surveys do
|
||||
member do
|
||||
get 'result'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+3
-2
@@ -22,9 +22,10 @@ module Faq
|
||||
default_widget do
|
||||
enable ["typeA"]
|
||||
query 'Survey.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now, :postdate.lte => Time.now} )'
|
||||
link_field :title,{:method => 'panel_survey_front_end_survey_path',:args=>:self}
|
||||
link_field :title, {:method => 'panel_survey_front_end_survey_path',:args=>:self}
|
||||
link_field :result, {:method => 'result_panel_survey_front_end_survey_path', :args=>:self}
|
||||
field :time_range
|
||||
link_to_more 'panel_survey_front_end_survey_path',:title_i18n=> 'faq.default_widget.to_more'
|
||||
link_to_more 'panel_survey_front_end_survey_path', :title_i18n=> 'faq.default_widget.to_more'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user