学生列表增加删除功能、删除学生时删除其对应的作品

This commit is contained in:
cxt 2016-11-11 13:58:07 +08:00
parent 0d8d2fbc90
commit 07b97c8eb9
10 changed files with 82 additions and 20 deletions

View File

@ -558,6 +558,35 @@ class CoursesController < ApplicationController
end end
end end
def delete_member
member = @course.members.find params[:member_id]
student_role = member.member_roles.where("role_id = 10").first
if member && member.deletable? && student_role
user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id)
if user_admin.size > 0
user_admin.destroy_all
end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@course.id)
joined.destroy_all
if member.member_roles.count > 1
student_role.destroy
member.update_attribute("course_group_id", 0)
else
member.destroy
end
#移出课程发送消息
CourseMessage.create(:user_id => member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id)
@course_groups = @course.course_groups
@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count
@canShowCode = isCourseTeacher(User.current.id,@course)
respond_to do |format|
format.js
end
end
end
def handle_course courses, activities def handle_course courses, activities
course_activity_count_array=activities.values() course_activity_count_array=activities.values()
course_array=[] course_array=[]

View File

@ -337,7 +337,7 @@ class MembersController < ApplicationController
else else
joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
@member.course_group_id = 0 @member.course_group_id = 0
end end
@ -423,7 +423,7 @@ class MembersController < ApplicationController
end end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id) joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
@roles = Role.givable.all[3..5] @roles = Role.givable.all[3..5]
@members = @course.member_principals.includes(:roles, :principal).all.sort @members = @course.member_principals.includes(:roles, :principal).all.sort

View File

@ -125,7 +125,7 @@ class WatchersController < ApplicationController
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
end end
respond_to do |format| respond_to do |format|

View File

@ -8,4 +8,12 @@ class StudentsForCourse < ActiveRecord::Base
validates_presence_of :course_id, :student_id validates_presence_of :course_id, :student_id
validates_uniqueness_of :student_id, :scope => :course_id validates_uniqueness_of :student_id, :scope => :course_id
after_destroy :delete_student_works
def delete_student_works
course = self.course
homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}")
student_works.destroy_all
end
end end

View File

@ -207,7 +207,7 @@ class CoursesService
unless member.role_ids.include?(10) unless member.role_ids.include?(10)
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,c.id) joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,c.id)
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
end end
@ -460,7 +460,7 @@ class CoursesService
@member.first.destroy @member.first.destroy
joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', user.id, params[:object_id])
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
@state = 0 @state = 0
@state @state
@ -837,7 +837,7 @@ class CoursesService
member = Member.new(:role_ids =>[7], :user_id => params[:user_id],:course_id=>params[:course_id]) member = Member.new(:role_ids =>[7], :user_id => params[:user_id],:course_id=>params[:course_id])
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id) joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id)
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
member.course_group_id = 0 member.course_group_id = 0
members << member members << member
@ -858,7 +858,7 @@ class CoursesService
end end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:course_id])
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
end end
@ -1261,7 +1261,7 @@ class CoursesService
else else
joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:id]) joined = StudentsForCourse.where('student_id = ? and course_id = ?', params[:user_id],params[:id])
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
member.course_group_id = 0 member.course_group_id = 0
end end
@ -1305,7 +1305,7 @@ class CoursesService
end end
joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id) joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,course.id)
joined.each do |join| joined.each do |join|
join.delete join.destroy
end end
roles = Role.givable.all[3..5] roles = Role.givable.all[3..5]
#移出课程发送消息 #移出课程发送消息

View File

@ -1,8 +1,9 @@
<% is_teacher = User.current.allowed_to?(:as_teacher, @course) || User.current.admin? %>
<% if members.any? %> <% if members.any? %>
<table class="sy_new_table clear sy_new_table_width" cellpadding="0" cellspacing="0"> <table class="sy_new_table clear sy_new_table_width" cellpadding="0" cellspacing="0">
<thead> <thead>
<tr class="clear"> <tr class="clear">
<th class="sy_th7">序号</th> <th class="sy_th6">序号</th>
<th class="sy_th15">姓名</th> <th class="sy_th15">姓名</th>
<th class="sy_th15"> <th class="sy_th15">
<%= link_to '学号', member_score_sort_course_path(:sort_type => 'student_id', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%> <%= link_to '学号', member_score_sort_course_path(:sort_type => 'student_id', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%>
@ -12,7 +13,7 @@
<a href="javascript:void(0)" class="sy_sortdownbtn"></a> <a href="javascript:void(0)" class="sy_sortdownbtn"></a>
<% end %> <% end %>
</th> </th>
<th class="sy_th0 sy_fenban_tap"> <th class="<%= is_teacher ? 'sy_th0' : 'sy_th1' %> sy_fenban_tap">
<%= link_to '作业得分', member_score_sort_course_path(:sort_type => 'score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%> <%= link_to '作业得分', member_score_sort_course_path(:sort_type => 'score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%>
<% if @sort_type == "score" && @score_sort_by == 'desc' %> <% if @sort_type == "score" && @score_sort_by == 'desc' %>
<a href="javascript:void(0)" class="sy_sortupbtn"></a> <a href="javascript:void(0)" class="sy_sortupbtn"></a>
@ -24,7 +25,7 @@
班级作业的得分总和</p> 班级作业的得分总和</p>
</div> </div>
</th> </th>
<th class="sy_th0 sy_fenban_tap"> <th class="<%= is_teacher ? 'sy_th0' : 'sy_th1' %> sy_fenban_tap">
<%= link_to '测评得分', member_score_sort_course_path(:sort_type => 'ex_score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%> <%= link_to '测评得分', member_score_sort_course_path(:sort_type => 'ex_score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0), :search_name => (@search_name ? @search_name : nil)), :result => members, method: 'get', remote: true, :style => 'color:#000000;'%>
<% if @sort_type == "ex_score" && @score_sort_by == 'desc' %> <% if @sort_type == "ex_score" && @score_sort_by == 'desc' %>
<a href="javascript:void(0)" class="sy_sortupbtn"></a> <a href="javascript:void(0)" class="sy_sortupbtn"></a>
@ -36,7 +37,7 @@
班级测验的得分总和</p> 班级测验的得分总和</p>
</div> </div>
</th> </th>
<th class="sy_th0 sy_fenban_tap"> <th class="<%= is_teacher ? 'sy_th0' : 'sy_th1' %> sy_fenban_tap">
<%= link_to '社区得分', member_score_sort_course_path(:sort_type => 'act_score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true, :style => 'color:#000000;'%> <%= link_to '社区得分', member_score_sort_course_path(:sort_type => 'act_score', :sort_by => (@score_sort_by == "desc" ? "asc" : "desc"), :group_id => (@group ? (@group == -1 ? -1 : @group.id) : 0),:search_name => (@search_name ? @search_name : nil)) ,:result => members,method: 'get', remote: true, :style => 'color:#000000;'%>
<% if @sort_type == "act_score" && @score_sort_by == 'desc' %> <% if @sort_type == "act_score" && @score_sort_by == 'desc' %>
<a href="javascript:" class= "sy_sortupbtn"></a> <a href="javascript:" class= "sy_sortupbtn"></a>
@ -56,13 +57,16 @@
</p> </p>
</div> </div>
</th> </th>
<th class="sy_th0 sy_fenban_tap">总得分 <th class="<%= is_teacher ? 'sy_th0' : 'sy_th1' %> sy_fenban_tap">总得分
<div class="sy_fenban_show undis" style="width:180px;"> <div class="sy_fenban_show undis" style="width:180px;">
<p>积分规则<br/> <p>积分规则<br/>
作业得分+测评得分+社区得分</p> 作业得分+测评得分+社区得分</p>
</div> </div>
</th> </th>
<th class="sy_th13">分班</th> <th class="sy_th13">分班</th>
<% if is_teacher %>
<th class="sy_th3"></th>
<% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -98,10 +102,10 @@
</td> </td>
<td class="pr"> <td class="pr">
<span class="sum_score_tip"><%= format("%0.2f", sum) %></span> <span class="sum_score_tip"><%= format("%0.2f", sum) %></span>
<div class="sy_tips_box_inner undis" style="left: 215px; top: -60px; text-align: left;"> <div class="sy_tips_box_inner undis" style="left: <%=is_teacher ? '230px' : '215px' %>; top: -60px; text-align: left;">
<span style="top: 75px;"></span> <span style="top: 75px;"></span>
<p > <p >
<font class="fb"><%= user.show_name %></font><br/> <font class="fb"><%= user.show_name %>(<%=user.login %>)</font><br/>
资源&nbsp;&nbsp;&nbsp;&nbsp;发布数:<%= member.resource_num.nil? ? 0 : member.resource_num %><br/> 资源&nbsp;&nbsp;&nbsp;&nbsp;发布数:<%= member.resource_num.nil? ? 0 : member.resource_num %><br/>
<font class="mr15">问答&nbsp;&nbsp;&nbsp;&nbsp;发布数:<%= member.message_num.nil? ? 0 : member.message_num %></font>回复数:<%= member.message_reply_num.nil? ? 0 : member.message_reply_num %><br/> <font class="mr15">问答&nbsp;&nbsp;&nbsp;&nbsp;发布数:<%= member.message_num.nil? ? 0 : member.message_num %></font>回复数:<%= member.message_reply_num.nil? ? 0 : member.message_reply_num %><br/>
<font class="mr15">通知&nbsp;&nbsp;&nbsp;&nbsp;提交数:<%= member.news_num.nil? ? 0 : member.news_num %></font>留言数:<%= member.news_reply_num.nil? ? 0 : member.news_reply_num %><br/> <font class="mr15">通知&nbsp;&nbsp;&nbsp;&nbsp;提交数:<%= member.news_num.nil? ? 0 : member.news_num %></font>留言数:<%= member.news_reply_num.nil? ? 0 : member.news_reply_num %><br/>
@ -112,7 +116,7 @@
</div> </div>
</td> </td>
<td> <td>
<% if User.current.allowed_to?(:as_teacher, @course) || User.current.admin? || User.current == user %> <% if is_teacher || User.current == user %>
<% if @course.course_groups.empty? %> <% if @course.course_groups.empty? %>
<%=member.course_group_id == 0 ? "暂无" : member.course_group.name %> <%=member.course_group_id == 0 ? "暂无" : member.course_group.name %>
<% else %> <% else %>
@ -130,6 +134,11 @@
<%=member.course_group_id == 0 ? "暂无" : member.course_group.name %> <%=member.course_group_id == 0 ? "暂无" : member.course_group.name %>
<% end %> <% end %>
</td> </td>
<% if is_teacher %>
<td>
<a href="javascript:void(0)" onClick="delete_confirm_box('<%=delete_member_course_path(@course, :member_id => member.id) %>', '确认删除该成员吗?');" class="sy_icons_del fl"></a>
</td>
<% end %>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@ -0,0 +1,4 @@
hideModal();
$("#member_li_<%=params[:member_id] %>").html("");
$("#st_groups").html("<%=escape_javascript(render :partial => 'new_groups_name', :locals => {:course_groups => @course_groups}) %>");
$("#group_children_list").html("<%= escape_javascript( render :partial => 'layouts/group_children_list', :locals => {:course => @course})%>");

View File

@ -1238,6 +1238,7 @@ RedmineApp::Application.routes.draw do
get "switch_role" get "switch_role"
get 'search_not_group_member' get 'search_not_group_member'
post 'add_members' post 'add_members'
get 'delete_member'
end end
collection do collection do
match 'join_private_courses', :via => [:get, :post] match 'join_private_courses', :via => [:get, :post]

View File

@ -1768,6 +1768,15 @@ function expand_course_list(id, target, btnid, count) {
btn.parent().show(); btn.parent().show();
} }
} }
//点击删除时的确认弹框
function delete_confirm_box(url, str){
var htmlvalue = '<div id="muban_popup_box" style="width:300px;"><div class="muban_popup_top"><h3 class="fl">提示</h3><a href="javascript:void(0);" class="muban_icons_close fr"></a></div>'+
'<div class="clear mt15"><p class="text_c f16">' + str + '</p><div class="cl"></div><a href="'+ url +'" class="fr sy_btn_blue mr10 mt10" data-remote="true">确定</a>'+
'<a href="javascript:void(0);" class="fr sy_btn_grey mt10 mr10" onclick="hideModal();">取消</a></div></div>';
pop_box_new(htmlvalue, 300, 140);
}
//删除组织成员 //删除组织成员
function ifDeleteOrgMember(id,name){ function ifDeleteOrgMember(id,name){
var htmlvalue = "</br><div style='width:550px;text-align:center'>您确定要删除"+name+"吗?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='deleteOrgMember("+id+")'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div>" + var htmlvalue = "</br><div style='width:550px;text-align:center'>您确定要删除"+name+"吗?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='deleteOrgMember("+id+")'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div>" +

View File

@ -629,9 +629,11 @@ a:hover.sy_class_ltitle{ color:#333;}
.sy_class_users_st img{ width:30px;height:30px; border: 1px solid #fff;-webkit-border-radius:50px;-moz-border-radius:50px;-o-border-radius:50px;border-radius:50px;} .sy_class_users_st img{ width:30px;height:30px; border: 1px solid #fff;-webkit-border-radius:50px;-moz-border-radius:50px;-o-border-radius:50px;border-radius:50px;}
.sy_fenban_select{height: 28px; background-color: #fff; border: 1px solid #d1d1d1;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;border-radius:3px; border:1px solid #d3d3d3;padding-left:5px; color:#888; box-shadow: inset 0px 0px 5px #dcdcdc; } .sy_fenban_select{height: 28px; background-color: #fff; border: 1px solid #d1d1d1;-webkit-border-radius:3px;-moz-border-radius:3px;-o-border-radius:3px;border-radius:3px; border:1px solid #d3d3d3;padding-left:5px; color:#888; box-shadow: inset 0px 0px 5px #dcdcdc; }
.sy_new_table_width tr th.sy_th10{ width: 10%; } .sy_new_table_width tr th.sy_th10{ width: 10%; }
.sy_new_table_width tr th.sy_th0{ width: 12.5%; } .sy_new_table_width tr th.sy_th0{ width: 12%; }
.sy_new_table_width tr th.sy_th1{ width: 12.5%; }
.sy_new_table_width tr th.sy_th15{ width: 15%; } .sy_new_table_width tr th.sy_th15{ width: 15%; }
.sy_new_table_width tr th.sy_th7{ width: 7%;} .sy_new_table_width tr th.sy_th6{ width: 6%;}
.sy_new_table_width tr th.sy_th3{ width: 3%;}
.sy_new_table_width tr th.sy_th13{ width: 13%;} .sy_new_table_width tr th.sy_th13{ width: 13%;}
.sy_fenban_tap{ cursor: pointer; position: relative;} .sy_fenban_tap{ cursor: pointer; position: relative;}
.sy_fenban_tap:hover .sy_fenban_show{ display: block;} .sy_fenban_tap:hover .sy_fenban_show{ display: block;}