From 6a9037dde5b5be8ff1a00d66bab0135f551aff34 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 5 Jun 2014 10:33:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=B3=E9=97=AD=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 6 ++++++ app/controllers/courses_controller.rb | 21 ++++++++++++++++++- app/views/courses/finishcourse.js.erb | 8 +++++++ .../users/_course_list_have_entity.html.erb | 2 +- db/schema.rb | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 app/views/courses/finishcourse.js.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a25b346c..8cf3a2c3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 53717aef..932550e4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 diff --git a/app/views/courses/finishcourse.js.erb b/app/views/courses/finishcourse.js.erb new file mode 100644 index 00000000..bfbaee70 --- /dev/null +++ b/app/views/courses/finishcourse.js.erb @@ -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 %> diff --git a/app/views/users/_course_list_have_entity.html.erb b/app/views/users/_course_list_have_entity.html.erb index 19fb88a6..e29c8710 100644 --- a/app/views/users/_course_list_have_entity.html.erb +++ b/app/views/users/_course_list_have_entity.html.erb @@ -1,6 +1,6 @@