删除学生/退出班级时隐藏学生作品、退出班级按钮位置调整

This commit is contained in:
cxt 2016-11-17 10:23:13 +08:00
parent ef9b389cfc
commit efd0bf6707
10 changed files with 55 additions and 8 deletions

View File

@ -561,6 +561,7 @@ class CoursesController < ApplicationController
def delete_member def delete_member
member = @course.members.find params[:member_id] member = @course.members.find params[:member_id]
student_role = member.member_roles.where("role_id = 10").first student_role = member.member_roles.where("role_id = 10").first
teacher_role = member.member_roles.where("role_id = 7 || role_id = 9").first
if member && member.deletable? && student_role if member && member.deletable? && student_role
user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id) user_admin = CourseInfos.where("user_id = ? and course_id = ?", member.user_id, @course.id)
if user_admin.size > 0 if user_admin.size > 0
@ -569,8 +570,9 @@ class CoursesController < ApplicationController
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.destroy_all joined.destroy_all
if member.member_roles.count > 1 if member.member_roles.count > 1&& student_role && teacher_role
student_role.destroy student_role.destroy
teacher_role.update_attribute("is_current", 1)
member.update_attribute("course_group_id", 0) member.update_attribute("course_group_id", 0)
else else
member.destroy member.destroy

View File

@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base
has_one :homework_detail_group, :dependent => :destroy has_one :homework_detail_group, :dependent => :destroy
has_many :student_work_projects, :dependent => :destroy has_many :student_work_projects, :dependent => :destroy
has_many :homework_tests, :dependent => :destroy has_many :homework_tests, :dependent => :destroy
has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works, :dependent => :destroy, :conditions => "is_test=0 and is_delete != 1"
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表
has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :apply_homeworks, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy

View File

@ -9,11 +9,21 @@ class StudentsForCourse < ActiveRecord::Base
validates_uniqueness_of :student_id, :scope => :course_id validates_uniqueness_of :student_id, :scope => :course_id
after_destroy :delete_student_works after_destroy :delete_student_works
after_create :recovery_student_works
#退出班级或删除学生时隐藏学生的作品
def delete_student_works def delete_student_works
course = self.course course = self.course
homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")" 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 = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}")
student_works.destroy_all student_works.update_all(:is_delete => 1)
end
#加入班级时还原作品
def recovery_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.update_all(:is_delete => 0)
end end
end end

View File

@ -452,12 +452,20 @@ class CoursesService
@state = 2 @state = 2
return @state return @state
end end
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id) @member = Member.where('course_id = ? and user_id = ?', params[:object_id], user.id).first
if @member.nil? || @member.count == 0 if @member.nil?
@state = 1 @state = 1
return @state return @state
end end
@member.first.destroy student_role = @member.member_roles.where("role_id = 10").first
teacher_role = @member.member_roles.where("role_id = 7 || role_id = 9").first
if @member.member_roles.count > 1 && student_role && teacher_role
student_role.destroy
teacher_role.update_attribute("is_current", 1)
@member.update_attribute("course_group_id", 0)
else
@member.destroy
end
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.destroy join.destroy

View File

@ -1,3 +1,4 @@
hideModal();
<% if object_id && @state != 6%> <% if object_id && @state != 6%>
$("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>"); $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>");
<% end %> <% end %>

View File

@ -26,6 +26,18 @@
</li> </li>
</ul> </ul>
</div> </div>
<% elsif User.current.logged? && User.current.member_of_course?(@course) %>
<div class="sy_class_setting" >
<ul>
<li class="sy_class_setting_icon">
<ul class="sy_class_setting_text">
<li>
<a href="javascript:void(0)" onclick="delete_confirm();" class="sy_class_option">退出班级</a>
</li>
</ul>
</li>
</ul>
</div>
<% end %> <% end %>
<div class="cl"></div> <div class="cl"></div>
@ -84,7 +96,7 @@
<% elsif is_teacher && is_ST %> <% elsif is_teacher && is_ST %>
<%= link_to '学生身份', switch_role_course_path(@course, :user_id => User.current.id, :curr_role => (is_TA ? 7 : 9), :tar_role => 10), :class => "sy_btn_orange mr10 fl", :title => "由教师身份切换至学生身份" %> <%= link_to '学生身份', switch_role_course_path(@course, :user_id => User.current.id, :curr_role => (is_TA ? 7 : 9), :tar_role => 10), :class => "sy_btn_orange mr10 fl", :title => "由教师身份切换至学生身份" %>
<% end %> <% end %>
<% unless (is_teacher || is_TA || is_TE) %> <% unless (is_teacher || is_TA || is_TE || is_ST) %>
<div id="join_in_course_header"><%= join_in_course_header(@course, User.current) %></div> <div id="join_in_course_header"><%= join_in_course_header(@course, User.current) %></div>
<% end %> <% end %>
</div> </div>

View File

@ -276,6 +276,13 @@
$("#expand_tools_expand a").addClass('active'); $("#expand_tools_expand a").addClass('active');
$("#navContentCourse").toggle(); $("#navContentCourse").toggle();
}); });
function delete_confirm(){
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 f14">您确认要退出该班级吗?</p><div class="cl"></div><a href="<%=join_path(:object_id => @course.id) %>" class="fr sy_btn_blue mr85 mt10" data-method="delete" data-remote="true">确&nbsp;&nbsp;定</a>'+
'<a href="javascript:void(0);" class="fr sy_btn_grey mt10 mr10" onclick="hideModal();">取&nbsp;&nbsp;消</a></div></div>';
pop_box_new(htmlvalue, 300, 140);
}
</script> </script>
</html> </html>

View File

@ -0,0 +1,5 @@
class AddIsDeleteToStudentWorks < ActiveRecord::Migration
def change
add_column :student_works, :is_delete, :integer, :default => 0
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20161114092115) do ActiveRecord::Schema.define(:version => 20161117015856) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -1910,6 +1910,7 @@ ActiveRecord::Schema.define(:version => 20161114092115) do
t.float "work_score" t.float "work_score"
t.integer "work_status", :default => 0 t.integer "work_status", :default => 0
t.datetime "commit_time" t.datetime "commit_time"
t.integer "is_delete", :default => 0
end end
add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id" add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id"

View File

@ -169,6 +169,7 @@ h4{ font-size:14px;}/*color:#3b3b3b;*/
.mr70{margin-right: 70px;} .mr70{margin-right: 70px;}
.mr75{margin-right: 75px;} .mr75{margin-right: 75px;}
.mr80{margin-right: 80px;} .mr80{margin-right: 80px;}
.mr85{margin-right: 85px;}
.mr95 {margin-right:95px !important;} .mr95 {margin-right:95px !important;}
.mr100 {margin-right:100px !important;} .mr100 {margin-right:100px !important;}
.mr118 {margin-right:118px !important;} .mr118 {margin-right:118px !important;}