添加身份
This commit is contained in:
parent
5da45ac806
commit
a817c3b81e
|
@ -31,27 +31,25 @@ class CoursesController < ApplicationController
|
|||
|
||||
def join
|
||||
if User.current.logged?
|
||||
cs = CoursesService.new
|
||||
user = User.current
|
||||
join = cs.join_course params,user
|
||||
@state = join[:state]
|
||||
course = join[:course]
|
||||
if params[:role] == 10
|
||||
cs = CoursesService.new
|
||||
@user = User.current
|
||||
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
|
||||
@state = 5 #未登录
|
||||
end
|
||||
# if @state == 1 || @state == 3
|
||||
# respond_to course_path(course.id)
|
||||
# else
|
||||
respond_to do |format|
|
||||
format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :object_id => params[:object_id]} }
|
||||
end
|
||||
#end
|
||||
|
||||
rescue Exception => e
|
||||
@state = 4 #已经加入了课程
|
||||
@object_id = params[:object_id]
|
||||
respond_to do |format|
|
||||
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => nil, :object_id => nil} }
|
||||
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def unjoin
|
||||
|
|
|
@ -18,8 +18,10 @@ class CourseMessage < ActiveRecord::Base
|
|||
after_create :add_user_message
|
||||
|
||||
def add_user_message
|
||||
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
#unless self.course_message_type == 'JoinCourseRequest'
|
||||
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
#end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -299,6 +299,7 @@ class CoursesService
|
|||
#@state == 3 您已经加入了课程
|
||||
#@state == 4 您加入的课程不存在
|
||||
#@state == 5 您还未登录
|
||||
#@state == 6 申请成功,请等待审核完毕
|
||||
#@state 其他 未知错误,请稍后再试
|
||||
def join_course params,current_user
|
||||
course = Course.find_by_id params[:object_id]
|
||||
|
|
|
@ -71,12 +71,12 @@
|
|||
<span class="tips">密 码:</span>
|
||||
<input class=" width190" type="password" name="course_password" id="course_password" value="" >
|
||||
</li>
|
||||
<li style="margin-top: 30px;display: none">
|
||||
<li style="margin-top: 30px;">
|
||||
<span style="margin-right: 20px;">身 份:</span>
|
||||
<select class="IDType">
|
||||
<option>教师</option>
|
||||
<option>教辅</option>
|
||||
<option>学生</option>
|
||||
<select name="role" class="IDType">
|
||||
<option value="9">教师</option>
|
||||
<option value="7">教辅</option>
|
||||
<option value="10">学生</option>
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<% if object_id%>
|
||||
<% if object_id && @state != 6%>
|
||||
$("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>");
|
||||
<% end %>
|
||||
<% if @state %>
|
||||
|
@ -18,6 +18,8 @@
|
|||
alert("您加入的课程不存在");
|
||||
<% elsif @state == 5 %>
|
||||
alert("您还未登录");
|
||||
<% elsif @state == 6 %>
|
||||
alert("申请成功,请等待审核")
|
||||
<% else %>
|
||||
alert("未知错误,请稍后再试");
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<% if @object_id && @state != 6%>
|
||||
$("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(@course, @user)) %>");
|
||||
<% end %>
|
||||
<% if @state %>
|
||||
<% 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%>"
|
||||
<% elsif @state == 1 %>
|
||||
alert("密码错误");
|
||||
<% elsif @state == 2 %>
|
||||
alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)");
|
||||
<% elsif @state == 3 %>
|
||||
alert("您已经加入了课程");
|
||||
window.location.href= "http://"+"<%= Setting.host_name%>"+"/courses/" + "<%= course.id%>"
|
||||
<% elsif @state == 4 %>
|
||||
alert("您加入的课程不存在");
|
||||
<% elsif @state == 5 %>
|
||||
alert("您还未登录");
|
||||
<% elsif @state == 6 %>
|
||||
alert("申请成功,请等待审核")
|
||||
<% else %>
|
||||
alert("未知错误,请稍后再试");
|
||||
<% end %>
|
||||
<% end %>
|
Loading…
Reference in New Issue