2021-09-12 12:20:03 +00:00
|
|
|
<%
|
|
|
|
data = action_data
|
|
|
|
@survey = data["survey"]
|
|
|
|
@user = data["user"]
|
|
|
|
@survey_answers = data["survey_answers"]
|
|
|
|
@table_fields = data["table_fields"]
|
|
|
|
@is_answer_list = data["is_answer_list"]
|
|
|
|
%>
|
|
|
|
<% if @user.nil? %>
|
|
|
|
<h3><a id="display_login_button" href="#" title="<%=t("survey.please_login_first")%>"><%=t("survey.please_login_first")%></a></h3>
|
|
|
|
<script>
|
|
|
|
$("#display_login_button").click(function(){
|
|
|
|
$('#loginbutton').click();
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
<% else %>
|
|
|
|
<style type="text/css">
|
|
|
|
#survey_answer_search label{
|
|
|
|
float: left;
|
|
|
|
margin-right: 0.5em;
|
|
|
|
line-height: 2;
|
|
|
|
}
|
|
|
|
#survey_answer_search input{
|
|
|
|
float: left;
|
|
|
|
line-height: 2;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<h3><%= @survey.title %></h3>
|
|
|
|
<div>
|
|
|
|
<h4><%=t('survey.taken_by')%>: <%=@user.member_name%></h4>
|
|
|
|
</div>
|
|
|
|
<table class="table main-list">
|
|
|
|
<thead>
|
|
|
|
<tr class="sort-header">
|
|
|
|
<% @table_fields.each do |f| %>
|
|
|
|
<%= thead(f) %>
|
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<% (@survey_answer_groups || @survey_answers).each do |sa| %>
|
|
|
|
<tr>
|
|
|
|
<% user = sa.user.nil? ? nil : (User.find(sa.user) rescue nil) %>
|
|
|
|
<% if !user.nil? %>
|
|
|
|
<td><%= user.member_name rescue user.name %></td>
|
|
|
|
<% else %>
|
|
|
|
<td>NA</td>
|
|
|
|
<% end %>
|
|
|
|
<td><%= (@is_answer_list ? sa.updated_at : sa.last_modified).strftime("%h %d, %Y - %H:%M") rescue nil %></td>
|
|
|
|
<td>
|
|
|
|
<% if @answer_repeat && !@is_answer_list %>
|
|
|
|
<a class="btn btn-primary" href="/admin/surveys/<%= sa.id.to_s %>/answer_list" title="<%= t("survey.view") %>"><%= t("survey.view") %>(<%=sa.survey_answer_ids.count%>)</a>
|
|
|
|
<button class="btn btn-primary export-xls" data-href="/admin/surveys/<%= sa.id.to_s %>/export_answers" title="<%= t("survey.export") %>"><%= t("survey.export") %></button>
|
|
|
|
<% else %>
|
2021-10-13 09:15:47 +00:00
|
|
|
<% if @survey.result_type == QuestionnaireSurvey::ResultCriteria %>
|
|
|
|
<% tmp_msgs = []
|
|
|
|
answer_model_attrs = sa.attributes
|
|
|
|
weight_relations = @survey.survey_questions.map{|q| [q.id.to_s,(q.weight.nil? ? 1 : q.weight)]}.to_h
|
|
|
|
types = [] %>
|
|
|
|
<% @survey.result_criteria.each do |criteria| %>
|
|
|
|
<%
|
|
|
|
total_criteria_score = 0
|
|
|
|
total_weight = 0
|
|
|
|
((criteria["questions"][0].to_i - 1)..(criteria["questions"][1].to_i - 1)).each do |x|
|
|
|
|
total_criteria_score = (total_criteria_score + sa.individual_total[x].to_i) rescue 0
|
|
|
|
k = weight_relations.keys[x]
|
|
|
|
if k && answer_model_attrs.has_key?(k)
|
|
|
|
total_weight += weight_relations[k]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
type = criteria["type"].to_i
|
|
|
|
%>
|
|
|
|
<% if type == 0 %>
|
|
|
|
<% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score) %>
|
|
|
|
<% tmp_msgs << criteria["msg"] %>
|
|
|
|
<% types << type %>
|
|
|
|
<% end %>
|
|
|
|
<% else %>
|
|
|
|
<% if (criteria["range"][0].to_i..criteria["range"][1].to_i).cover?(total_criteria_score / total_weight) %>
|
|
|
|
<% tmp_msgs << criteria["msg"] %>
|
|
|
|
<% types << type %>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
<% end %>
|
|
|
|
<% if types.include?(0) %>
|
|
|
|
<h4>Your total score is <%= sa.scored_points %> </h4>
|
|
|
|
<% end %>
|
|
|
|
<% if types.include?(1) %>
|
|
|
|
<h4>Your average score is <%= sa.get_avg_points %> </h4>
|
|
|
|
<% end %>
|
|
|
|
<% tmp_msgs.each do |msg| %>
|
|
|
|
<div><%=msg.html_safe%></div>
|
|
|
|
<% end %>
|
|
|
|
<% else %>
|
2021-09-12 12:20:03 +00:00
|
|
|
<a class="btn btn-primary" href="/admin/surveys/<%= @is_answer_list ? sa.id : sa.survey_answer_ids.last.to_s %>/answer_set" title="<%= t("survey.view_answers") %>"><%= t("survey.view_answers") %></a>
|
2021-10-13 09:15:47 +00:00
|
|
|
<% end %>
|
2021-09-12 12:20:03 +00:00
|
|
|
<% end %>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<% end %>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<%= create_pagination((@survey_answer_groups || @survey_answers).total_pages).html_safe %>
|
|
|
|
<% end %>
|