diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 54d1c7569..b1d7bf32d 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 class SyllabusesController < ApplicationController include ApplicationHelper helper :attachments @@ -5,7 +6,7 @@ class SyllabusesController < ApplicationController include CoursesHelper before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy] - before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist] + before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :update_base_info] def index user = User.current @syllabuses = user.syllabuses @@ -71,7 +72,7 @@ class SyllabusesController < ApplicationController #删除课程大纲的描述 def destroy - if @syllabus and @syllabus.courses.empty? + if @syllabus && @syllabus.courses.empty? @syllabus.destroy redirect_to user_path(User.current.id) end @@ -122,6 +123,27 @@ class SyllabusesController < ApplicationController end end + #修改英文名称 + def edit_syllabus_eng_name + if @syllabus + @syllabus.update_column("eng_name",params[:eng_name]) + end + respond_to do |format| + format.js + end + end + + #编辑属性 + def update_base_info + if @syllabus + @syllabus.update_attributes(:credit => params[:credit], :hours => params[:hours], :theory_hours => params[:theory_hours], :practice_hours => params[:practice_hours], :applicable_major => params[:applicable_major], :pre_course => params[:pre_course]) + @syllabus.update_attributes(:syllabus_type => params[:syllabus_type]) + respond_to do |format| + format.js + end + end + end + private def find_syllabus @syllabus = Syllabus.find params[:id] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 68e7f5590..411f47f1e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1372,7 +1372,7 @@ class UsersController < ApplicationController @courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) @all_count = @user.courses.visible.where("is_delete =?", 0).count elsif @type == 'Syllabus' - @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first + @syllabus = Syllabus.where("id = #{params[:syllabus]}").first @courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page * 5) @all_count = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).count end @@ -3205,7 +3205,7 @@ class UsersController < ApplicationController # end @syllabus.each do |syllabus| count = 0 - courses = @courses.select("syllabus_id = #{syllabus.id}") + courses = @courses.where("syllabus_id = #{syllabus.id}") courses.each do |c| count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) end diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index af5472ee1..00331e0dc 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 module SyllabusesHelper def get_syllabuses_by_tag(tag_name) Syllabus.tagged_with(tag_name).order('updated_at desc') @@ -35,4 +36,37 @@ module SyllabusesHelper end count end + + #课程性质下拉框 + def syllabus_type + type = [] + option1 = [] + option2 = [] + option3 = [] + option4 = [] + option5 = [] + option6 = [] + + option1 << "请选择" + option1 << 1 + option2 << "公共必修课" + option2 << 2 + option3 << "学科必修课" + option3 << 3 + option4 << "专业选修课" + option4 << 4 + option5 << "实践必修课" + option5 << 5 + option6 << "实践选修课" + option6 << 6 + + type << option1 + type << option2 + type << option3 + type << option4 + type << option5 + type << option6 + + type + end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4a6dbc6b6..f312d2275 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -32,7 +32,7 @@ module UsersHelper def get_resource_type type case type when 'Course' - '课程资源' + '班级资源' when 'Project' '项目资源' when 'Issue' @@ -122,11 +122,11 @@ module UsersHelper when 'homework' '作业消息' when 'course_message' - '课程讨论' + '班级讨论' when 'course_news' - '课程通知' + '班级通知' when 'poll' - '课程问卷' + '班级问卷' when 'issue' '项目任务' when 'forge_message' diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 2f2ec495f..5e368f341 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 class Syllabus < ActiveRecord::Base include Redmine::SafeAttributes include ApplicationHelper @@ -8,13 +9,29 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses has_many :journals_for_messages, :as => :jour, :dependent => :destroy - attr_accessible :description, :title, :eng_name, :type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course - safe_attributes 'title', 'description', 'eng_name', 'type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' + attr_accessible :description, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course + safe_attributes 'title', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' def delete_kindeditor_assets delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS end + def syllabus_type_str + case self.syllabus_type + when 1 + type = "公共必修课" + when 2 + type = "学科必修课" + when 3 + type = "专业选修课" + when 4 + type = "实践必修课" + when 5 + type = "实践选修课" + end + type + end + ###添加回复 def self.add_syllabus_jour(user, notes, id , options = {}) syllabus = Syllabus.find(id) diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb index 2e83a96aa..4786bbe89 100644 --- a/app/views/admin/course_resource_list.html.erb +++ b/app/views/admin/course_resource_list.html.erb @@ -39,7 +39,7 @@ <%= number_to_human_size(resource.filesize)%>