添加申请课程的加入身份
This commit is contained in:
parent
0fffed55a6
commit
e44d95cca5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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("<a href='<%=url_for(:controller => 'homework_common', :action => 'index',:course=>course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品</a>");
|
||||
window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>"
|
||||
$("#try_join_course_link").replaceWith("<a href='<%=url_for(:controller => 'homework_common', :action => 'index',:course=>@course.id, :host=>Setting.host_course)%>' target='_blank' class='blue_n_btn fr mt20'>提交作品</a>");
|
||||
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 %>
|
||||
|
|
|
@ -428,4 +428,71 @@
|
|||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if ma.course_message_type == "JoinCourseRequest" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"></a></li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<span class="newsBlue homepageNewsPublisher">系统提示</span>
|
||||
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">您有了新的课程成员申请:</span>
|
||||
</li>
|
||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||
<%= link_to User.find(ma.course_message_id).name+"申请成为课程\""+"#{Course.find(ma.course_id).name}"+"\"的"+"#{ma.content == '9' ? "教师" : "教辅"}", user_path(User.find(ma.course_message_id)),
|
||||
:class => "#{ma.viewed==0 ? "newsBlack" : "newsGrey"}",
|
||||
:onmouseover => "message_titile_show($(this),event)",
|
||||
:onmouseout => "message_titile_hide($(this))" %></a>
|
||||
<span id="deal_info_<%=ma.id%>">
|
||||
<% if ma.status == 0 || ma.status.nil?%>
|
||||
<%= link_to '同意',dealwith_apply_request_user_path(User.current,:agree=>'Y',:msg_id=>ma.id),:remote=>'true'%>
|
||||
|
|
||||
<%= link_to '拒绝',dealwith_apply_request_user_path(User.current,:agree=>'N',:msg_id=>ma.id),:remote=>'true'%>
|
||||
<% elsif ma.status == 1%> <!-- 同意 -->
|
||||
您已经同意了该申请
|
||||
<% elsif ma.status == 2%> <!-- 拒绝 -->
|
||||
您已经拒绝了该申请
|
||||
<%end %>
|
||||
</span>
|
||||
</li>
|
||||
<div style="display: none" class="message_title_red system_message_style">
|
||||
<p>
|
||||
<%= User.current.lastname + User.current.firstname %>老师您好!您有了新的课程成员申请,信息如下:
|
||||
</p>
|
||||
<p>真实姓名:<%= User.find(ma.course_message_id).realname %></p>
|
||||
<p>申请课程:<%= Course.find(ma.course_id).name%></p>
|
||||
<div class="fl">课程描述:</div>
|
||||
<div class="ml60"><%= Course.find(ma.course_id).description.html_safe %></div>
|
||||
<p>申请职位:<%= ma.content == '9' ? "教师" : "教辅"%></p>
|
||||
</div>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if ma.course_message_type == "CourseRequestDealResult" %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"></a></li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<span class="newsBlue homepageNewsPublisher">系统提示</span>
|
||||
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">
|
||||
课程申请进度反馈:</span>
|
||||
</li>
|
||||
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
|
||||
<%= link_to ma.status == 1 ?
|
||||
'您申请成为课程"'+Course.find(ma.course_id).name+'"的'+(ma.content == '9' ? '老师' : '教辅')+'申请已通过'
|
||||
:
|
||||
'您申请成为课程"'+Course.find(ma.course_id).name+'"的'+(ma.content == '9' ? '老师' : '教辅')+'的申请被拒绝', course_path(Course.find(ma.course_id)),
|
||||
:class => "#{ma.viewed==0 ? "newsBlack" : "newsGrey"}",
|
||||
:onmouseover => "message_titile_show($(this),event)",
|
||||
:onmouseout => "message_titile_hide($(this))" %></a>
|
||||
</span>
|
||||
</li>
|
||||
<div style="display: none" class="message_title_red system_message_style">
|
||||
<p>
|
||||
<%= User.current.lastname + User.current.firstname %>老师您好!您已成功加入课程<%= Course.find(ma.course_id).name%>。
|
||||
</p>
|
||||
<p>申请课程:<%= Course.find(ma.course_id).name%></p>
|
||||
<div class="fl">课程描述:</div>
|
||||
<div class="ml60"><%= Course.find(ma.course_id).description.html_safe %></div>
|
||||
<p>申请职位:<%= ma.content == '9' ? "教师" : "教辅"%></p>
|
||||
</div>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -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 %>
|
||||
);
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue