加入、退出课程逻辑优化

This commit is contained in:
nwb 2014-06-16 17:14:05 +08:00
parent b4e78d2b0c
commit 9c3605320e
6 changed files with 20 additions and 18 deletions

View File

@ -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]
}
}

View File

@ -352,11 +352,6 @@ class ProjectsController < ApplicationController
#gcmend
# added by fq
def new_join
@course = Project.find(params[:object_id])
end
#Added by young
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})

View File

@ -71,7 +71,7 @@ module WatchersHelper
# Somebody may use option params
def join_in_course(course, user, options=[])
return '' unless user && user.logged?
joined = user.member_of?(course)
joined = user.member_of_course?(course)
text = joined ? l(:label_exit_course) : l(:label_join_course)
url_t = join_path(:object_id => course.id)
url_f = try_join_path(:object_id => course.id)
@ -85,7 +85,7 @@ module WatchersHelper
def join_in_course_for_list(course, user, options=[])
return '' unless user && user.logged?
joined = user.member_of?(course)
joined = user.member_of_course?(course)
text = joined ? l(:label_exit_course) : l(:label_join_course)
url_t = join_path(:object_id => course.id)
url_f = try_join_path(:object_id => course.id)

View File

@ -1,7 +1,8 @@
class StudentsForCourse < ActiveRecord::Base
attr_accessible :course_id, :student_id
belongs_to :course, :class_name => 'Project', :foreign_key => :course_id
belongs_to :course, :class_name => 'Course', :foreign_key => :course_id
belongs_to :student, :class_name => 'User', :foreign_key => :student_id
validates_presence_of :course_id, :student_id

View File

@ -0,0 +1,3 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'projects/new_join', :locals => {:course => @course}) %>');
showModal('ajax-modal', '400px');
$('#ajax-modal').addClass('new-watcher');

View File

@ -643,7 +643,7 @@ RedmineApp::Application.routes.draw do
match 'calls/:id/settings', :to => 'bids#settings' #bai
delete 'attachment/:id', :to => 'attachments#delete_homework'
match 'new_join', :to => 'projects#new_join', :as => 'try_join'
match 'new_join', :to => 'courses#new_join', :as => 'try_join'
match 'new_join_in_contest', :to => 'bids#new_join', :as => 'try_join_in_contest'
match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post
match 'calls/:id/manage',:to => 'bids#manage',:via => [:get,:post]