diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fe9318006..dcb330b3b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -31,17 +31,21 @@ class CoursesController < ApplicationController def join if User.current.logged? - if params[:role] == 10 + # if params[:role] == 10 cs = CoursesService.new @user = User.current - join = cs.join_course params,user + join = cs.join_course params,@user @state = join[:state] @course = join[:course] - else - @course = Course.find_by_id params[:object_id] - CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') - @state = 6 - end + # else + # if params[:course_password] == course.password + # @course = Course.find_by_id params[:object_id] + # CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest') + # @state = 6 + # else + # @state = 1 #密码错误 + # end + # end else @state = 5 #未登录 end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7adba7cbf..f09494968 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -239,6 +239,45 @@ class UsersController < ApplicationController end end + #处理加入课程成为教辅教师的请求 + #status 1 同意 2 拒绝 + def dealwith_apply_request + @msg = CourseMessage.find(params[:msg_id]) + case params[:agree] + when 'Y' + apply_user = User.find(@msg.course_message_id) + + if apply_user.member_of_course?(Course.find(@msg.course_id)) + #将角色改为老师或者教辅 + member = Course.find(@msg.course_id).members.where(:user_id=>apply_user.id).all[0] + member.role_ids = [@msg.content] # msg content保存的是申请的职位角色 + #删除为学生的记录 + joined = StudentsForCourse.where('student_id = ? and course_id = ?', member.user_id,@msg.course_id) + joined.each do |join| + join.delete + end + + member.course_group_id = 0 + member.save + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) + @msg.update_attributes(:status=>1) + else + members = [] + members << Member.new(:role_ids => [@msg.content.to_i], :user_id => @msg.course_message_id) + Course.find(@msg.course_id).members << members + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1) + @msg.update_attributes(:status=>1) + end + + when 'N' + CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2) + @msg.update_attributes(:status=>2) + end + respond_to do |format| + format.js + end + end + # added by bai def show_score diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 4639f1c2b..277d5a545 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -308,15 +308,27 @@ class CoursesService if course_endTime_timeout? course @state = 2 else - if current_user.member_of_course?(course) - @state = 3 + if current_user.member_of_course?(course) #如果已经是成员 + #如果加入角色为学生 + if params[:role] == 10 + @state = 3 + else + #如果加入角色为教师或者教辅 + CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) + @state = 6 + end else if params[:course_password] == course.password - members = [] - members << Member.new(:role_ids => [10], :user_id => current_user.id) - course.members << members - StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) - @state = 0 + if params[:role] == 10 + members = [] + members << Member.new(:role_ids => [10], :user_id => current_user.id) + course.members << members + StudentsForCourse.create(:student_id => current_user.id, :course_id => params[:object_id]) + @state = 0 + else + CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest',:status=>0) + @state = 6 + end else @state = 1 end diff --git a/app/views/courses/join.js.erb b/app/views/courses/join.js.erb index 64b1ffd4c..b4e6a98ec 100644 --- a/app/views/courses/join.js.erb +++ b/app/views/courses/join.js.erb @@ -5,15 +5,15 @@ $("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(@c <% if @state == 0 %> alert("加入成功"); hideModal($("#popbox02")); -$("#try_join_course_link").replaceWith(" 'index',:course=>course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品"); -window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" +$("#try_join_course_link").replaceWith(" 'index',:course=>@course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品"); +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 1 %> alert("密码错误"); <% elsif @state == 2 %> alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)"); <% elsif @state == 3 %> alert("您已经加入了课程"); -window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>" +window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= @course.id%>" <% elsif @state == 4 %> alert("您加入的课程不存在"); <% elsif @state == 5 %> diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb index 86b44f66d..b98e3be53 100644 --- a/app/views/users/_user_message_course.html.erb +++ b/app/views/users/_user_message_course.html.erb @@ -428,4 +428,71 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> + <% if ma.course_message_type == "JoinCourseRequest" %> + + <% end %> + <% if ma.course_message_type == "CourseRequestDealResult" %> + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/users/dealwith_apply_request.js.erb b/app/views/users/dealwith_apply_request.js.erb new file mode 100644 index 000000000..e31c0be85 --- /dev/null +++ b/app/views/users/dealwith_apply_request.js.erb @@ -0,0 +1,11 @@ +$("#deal_info_<%=@msg.id%>").html( +<% if @msg.status == 0 || @msg.status.nil?%> +<%= link_to '同意',dealwith_apply_request_user_path(User.current,:agree=>'Y',:msg_id=>@msg.id),:remote=>'true'%> +'|' +<%= link_to '拒绝',dealwith_apply_request_user_path(User.current,:agree=>'N',:msg_id=>@msg.id),:remote=>'true'%> +<% elsif @msg.status == 1%> + '您已经同意了该申请' +<% elsif @msg.status == 2%> + '您已经拒绝了该申请' +<%end %> +); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 810c22e7a..cb9e81c01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -388,6 +388,7 @@ RedmineApp::Application.routes.draw do get 'user_ref_resource_search' post 'import_resources_to_homework' get 'store_selected_resource' + get 'dealwith_apply_request' # end end end