课程问卷 其它选项如果过多的时候默认显示, 添加“隐藏”和“显示”按钮
This commit is contained in:
parent
ff34ec6de8
commit
244303f0e4
|
@ -63,6 +63,11 @@ module PollHelper
|
|||
def total_answer id
|
||||
total = PollVote.find_by_sql("SELECT distinct(user_id) FROM `poll_votes` where poll_question_id = #{id}").count
|
||||
end
|
||||
|
||||
# 获取其它选项的答案
|
||||
def other_answers poll_question
|
||||
poll_question.poll_votes.select{|pv| !pv.try(:vote_text).blank?}
|
||||
end
|
||||
|
||||
#页面体型显示
|
||||
def options_show pq
|
||||
|
|
|
@ -1,28 +1,63 @@
|
|||
<div class="ur_table_result">
|
||||
<table border="0" cellspacing="0" cellpadding="0" >
|
||||
<tbody>
|
||||
<tr class="table_bluebg">
|
||||
<td class="td327"><%= l(:label_poll_options) %> </td>
|
||||
<td class="td42"><%= l(:label_poll_subtotal) %> </td>
|
||||
<td class="td287"><%= l(:label_poll_proportion) %> </td>
|
||||
</tr>
|
||||
<% poll_question.poll_answers.each do |poll_answer| %>
|
||||
<tr>
|
||||
<td class="td327"><%= poll_answer.answer_text == "" ? "其他" :poll_answer.answer_text %> </td>
|
||||
<td class="td42"><%= poll_answer.poll_votes.count %> </td>
|
||||
<td class="td287">
|
||||
<div class="Bar">
|
||||
<span style="width:<%= statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)) %>%;" id="choice_percentage_<%= poll_answer.id %>"></span>
|
||||
</div>
|
||||
<%= statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)) %>%</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr class="table_bluebg">
|
||||
<td class="td327"><%= l(:label_poll_valid_commit) %> </td>
|
||||
<td class="td42"><%= total_answer(poll_question.id) %></td>
|
||||
<td class="td287"> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<tr class="table_bluebg">
|
||||
<td class="td327"><%= l(:label_poll_options) %> </td>
|
||||
<td class="td42"><%= l(:label_poll_subtotal) %> </td>
|
||||
<td class="td287"><%= l(:label_poll_proportion) %> </td>
|
||||
</tr>
|
||||
<% poll_question.poll_answers.each do |poll_answer| %>
|
||||
<tr>
|
||||
<td class="td327">
|
||||
<% if poll_answer.answer_text == "" %>
|
||||
其它<a onclick="hidden_others(<%= poll_question.id %>, <%= poll_answer.id %>);" class="c_blue fr mr5" id ="other_answer_<%= poll_answer.id %>"><%= "隐藏" if other_answers(poll_question).count > 0 %></a>
|
||||
<% else %>
|
||||
<%= poll_answer.answer_text %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="td42"><%= poll_answer.poll_votes.count %> </td>
|
||||
<td class="td287">
|
||||
<div class="Bar">
|
||||
<span style="width:<%= statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)) %>%;" id="choice_percentage_<%= poll_answer.id %>"></span>
|
||||
</div>
|
||||
<%= statistics_result_percentage(poll_answer.poll_votes.count, total_answer(poll_question.id)) %>%</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="other_tip_<%= poll_question.id %>" style="display: block">
|
||||
<% if other_answers(poll_question).count > 0 %>
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr class="table_bluebg"><td class="pl5 w607">其它(详情)</td></tr>
|
||||
<% other_answers(poll_question).each do |pv| %>
|
||||
<tr><td class="pl5 w607"><%= pv.vote_text %></td></tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
</div>
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr class="table_bluebg">
|
||||
<td class="td327"><%= l(:label_poll_valid_commit) %> </td>
|
||||
<td class="td42"><%= total_answer(poll_question.id) %></td>
|
||||
<td class="td287"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function hidden_others(id1, id2){
|
||||
var other_answer = document.getElementById("other_answer_"+id2).innerText;
|
||||
if (other_answer == "隐藏")
|
||||
{
|
||||
$("#other_answer_"+id2).text("显示");
|
||||
$("#other_tip_"+id1).hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#other_answer_"+id2).text("隐藏");
|
||||
$("#other_tip_"+id1).show();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue