|
|
|
@ -9,7 +9,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
menu_item l(:label_sort_by_active), :only => :index
|
|
|
|
|
menu_item l(:label_sort_by_influence), :only => :index
|
|
|
|
|
|
|
|
|
|
before_filter :find_course, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
|
|
|
|
|
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
|
|
|
|
|
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
|
|
|
|
|
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
|
|
|
|
|
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
|
|
|
|
@ -20,9 +20,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def join
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
course = Project.find(params[:object_id])
|
|
|
|
|
course_prefs = Course.find_by_extra(course.identifier)
|
|
|
|
|
if params[:course_password] == course_prefs.password
|
|
|
|
|
course = Course.find(params[:object_id])
|
|
|
|
|
if params[:course_password] == course.password
|
|
|
|
|
members = []
|
|
|
|
|
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
|
|
|
|
course.members << members
|
|
|
|
@ -35,14 +34,14 @@ class CoursesController < ApplicationController
|
|
|
|
|
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 => Project.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
|
|
|
|
|
|
|
|
|
|
def unjoin
|
|
|
|
|
if User.current.logged?
|
|
|
|
|
|
|
|
|
|
@member = Member.where('project_id = ? and user_id = ?', params[:object_id], User.current.id)
|
|
|
|
|
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
|
|
|
|
|
@member.first.destroy
|
|
|
|
|
|
|
|
|
|
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
|
|
|
@ -52,7 +51,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
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 => Project.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
|
|
|
|
|
|
|
|
|
@ -88,6 +87,10 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new_join
|
|
|
|
|
@course = Course.find(params[:object_id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课程搜索
|
|
|
|
|
# add by nwb
|
|
|
|
|
def search
|
|
|
|
@ -660,13 +663,13 @@ class CoursesController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def allow_join
|
|
|
|
|
if course_endTime_timeout? Project.find(params[:object_id])
|
|
|
|
|
if course_endTime_timeout? Course.find(params[:object_id])
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js {
|
|
|
|
|
@state = 2
|
|
|
|
|
render :partial => 'set_join',
|
|
|
|
|
:locals => {:user => User.current,
|
|
|
|
|
:course => Project.find(params[:object_id]),
|
|
|
|
|
:course => Course.find(params[:object_id]),
|
|
|
|
|
:object_id => params[:object_id]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|