1.增加课程留言界面的路由

2.增加点击已批作业、未批作业、全部作业、留言的ajax调用
3.实现点击已批作业、未批作业、全部作业、留言时界面切换
This commit is contained in:
sw 2014-10-30 16:33:14 +08:00
parent afa1ef22d5
commit 3fa5a4b3c5
9 changed files with 91 additions and 100 deletions

View File

@ -4,14 +4,61 @@ class HomeworkAttachController < ApplicationController
###############################
before_filter :can_show_course,except: []
#判断当前角色权限时需先找到当前操作的project
before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework]
before_filter :find_course_by_bid_id, :only => [:new,:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
#判断当前角色是否有操作权限
#勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
#获取未批作业列表
def get_not_batch_homework
@homeworks = HomeworkAttach.all
teachers = find_course_teachers @course
limit = 10
start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit
@homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY s_score DESC,created_at ASC
limit #{start_item}, #{limit}")
respond_to do |format|
format.js
end
end
#获取已评作业列表
def get_batch_homeworks
teachers = find_course_teachers @course
limit = 10
start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit
@homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY s_score DESC,created_at ASC
limit #{start_item}, #{limit}")
respond_to do |format|
format.js
end
end
#获取所有作业列表
def get_homeworks
teachers = find_course_teachers @course
limit = 10
start_item = params['page'].nil? ? 0 : (params['page'].to_i - 1) * limit
@homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY s_score DESC,created_at ASC
limit #{start_item}, #{limit}")
respond_to do |format|
format.js
end
end
#获取作业的留言列表
def get_homework_jours
respond_to do |format|
format.js
end
@ -328,7 +375,7 @@ class HomeworkAttachController < ApplicationController
def find_course_by_bid_id
@bid = Bid.find(params[:id])
@course = @bid.courses[0]
@course = @bid.courses.first
rescue ActiveRecord::RecordNotFound
render_404
end
@ -337,5 +384,19 @@ class HomeworkAttachController < ApplicationController
@homework = HomeworkAttach.find(params[:id])
@course = @homework.bid.courses[0]
end
#获取课程的老师列表
def find_course_teachers course
teachers = "("
teacher_members = searchTeacherAndAssistant(course)
teacher_members.each do |member|
if member == teacher_members.last
teachers += member.user_id.to_s + ")"
else
teachers += member.user_id.to_s + ","
end
end
teachers
end
end

View File

@ -2,20 +2,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>作业列表页_老师界面</title>
<script type="text/javascript" language="javascript">
function g(o){return document.getElementById(o);}
function HoverLi(n){
for(var i=1;i<=5;i++){g('tb_'+i).className='normaltab';g('tbc_0'+i).className='undis';}g('tbc_0'+n).className='dis';g('tb_'+n).className='hovertab';
}
function get_not_batch_homework() {
$.ajax({
type: "POST",
url: '<%= %>',
data: 'text',
success: function (data) {
alert("1111")
}
})
for(var i=1;i<=5;i++){$("#tb_"+i).className("normaltab");}$("#tb_"+n).className("hovertab");
}
</script>
<%= stylesheet_link_tag 'css', :media => 'all' %>
@ -28,97 +16,24 @@
<li id="tb_1" class="hovertab" onclick="a:HoverLi(1);">
<%= link_to "未批作业", get_not_batch_homework_homework_attach_path(@bid), {:remote => true}%>
</li>
<li id="tb_2" class="normaltab" onclick="a:HoverLi(2);">已改作业</li>
<li id="tb_3" class="normaltab" onclick="a:HoverLi(3);">全部作业</li>
<li id="tb_2" class="normaltab" onclick="a:HoverLi(2);">
<%= link_to "已改作业", get_batch_homeworks_homework_attach_path(@bid), {:remote => true}%>
</li>
<li id="tb_3" class="normaltab" onclick="a:HoverLi(3);">
<%= link_to "全部作业", get_homeworks_homework_attach_path(@bid), {:remote => true}%>
</li>
<li id="tb_4" class="normaltab" onclick="o:HoverLi(4);"><a href="#">作业下载</a></li>
<li id="tb_5" class="normaltab" onclick="g:HoverLi(5);">留言(<span class="c_red f_12">23</span>)</li>
<li id="tb_5" class="normaltab" onclick="g:HoverLi(5);">
<%= link_to "留言", get_homework_jours_homework_attach_path(@bid), {:remote => true}%>
(<span class="c_red f_12">23</span>)
</li>
</ul>
</div>
<div class="cl"></div>
<div class="ctt">
<div class="dis" id="tbc_01">
<%= render :partial => 'homework_attach/not_batch_homwork', :locals => {:homeworks => homework}%>
<%= render :partial => 'homework_attach/homeworks_list', :locals => {:homeworks => homework}%>
</div><!---未批作业结束-->
<div class="undis" id="tbc_02">
<div class="code_list"><span>作品列表(<font color="#CC0000">2</font>)</span><span class="fr">按&nbsp;<a href="#">评分</a>&nbsp;/&nbsp;<a href="#">时间</a>&nbsp;排序</span></div>
<div class="cl"></div>
<ul>
<li class="pic_head"><a href="#" target="_blank"><img src="images/225905790.jpg" width="40" height="40" /><span>gugu01</span></a></li>
<li class="wname"><a href="#" target="_blank">科大校园助手最终提交文档及源码科大校园助手最终提交文档及源码</a></li>
<li class="wdown"><a href="#" target="_blank">5个附件</a></li>
<li class="wscore">教师评分:<span class="c_red">4.8</span>&nbsp;&nbsp;</li>
<li class="wscore">学生评分:<span class="c_red">未评分</span></li>
<li class="wping"><a href="#" target="_blank">评分</a></li>
</ul>
<div class="cl"></div>
<ul>
<li class="pic_head"><a href="#" target="_blank"><img src="images/225905790.jpg" width="40" height="40" /><span>gugu01</span></a></li>
<li class="wname"><a href="#" target="_blank">科大校园助手最终提交文档及源码科大校园助手最终提交文档及源码</a></li>
<li class="wdown"><a href="#" target="_blank">5个附件</a></li>
<li class="wscore">教师评分:<span class="c_red">4.8</span>&nbsp;&nbsp;</li>
<li class="wscore">学生评分:<span class="c_red">未评分</span></li>
<li class="wping"><a href="#" target="_blank">评分</a><span class="c_red">&nbsp;&nbsp;迟交!</span></li>
</ul>
<div class="cl"></div>
<ul class="wlist">
<li><a href="#">上一页</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">...</a></li>
<li><a href="#">下一页</a></li>
</ul>
<div class="cl"></div>
</div><!---已改作业结束-->
<div class="undis" id="tbc_03">
<div class="code_list"><span>作品列表(<font color="#CC0000">3</font>)</span><span class="fr">按&nbsp;<a href="#">评分</a>&nbsp;/&nbsp;<a href="#">时间</a>&nbsp;排序</span></div>
<div class="cl"></div>
<ul>
<li class="pic_head"><a href="#" target="_blank"><img src="images/225905790.jpg" width="40" height="40" /><span>gugu01</span></a></li>
<li class="wname"><a href="#" target="_blank">科大校园助手最终提交文档及源码科大校园助手最终提交文档及源码</a></li>
<li class="wdown"><a href="#" target="_blank">5个附件</a></li>
<li class="wscore">教师评分:<span class="c_red">4.8</span>&nbsp;&nbsp;</li>
<li class="wscore">学生评分:<span class="c_red">未评分</span></li>
<li class="wping"><a href="#" target="_blank">评分</a></li>
</ul>
<div class="cl"></div>
<ul>
<li class="pic_head"><a href="#" target="_blank"><img src="images/225905790.jpg" width="40" height="40" /><span>gugu01</span></a></li>
<li class="wname"><a href="#" target="_blank">科大校园助手最终提交文档及源码科大校园助手最终提交文档及源码</a></li>
<li class="wdown"><a href="#" target="_blank">5个附件</a></li>
<li class="wscore">教师评分:<span class="c_red">4.8</span>&nbsp;&nbsp;</li>
<li class="wscore">学生评分:<span class="c_red">未评分</span></li>
<li class="wping"><a href="#" target="_blank">评分</a></li>
</ul>
<div class="cl"></div>
<ul>
<li class="pic_head"><a href="#" target="_blank"><img src="images/225905790.jpg" width="40" height="40" /><span>gugu01</span></a></li>
<li class="wname"><a href="#" target="_blank">科大校园助手最终提交文档及源码科大校园助手最终提交文档及源码</a></li>
<li class="wdown"><a href="#" target="_blank">5个附件</a></li>
<li class="wscore">教师评分:<span class="c_red">4.8</span>&nbsp;&nbsp;</li>
<li class="wscore">学生评分:<span class="c_red">未评分</span></li>
<li class="wping"><a href="#" target="_blank">评分</a><span class="c_red">&nbsp;&nbsp;迟交!</span></li>
</ul>
<div class="cl"></div>
<ul class="wlist">
<li><a href="#">上一页</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">...</a></li>
<li><a href="#">下一页</a></li>
</ul>
<div class="cl"></div>
</div><!---全部作业结束-->
<div class="undis" id="tbc_04"></div><!---作业下载结束-->
<div class="undis" id="tbc_05">
<div class="msg_box">
<h4>留言内容</h4>
<textarea id="ta_msg_content" name="content" placeholder="最多250个字" ></textarea>
<a href="#">取&nbsp;&nbsp;消</a><a href="#">留&nbsp;&nbsp;言</a>
</div>
<div class="msg_list"></div>
</div><!---留言结束-->
</div>
</div>
</div>

View File

@ -0,0 +1,7 @@
<div class="msg_box">
<h4>留言内容</h4>
<textarea id="ta_msg_content" name="content" placeholder="最多250个字" ></textarea>
<a href="#">取&nbsp;&nbsp;消</a><a href="#">留&nbsp;&nbsp;言</a>
</div>
<div class="msg_list"></div>

View File

@ -0,0 +1 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>');

View File

@ -0,0 +1 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homework_jours' )) %>');

View File

@ -0,0 +1,2 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>');

View File

@ -0,0 +1 @@
$('#tbc_01').html('<%= escape_javascript(render(:partial => 'homeworks_list', :locals => {:homeworks => @homework_list} )) %>');

View File

@ -47,6 +47,9 @@ RedmineApp::Application.routes.draw do
end
member do
get 'get_not_batch_homework'
get 'get_batch_homeworks'
get 'get_homeworks'
get 'get_homework_jours'
match 'add_homework_users', :via => [:get,:post]
match 'destory_homework_users', :via => [:get,:post]
end