1.优化加入课程页面

2.增加是否已经加入课程的判断
This commit is contained in:
sw 2014-10-16 11:55:42 +08:00
parent b696aa3362
commit 6a33934122
4 changed files with 28 additions and 13 deletions

View File

@ -26,21 +26,31 @@ class CoursesController < ApplicationController
def join def join
if User.current.logged? if User.current.logged?
course = Course.find(params[:object_id]) course = Course.find(params[:object_id])
if params[:course_password] == course.password unless User.current.member_of_course? course
members = [] if params[:course_password] == course.password
members << Member.new(:role_ids => [10], :user_id => User.current.id) members = []
course.members << members members << Member.new(:role_ids => [10], :user_id => User.current.id)
course.members << members
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id]) StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
@state = 0 @state = 0
else
@state = 1
end
else else
@state = 1 @state = 3
end end
end end
respond_to do |format| respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} } format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end end
rescue Exception => e
@state = 4
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => nil, :object_id => nil} }
end
end end
def unjoin def unjoin
@ -61,9 +71,7 @@ class CoursesController < ApplicationController
end end
def join_private_courses def join_private_courses
respond_to do |format| respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js format.js
end end
end end

View File

@ -36,7 +36,7 @@
} }
</style> </style>
<h3 class="title">请输入相关信息</h3> <h3 class="title">加入公开课程或私有课程</h3>
<%= form_tag({:controller => 'courses', <%= form_tag({:controller => 'courses',
:action => 'join'}, :action => 'join'},
@ -46,6 +46,7 @@
<div> <div>
<span>课程ID</span> <span>课程ID</span>
<%= text_field_tag 'object_id', nil, :style=>'width:80%'%> <%= text_field_tag 'object_id', nil, :style=>'width:80%'%>
<span style="padding-left: 55px;color: red;">(课程ID是课程的网址中出现的序号)</span>
</div> </div>
<div> <div>
<span>密码&nbsp;&nbsp;&nbsp;</span> <span>密码&nbsp;&nbsp;&nbsp;</span>

View File

@ -1,4 +1,6 @@
$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(course, user) %>'); <% if object_id%>
$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(course, user) %>');
<% end %>
<% if @state %> <% if @state %>
<% if @state == 0 %> <% if @state == 0 %>
alert("加入成功") alert("加入成功")
@ -6,7 +8,11 @@ $("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(
alert("密码错误") alert("密码错误")
<% elsif @state == 2 %> <% elsif @state == 2 %>
alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)") alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)")
<% else %> <% elsif @state == 3 %>
alert("您已经加入了课程");
<% elsif @state == 3 %>
alert("您已经的课程不存在")
<% else %>
alert("未知错误,请稍后再试") alert("未知错误,请稍后再试")
<% end %> <% end %>
<% end %> <% end %>

View File

@ -5,6 +5,6 @@
<% end %> <% end %>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<% end %> <% end %>
<%= link_to "加入课程", join_private_courses_courses_path ,:remote => true, :class => 'icon icon-add' %> <%= link_to l(:label_course_join_student), join_private_courses_courses_path ,:remote => true, :class => 'icon icon-add' %>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to l(:label_more), {:controller => 'courses', :action => 'index', :school_id => school_id} %> <%= link_to l(:label_more), {:controller => 'courses', :action => 'index', :school_id => school_id} %>