349 lines
18 KiB
Plaintext
349 lines
18 KiB
Plaintext
<%= stylesheet_link_tag 'polls', :media => 'all' %>
|
|
<div class="homepageRight mt0 ml10">
|
|
<div class="resources" id="polls">
|
|
<div class="testStatus">
|
|
<h1 class="ur_page_title">
|
|
<%= @poll.polls_name %>
|
|
</h1>
|
|
|
|
<div class="testDesEdit mt5"><%= @poll.polls_description.nil? ? "" : @poll.polls_description.html_safe %></div>
|
|
</div>
|
|
|
|
<% @poll_questions.each do |pq| %>
|
|
<% if pq.question_type == 1 %>
|
|
<!-- 单选题 -->
|
|
<div class="testStatus">
|
|
<div id="poll_questions_<%= pq.id %>">
|
|
<div id="show_poll_questions_<%= pq.id %>">
|
|
<div>
|
|
<div class="testEditTitle">
|
|
<%= l(:label_question_number, :question_number => pq.question_number) %>
|
|
<%= pq.question_title %>
|
|
<span class="fontBlue">[单选题]</span>
|
|
<% if pq.is_necessary == 1 %>
|
|
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
|
|
<% end %>
|
|
</div>
|
|
<div class="cl"></div>
|
|
<div class="ur_inputs">
|
|
<table class="ur_table" style="width:675px;">
|
|
<tbody>
|
|
<% pq.poll_answers.each do |pa| %>
|
|
<tr>
|
|
<td>
|
|
<label>
|
|
<script>
|
|
function onblur_<%= pa.id %>(obj) {
|
|
$(window).unbind('beforeunload');
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_question_id: <%= pq.id %>,
|
|
poll_answer_id: <%= pa.id %>,
|
|
vote_text: obj.value
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
//document.getElementById("poll_vote_<%#=pq.id %>poll_answer_id_<%#=pa.id %>").checked = true;
|
|
//var span = $('#percent');
|
|
//span.html(dataObj.percent);
|
|
}
|
|
});
|
|
}
|
|
function click_<%= pa.id %>(obj) {
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_answer_id: <%= pa.id %>,
|
|
poll_question_id: <%= pq.id %>
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
if (dataObj.text == "ok") {
|
|
obj.checked = true;
|
|
$(obj).parent().parent().parent().parent().find("input[type='text']").attr("disabled", "disabled");
|
|
$(obj).next('input').removeAttr("disabled");
|
|
}
|
|
else {
|
|
obj.checked = false;
|
|
$(obj).next('input').attr("disabled", "disabled");
|
|
}
|
|
var span = $('#percent');
|
|
span.html(dataObj.percent);
|
|
},
|
|
error: function () {
|
|
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<%= radio_button "poll_vote", pq.id.to_s+"poll_answer_id", pa.id, :class => "ur_radio", :onclick => "click_#{pa.id}(this);return false;", :checked => answer_be_selected?(pa, User.current), :disabled => !@can_edit_poll %>
|
|
<% if pa.answer_text == "" %>
|
|
<input class="ur_text ur_textbox" type="text" size="" maxlength="" style="width: 93%" value="<%= get_anwser_vote_text(pq.id, User.current.id, pa.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= (@can_edit_poll && answer_be_selected?(pa, User.current)) ? "" : "disabled=disabled" %> placeholder="其他">
|
|
<% else %>
|
|
<%= pa.answer_text %>
|
|
<% end %>
|
|
</label>
|
|
</td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<% elsif pq.question_type == 2 %>
|
|
<!-- 多选题 -->
|
|
<div class="testStatus">
|
|
<div id="poll_questions_<%= pq.id %>">
|
|
<div id="show_poll_questions_<%= pq.id %>">
|
|
<div>
|
|
<div class="testEditTitle">
|
|
<%= l(:label_question_number, :question_number => pq.question_number) %>
|
|
<%= pq.question_title %>
|
|
<span class="fontBlue">[多选题]</span>
|
|
<% if pq.is_necessary == 1 %>
|
|
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
|
|
<% end %>
|
|
<% if pq.min_choices != 0 || pq.max_choices != 0 %>
|
|
<p class="fontGrey2">
|
|
<% if pq.min_choices != 0 && pq.max_choices != 0 %>
|
|
答题时最少选<%=pq.min_choices %>项、最多选<%=pq.max_choices %>项
|
|
<% elsif pq.min_choices != 0 %>
|
|
答题时最少选<%=pq.min_choices %>项
|
|
<% elsif pq.max_choices != 0 %>
|
|
答题时最多选<%=pq.max_choices %>项
|
|
<% end %>
|
|
<span class="c_red ml10" id="mcq_notice_<%=pq.id %>"></span>
|
|
</p>
|
|
<% end %>
|
|
</div>
|
|
<div class="cl"></div>
|
|
<div class="ur_inputs">
|
|
<table class="ur_table" style="width:675px;">
|
|
<tbody>
|
|
<% pq.poll_answers.each do |pa| %>
|
|
<tr>
|
|
<td>
|
|
<label>
|
|
<script>
|
|
function onblur_<%= pa.id %>(obj) {
|
|
$(window).unbind('beforeunload');
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_question_id: <%= pq.id %>,
|
|
poll_answer_id: <%= pa.id %>,
|
|
vote_text: obj.value
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
//document.getElementById("poll_vote_<%#=pq.id %>poll_answer_id_<%#=pa.id %>").checked = true;
|
|
//var span = $('#percent');
|
|
//span.html(dataObj.percent);
|
|
}
|
|
});
|
|
}
|
|
function click_<%= pa.id %>(obj) {
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_answer_id: <%= pa.id %>,
|
|
poll_question_id: <%= pq.id %>
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
if (dataObj.text == "ok") {
|
|
obj.checked = true;
|
|
$(obj).next('input').removeAttr("disabled");
|
|
$("#mcq_notice_<%=pq.id %>").html("");
|
|
}
|
|
else {
|
|
obj.checked = false;
|
|
$(obj).next('input').attr("disabled", "disabled");
|
|
if(dataObj.text == "over"){
|
|
$("#mcq_notice_<%=pq.id %>").html("该题最多只能选择<%=pq.max_choices %>个选项");
|
|
}else{
|
|
$("#mcq_notice_<%=pq.id %>").html("");
|
|
}
|
|
}
|
|
var span = $('#percent');
|
|
span.html(dataObj.percent);
|
|
},
|
|
error: function () {
|
|
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<input class="ur_radio" id="poll_vote_<%= pq.id %>poll_answer_id_<%= pa.id %>" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa, User.current) ? "checked" : "" %> <%= @can_edit_poll ? "" : "disabled=disabled" %> >
|
|
<% if pa.answer_text == "" %>
|
|
<input class="ur_text ur_textbox" type="text" size="" maxlength="" style="width: 93%" value="<%= get_anwser_vote_text(pq.id, User.current.id, pa.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= (@can_edit_poll && answer_be_selected?(pa, User.current)) ? "" : "disabled=disabled" %> placeholder="其他">
|
|
<% else %>
|
|
<%= pa.answer_text %>
|
|
<% end %>
|
|
</label>
|
|
</td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<!--多选题显示 end-->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<% elsif pq.question_type == 3 %>
|
|
<!-- 单行文字-->
|
|
<div class="testStatus">
|
|
<div id="poll_questions_<%= pq.id %>">
|
|
<div id="show_poll_questions_<%= pq.id %>">
|
|
<div>
|
|
<div class="testEditTitle">
|
|
<%= l(:label_question_number, :question_number => pq.question_number) %>
|
|
<%= pq.question_title %>
|
|
<span class="fontBlue">[主观题]</span>
|
|
<% if pq.is_necessary == 1 %>
|
|
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
|
|
<% end %>
|
|
</div>
|
|
<div class="cl"></div>
|
|
<div>
|
|
<script>
|
|
function onblur_<%= pq.id %>(obj) {
|
|
$(window).unbind('beforeunload');
|
|
var val = $(obj).val().trim();
|
|
if (val != "") {
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_question_id: <%= pq.id %>,
|
|
vote_text: obj.value
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
obj.value = dataObj.text;
|
|
var span = $('#percent');
|
|
span.html(dataObj.percent);
|
|
},
|
|
error: function () {
|
|
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
<textarea class="fillInput" placeholder="在此填入答案" type="text" style="height:54px" value="<%= get_anwser_vote_text(pq.id, User.current.id).html_safe %>" onblur="onblur_<%= pq.id %>(this);" <%= @can_edit_poll ? "" : "disabled=disabled" %>></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<% elsif pq.question_type == 4 %>
|
|
<!-- 多行文字-->
|
|
<div class="testStatus">
|
|
<div id="poll_questions_<%= pq.id %>">
|
|
<div id="show_poll_questions_<%= pq.id %>">
|
|
<div>
|
|
<div class="testEditTitle">
|
|
<%= l(:label_question_number, :question_number => pq.question_number) %>
|
|
<%= pq.question_title %>
|
|
<span class="fontBlue">[多行主观题]</span>
|
|
<% if pq.is_necessary == 1 %>
|
|
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
|
|
<% end %>
|
|
</div>
|
|
<div class="cl"></div>
|
|
<% pq.poll_answers.each_with_index do |pa, i| %>
|
|
<div class="ml20 mb10">
|
|
<script>
|
|
function onblur_<%= pa.id %>(obj) {
|
|
$(window).unbind('beforeunload');
|
|
var val = $(obj).val().trim();
|
|
if (val != "") {
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= commit_answer_poll_path(@poll) %>",
|
|
data: {
|
|
poll_question_id: <%= pq.id %>,
|
|
poll_answer_id: <%= pa.id %>,
|
|
vote_text: obj.value
|
|
},
|
|
success: function (data) {
|
|
var dataObj = eval(data);
|
|
obj.value = dataObj.text;
|
|
var span = $('#percent');
|
|
span.html(dataObj.percent);
|
|
},
|
|
error: function () {
|
|
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
<p class="mb10"><%= i + 1 %>.<%= pa.answer_text %></p>
|
|
<input class="questionnaire-input" placeholder="在此填入答案" style="width: 99%" type="text" value="<%= get_anwser_vote_text(pq.id, User.current.id, pa.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= @can_edit_poll ? "" : "disabled=disabled" %>>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<% else %>
|
|
<!-- 未知题型 -->
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<% if @can_edit_poll %>
|
|
<div class="ur_buttons" style="width: 77px;">
|
|
<% if @poll.polls_status == 2 %>
|
|
<a href="javascript:void(0)" class="BlueCirBtn" onclick="commit_poll();"><%=l(:button_submit) %></a>
|
|
<%#= link_to l(:button_submit), commit_poll_poll_path(@poll), :method => :post, :class => "BlueCirBtn", :format => 'js', :remote => true %>
|
|
<% end %>
|
|
</div>
|
|
<div class="cl"></div>
|
|
<div class="ur_progress_text">
|
|
<%= l(:label_complete_question) %>
|
|
<strong class="ur_progress_number">
|
|
<span id="percent"><%= format "%.2f", @percent %></span>%
|
|
</strong>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<!--问卷内容end-->
|
|
</div>
|
|
<script>
|
|
function check_mcq(){
|
|
var result = true;
|
|
<% @poll.poll_questions.where("question_type = 2").each do |pq| %>
|
|
$("#mcq_notice_<%=pq.id %>").html("");
|
|
<% if pq.min_choices != 0 %>
|
|
var count = $("#show_poll_questions_<%= pq.id %>").find("input[type='checkbox']:checked").length;
|
|
if(count < <%=pq.min_choices %>) {
|
|
$("#mcq_notice_<%=pq.id %>").html("该题最少选择<%=pq.min_choices %>个选项");
|
|
result = false;
|
|
} else{
|
|
$("#mcq_notice_<%=pq.id %>").html("");
|
|
}
|
|
<% end %>
|
|
<% end %>
|
|
if(!result){
|
|
alert("您的多选题答题不符合要求,请检查后再提交");
|
|
}
|
|
return result;
|
|
}
|
|
function commit_poll(){
|
|
if(check_mcq()){
|
|
$.post('<%=commit_poll_poll_path(@poll) %>');
|
|
}
|
|
}
|
|
</script> |