86 lines
3.6 KiB
Plaintext
86 lines
3.6 KiB
Plaintext
|
|
||
|
<%
|
||
|
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 do |option| %>
|
||
|
<li>
|
||
|
<div id="question_chart_<%= question.id.to_s %>_<%= option.id.to_s %>" style="width: 600px; height: 300px;"></div>
|
||
|
</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 ] }] %>
|
||
|
<% @chart_data[qid].each do |option, groups| %>
|
||
|
var data_<%= qid %>_<%= option %> = google.visualization.arrayToDataTable([
|
||
|
['<%= t("survey_question.option") %>', ''],
|
||
|
<% groups.each do |group, count| %>
|
||
|
['<%= group %>', <%= count %>],
|
||
|
<% end %>
|
||
|
]);
|
||
|
var chart_<%= qid %>_<%= option %> = new google.visualization.PieChart(document.getElementById('question_chart_<%= qid %>_<%= option %>'));
|
||
|
chart_<%= qid %>_<%= option %>.draw(data_<%= qid %>_<%= option %>, {title: '<%= question.title %> - <%= options[option] %>'});
|
||
|
<% 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 %>
|