修改关闭课程逻辑
This commit is contained in:
parent
10397eec3e
commit
6a9037dde5
|
@ -291,6 +291,12 @@ class ApplicationController < ActionController::Base
|
|||
render_404
|
||||
end
|
||||
|
||||
def find_course
|
||||
@course= Course.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def self.model_object(model)
|
||||
self.model_object = model
|
||||
end
|
||||
|
|
|
@ -5,14 +5,15 @@ 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 :authorize, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
|
||||
#before_filter :authorize_global, :only => [:view_homework_attaches, :new,:create]
|
||||
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
|
||||
before_filter :toggleCourse, only: [:finishcourse, :restartcourse]
|
||||
|
||||
before_filter :require_login, :only => [:join, :unjoin]
|
||||
before_filter :allow_join, :only => [:join]
|
||||
|
||||
|
||||
def join
|
||||
if User.current.logged?
|
||||
course = Project.find(params[:object_id])
|
||||
|
@ -299,6 +300,24 @@ class CoursesController < ApplicationController
|
|||
return activities
|
||||
end
|
||||
|
||||
def toggleCourse
|
||||
@course_prefs = Course.find_by_extra(@course.extra)
|
||||
unless (@course_prefs.teacher == User.current || User.current.admin?)
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def finishcourse
|
||||
yesterday = Date.today.prev_day.to_time
|
||||
|
||||
@course_prefs.endup_time = yesterday
|
||||
@save_flag = @course_prefs.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def allow_join
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<% if @save_flag %>
|
||||
<% if Rails.env.development? %>
|
||||
console.debug('课程修改成功:结束时间改为<%=Course.find_by_extra(@project.extra).try(:endup_time)%>');
|
||||
<% end %>
|
||||
$('#finish_course_<%=@course.id%>').replaceWith("<%= j(render partial: 'courses/set_course_time', :locals => {:course => @course} )%>")
|
||||
<% else %>
|
||||
alert('权限不足,设置失败,请在论坛提交问题,等待管理员处理。');
|
||||
<% end %>
|
|
@ -1,6 +1,6 @@
|
|||
<div class="user_course_list menu-div">
|
||||
<div class="menu">
|
||||
<%= link_to "#{l(:label_course_new)}", new_project_path(course: 1, project_type: 1), class: 'icon icon-add' if @user == User.current %>
|
||||
<%= link_to "#{l(:label_course_new)}", new_course_path(course: 1, project_type: 1), class: 'icon icon-add' if @user == User.current %>
|
||||
<ul>
|
||||
<li mode='doing' class="on">进行中</li>
|
||||
<li mode='end'>已完结</li>
|
||||
|
|
|
@ -363,7 +363,7 @@ ActiveRecord::Schema.define(:version => 20140604071624) do
|
|||
end
|
||||
|
||||
create_table "homework_for_courses", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.integer "course_id"
|
||||
t.integer "bid_id"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue