加入课程与退出课程js刷新

This commit is contained in:
sw 2015-03-27 19:50:01 +08:00
parent 6cd56c339a
commit 72d683bdb7
5 changed files with 8 additions and 7 deletions

View File

@ -30,19 +30,19 @@ class CoursesController < ApplicationController
def join
if User.current.logged?
cs = CoursesService.new
join = cs.join_course params,User.current
user = User.current
join = cs.join_course params,user
@state = join[:state]
course = join[:course]
else
@state = 5 #未登录
end
respond_to do |format|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => course, :object_id => params[:object_id]} }
format.js { render :partial => 'set_join', :locals => {:user => user, :course => course, :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

View File

@ -677,7 +677,7 @@ module CoursesHelper
#加入课程、退出课程按钮
def join_in_course_header(course, user, options=[])
if user.logged?
joined = user.member_of_course? course
joined = course.members.map{|member| member.user_id}.include? user.id
text = joined ? ("<em class='pr_arrow'></em>".html_safe + l(:label_course_exit_student)) : ("<em class='pr_add'></em>".html_safe + l(:label_course_join_student))
url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id)
method = joined ? 'delete' : 'post'

View File

@ -33,8 +33,9 @@
<p id="bid_evaluation_num_span" class="c_red" style="padding-left: 90px;"></p>
</li>
<li class="ml45">
<label>&nbsp;&nbsp;<%= l(:label_attachment_plural) %>&nbsp;&nbsp;</label>
<label class="fl">&nbsp;&nbsp;<%= l(:label_attachment_plural) %>&nbsp;&nbsp;</label>
<%= render :partial => 'attachments/new_form', :locals => {:container => bid} %>
<div class="cl"></div>
</li>
<li class=" ml90" >
<a class="blue_btn fl c_white" onclick="submit_new_bid('<%= bid_id%>');" href="#"><%= l(:button_create)%></a>

View File

@ -1,5 +1,5 @@
<% if object_id%>
$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_course(course, user) %>');
$("#join_in_course_header").html("<%= escape_javascript(join_in_course_header(course, user)) %>");
<% end %>
<% if @state %>
<% if @state == 0 %>

View File

@ -77,7 +77,7 @@
<%= set_course_time @course%>
<%= link_to "<span class='pr_copy'></span>#{l(:button_copy)}".html_safe, copy_course_course_path(@course.id), :class => "pr_join_a" %>
<% else%>
<%= join_in_course_header(@course, User.current) %>
<div id="join_in_course_header"><%= join_in_course_header(@course, User.current) %></div>
<% end%>
</div>
<div class="cl"></div>