survey/app/views/surveys/result.html.erb

88 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

2014-10-06 05:55:25 +00:00
<%
data = action_data
@survey = data["survey"]
@chart_data = data["chart_data"]
@survey_questions = data["survey_questions"]
@survey_answers = data["survey_answers"]
%>
<% case @survey.result_type %>
<% when QuestionnaireSurvey::ResultChart %>
<h1><%= @survey.title %> <%= t('survey.chart') %></h1>
<div>
<section>
<div class="o-question">
<div class="o-question-description">
<%= t 'survey.results_count' %>: <%= @survey.survey_answers.count %>
</div>
<ol class="o-question-list">
<% @survey_questions.each do |question| %>
<% case question.type %>
<% when SurveyQuestion::Radio, SurveyQuestion::Check, ::SurveyQuestion::Select %>
<li>
<div id="question_chart_<%= question.id.to_s %>" style="width: 600px; height: 300px;"></div>
</li>
<% when SurveyQuestion::Radiogroup %>
<% question.survey_question_options.each_with_index do |option,index| %>
2014-10-06 05:55:25 +00:00
<li>
<div id="question_chart_<%= question.id.to_s %>_<%= index.to_s %>" style="width: 600px; height: 300px;"></div>
2014-10-06 05:55:25 +00:00
</li>
<% end %>
<% end %>
<% end %>
</ol>
</div>
</section>
</div>
<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 %>'});
<% when ::SurveyQuestion::Radiogroup %>
<% options = Hash[question.survey_question_options.collect{|o| [ o.id.to_s, o.name ] }] %>
<% i = 0 %>
2014-10-06 05:55:25 +00:00
<% @chart_data[qid].each do |option, groups| %>
var data_<%= qid %> = google.visualization.arrayToDataTable([
2014-10-06 05:55:25 +00:00
['<%= t("survey_question.option") %>', ''],
<% groups.each do |group, count| %>
['<%= group %>', <%= count %>],
<% end %>
]);
var chart_xx = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>_<%= i.to_s %>'));
chart_xx.draw(data_<%= qid %>, {title: '<%= question.title %> - <%= options[option] %>'});
<% i = i + 1 %>
2014-10-06 05:55:25 +00:00
<% end %>
<% end %>
<% end %>
});
} else {
window.location.href = "<%= survey_path(@survey, :inner => 'true') %>";
}
</script>
<% when QuestionnaireSurvey::ResultExtern %>
<script type="text/javascript">
window.location.href = "<%= @survey.extern_link %>";
</script>
<% when QuestionnaireSurvey::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} if !@survey.upload_file.blank? %>
</section>
<% end %>