Merge branch 'Poll' of http://repository.trustie.net/xianbo/trustie2 into Poll
This commit is contained in:
commit
40d6ebfd88
|
@ -1,5 +1,5 @@
|
|||
class PollController < ApplicationController
|
||||
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll]
|
||||
before_filter :find_poll_and_course, :only => [:edit,:update,:destroy,:show,:statistics_result,:create_poll_question,:commit_poll,:commit_answer]
|
||||
before_filter :find_container, :only => [:new,:create, :index]
|
||||
before_filter :is_member_of_course, :only => [:index,:show]
|
||||
before_filter :is_course_teacher, :only => [:new,:create,:edit,:update,:destroy]
|
||||
|
@ -19,12 +19,18 @@ class PollController < ApplicationController
|
|||
|
||||
def show
|
||||
@poll = Poll.find params[:id]
|
||||
#已提交问卷的用户不能再访问该界面
|
||||
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
|
||||
render_403
|
||||
else
|
||||
@can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
|
||||
poll_questions = @poll.poll_questions
|
||||
@poll_questions = paginateHelper poll_questions,3 #分页
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
if @course
|
||||
|
@ -165,6 +171,10 @@ class PollController < ApplicationController
|
|||
#提交答案
|
||||
def commit_answer
|
||||
pq = PollQuestion.find(params[:poll_question_id])
|
||||
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
|
||||
render :text => 'failure'
|
||||
return
|
||||
end
|
||||
if pq.question_type == 1
|
||||
#单选题
|
||||
pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
|
||||
|
@ -212,15 +222,8 @@ class PollController < ApplicationController
|
|||
render :text => "failure"
|
||||
end
|
||||
else
|
||||
|
||||
render :text => "failure"
|
||||
end
|
||||
|
||||
|
||||
#respond_to do |format|
|
||||
# format.js
|
||||
# format.json
|
||||
#end
|
||||
|
||||
end
|
||||
|
||||
#提交问卷
|
||||
|
@ -232,9 +235,12 @@ class PollController < ApplicationController
|
|||
pu.poll_id = @poll.id
|
||||
if pu.save
|
||||
#redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
|
||||
@status = 0 #提交成功
|
||||
else
|
||||
@status = 2 #未知错误
|
||||
end
|
||||
else
|
||||
|
||||
@status = 1 #有未做得必答题
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
|
@ -37,4 +37,14 @@ module PollHelper
|
|||
pv.vote_text
|
||||
end
|
||||
end
|
||||
|
||||
#判断用户是否已经提交了问卷
|
||||
def has_commit_poll?(poll_id,user_id)
|
||||
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
|
||||
if pu.nil?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,12 @@
|
|||
<div id="popbox">
|
||||
shaksdkfdks
|
||||
<div id="popbox" style="text-align: center;margin-top: 25px">
|
||||
<% if status == 0 %>
|
||||
<h3 style="font-weight: normal;color: green">提交成功!</h3>
|
||||
<%= link_to "确定", poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course'),:class => 'commit'%>
|
||||
<% elsif status == 1 %>
|
||||
<h3 style="font-weight: normal;color: red">您还有尚未作答的题目请完成后在提交!</h3>
|
||||
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
|
||||
<% else %>
|
||||
<h3 style="font-weight: normal;color: red">发生未知错误,请检查您的网络。</h3>
|
||||
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert') %>');
|
||||
showModal('ajax-modal', '513px');
|
||||
$('#ajax-modal').css('height','200px');
|
||||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>');
|
||||
showModal('ajax-modal', '400px');
|
||||
$('#ajax-modal').css('height','100px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<span style='float: right;cursor:pointer;padding-left: 513px;'>" +
|
||||
$('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
|
||||
"<a href='#' onclick='hidden_atert_form();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
|
||||
$('#ajax-modal').parent().removeClass("alert_praise");
|
||||
$('#ajax-modal').parent().css("top","50%").css("left","20%");
|
||||
$('#ajax-modal').parent().css("position","absolute");
|
||||
$('#ajax-modal').parent().css("top","").css("left","");
|
||||
$('#ajax-modal').parent().addClass("alert_box");
|
|
@ -13,7 +13,11 @@
|
|||
<% @polls.each do |poll|%>
|
||||
<ul id="polls_<%= poll.id %>">
|
||||
<li>
|
||||
<% if has_commit_poll?(poll.id ,User.current) %>
|
||||
<sapn class="polls_title fl"> <%= poll.polls_name %></sapn>
|
||||
<% else %>
|
||||
<%= link_to poll.polls_name, poll_path(poll.id), :class => "polls_title fl" %>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%if @is_teacher%>
|
||||
|
|
|
@ -4,6 +4,21 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>问卷调查_问卷页面</title>
|
||||
<%= stylesheet_link_tag 'polls', :media => 'all' %>
|
||||
<style type="text/css">
|
||||
.alert_box{width:480px;height:180px;position:fixed;z-index:100;left:55%;top:50%;margin:-215px 0 0 -300px; background:#fff; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 8px #194a81; overflow:auto;}
|
||||
.commit{
|
||||
height: 28px;
|
||||
display: block;
|
||||
width: 80px;
|
||||
color: #fff !important;
|
||||
background: #15bccf;
|
||||
text-align: center;
|
||||
padding-top: 4px;
|
||||
margin-left: 130px;
|
||||
margin-top: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function hidden_atert_form(cur_page,cur_type)
|
||||
{
|
||||
|
@ -62,7 +77,7 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
<%= radio_button "poll_vote","poll_answer_id",pa.id,:class=>"ur_radio",:onclick =>"click_#{pa.id}(this);return false;",:checked => answer_be_selected?(pa,User.current) %>
|
||||
<%= radio_button "poll_vote","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 %>
|
||||
<%= pa.answer_text %>
|
||||
</label>
|
||||
</td>
|
||||
|
@ -115,7 +130,7 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
<input class="ur_checkbox" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa,User.current) ? "checked":"" %>>
|
||||
<input class="ur_checkbox" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa,User.current) ? "checked":"" %> <%= @can_edit_poll?"":"disabled=disabled" %> >
|
||||
<%= pa.answer_text %>
|
||||
</label>
|
||||
</td>
|
||||
|
@ -156,7 +171,7 @@
|
|||
|
||||
}
|
||||
</script>
|
||||
<input class="ur_text ur_textbox" type="text" size="" maxlength="" value="<%= get_anwser_vote_text(pq.id,User.current.id) %>" onblur="onblur_<%= pq.id %>(this);">
|
||||
<input class="ur_text ur_textbox" type="text" size="" maxlength="" value="<%= get_anwser_vote_text(pq.id,User.current.id) %>" onblur="onblur_<%= pq.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %>>
|
||||
</div>
|
||||
</li><!--单行输入 end-->
|
||||
<% elsif pq.question_type == 4 %>
|
||||
|
@ -188,7 +203,7 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
<div contenteditable='true' class="ur_textbox" style="min-height: 150px;width: 100%" onblur="onblur_<%= pq.id %>(this);"><%= get_anwser_vote_text(pq.id,User.current.id) %></div>
|
||||
<div contenteditable='<%= @can_edit_poll %>' class="ur_textbox" style="min-height: 150px;width: 100%;<%= @can_edit_poll?"":"background-color:#DCDCDC;" %>" onblur="onblur_<%= pq.id %>(this);"><%= get_anwser_vote_text(pq.id,User.current.id) %></div>
|
||||
</div>
|
||||
</div>
|
||||
</li><!--多行输入 end-->
|
||||
|
|
|
@ -27,6 +27,7 @@ a.newbtn{ float:right; display:block; width:80px; height:30px; background:#64bdd
|
|||
a:hover.newbtn{ background:#55a1b9; text-decoration:none;}
|
||||
.polls_list ul{ padding-left:10px; border-bottom:1px dashed #c9c9c9; height:32px; padding-top:8px;}
|
||||
a.polls_title{ font-weight:bold; color:#3e6d8e;}
|
||||
.polls_title{ font-weight:bold; color:#3e6d8e;}
|
||||
a.pollsbtn{ display:block; width:66px; height:22px; text-align:center; border:1px solid #64bdd9; color:#64bdd9;}
|
||||
a:hover.pollsbtn{ background:#64bdd9; color:#fff; text-decoration:none;}
|
||||
.polls_date{ color:#666666;}
|
||||
|
|
Loading…
Reference in New Issue