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,6 +26,7 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
course = Course.find(params[:object_id])
unless User.current.member_of_course? course
if params[:course_password] == course.password
members = []
members << Member.new(:role_ids => [10], :user_id => User.current.id)
@ -36,11 +37,20 @@ class CoursesController < ApplicationController
else
@state = 1
end
else
@state = 3
end
end
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 => Course.find(params[:object_id]), :object_id => params[:object_id]} }
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
def unjoin
@ -61,9 +71,7 @@ class CoursesController < ApplicationController
end
def join_private_courses
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js
end
end

View File

@ -36,7 +36,7 @@
}
</style>
<h3 class="title">请输入相关信息</h3>
<h3 class="title">加入公开课程或私有课程</h3>
<%= form_tag({:controller => 'courses',
:action => 'join'},
@ -46,6 +46,7 @@
<div>
<span>课程ID</span>
<%= text_field_tag 'object_id', nil, :style=>'width:80%'%>
<span style="padding-left: 55px;color: red;">(课程ID是课程的网址中出现的序号)</span>
</div>
<div>
<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 == 0 %>
alert("加入成功")
@ -6,6 +8,10 @@ $("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course_for_list(
alert("密码错误")
<% elsif @state == 2 %>
alert("课程已过期\n请联系课程管理员重启课程。(在配置课程处)")
<% elsif @state == 3 %>
alert("您已经加入了课程");
<% elsif @state == 3 %>
alert("您已经的课程不存在")
<% else %>
alert("未知错误,请稍后再试")
<% end %>

View File

@ -5,6 +5,6 @@
<% end %>
&nbsp;&nbsp;&nbsp;&nbsp;
<% 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;
<%= link_to l(:label_more), {:controller => 'courses', :action => 'index', :school_id => school_id} %>