diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7dea90e4b..e81251f63 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -715,6 +715,7 @@ class CoursesController < ApplicationController @trackers = Tracker.sorted.all @course = Course.new @course.safe_attributes = params[:course] + @syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first if params[:syllabus_id] # month = Time.now.month render :layout => 'new_base' else diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index 69982b99a..5ee3224bd 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -8,8 +8,43 @@ class SyllabusesController < ApplicationController end def show - @courses = @syllabus.courses + #@courses = @syllabus.courses + respond_to do |format| + format.js + format.html{render :layout => 'base_syllabus'} + format.api + end + end + def new + if User.current.login? + @syllabus = Syllabus.new + render :layout => 'new_base' + else + redirect_to signin_url + end + end + + def create + if User.current.user_extensions.identity + @syllabus = Syllabus.new + @syllabus.title = params[:title] + @syllabus.eng_name = params[:eng_name] + @syllabus.user_id = User.current.id + if @syllabus && @syllabus.save + respond_to do |format| + flash[:notice] = l(:notice_successful_create) + format.html {redirect_to syllabus_path(@syllabus)} + format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'syllabuses', :action => 'show', :id => @syllabus.id) } + end + else + respond_to do |format| + flash[:notice] = l(:notice_create_failed) + format.html { redirect_to new_syllabus_path } #Added by young + format.api { render_validation_errors(@syllabus) } + end + end + end end private diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 2c390025e..e66f88848 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -13,6 +13,7 @@ class TagsController < ApplicationController include ForumsHelper include AttachmentsHelper include ContestsHelper + include SyllabusesHelper include ActsAsTaggableOn::TagsHelper include TagsHelper include FilesHelper @@ -529,6 +530,8 @@ class TagsController < ApplicationController @obj = Course.find_by_id(@obj_id) when '10' @obj = Attachment.find_by_id(@obj_id) + when '11' + @obj = Syllabus.find_by_id(@obj_id) else @obj = nil end @@ -619,6 +622,9 @@ class TagsController < ApplicationController when '9' then @obj = Course.find_by_id(obj_id) @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) + when '11' then + @obj = Syllabus.find_by_id(obj_id) + @obj_pages, @syllabuses_results, @results_count = for_pagination(get_syllabuses_by_tag(selected_tags)) else @obj = nil end @@ -684,6 +690,8 @@ class TagsController < ApplicationController return 'Course' when '10' return 'Attachment' + when '11' + return 'Syllabus' else render_error :message => e.message return diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 47d343e8f..fd3be1369 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -667,6 +667,22 @@ module CoursesHelper is_current_term || is_next_term end + #课程大纲下拉框 + def syllabus_option + type = [] + option1 = [] + option1 << "请选择课程" + option1 << 0 + type << option1 + Syllabus.all.each do |syllabus| + option = [] + option << syllabus.title + option << syllabus.id + type << option + end + type + end + #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index dac84937b..d5284586e 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -1,2 +1,5 @@ module SyllabusesHelper + def get_syllabuses_by_tag(tag_name) + Syllabus.tagged_with(tag_name).order('updated_at desc') + end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 8847f4163..54753807d 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -23,6 +23,8 @@ module TagsHelper @obj= Course.find_by_id(obj_id) when '10' @obj = Attachment.find_by_id(obj_id) + when '11' + @obj = Syllabus.find_by_id(obj_id) else raise Exception, '[TagsHelper] ===> tag type unknow.' end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 7d6319955..b1bdfd5aa 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -1,5 +1,7 @@ class Syllabus < ActiveRecord::Base + acts_as_taggable + belongs_to :user has_many :courses - attr_accessible :description, :title + attr_accessible :description, :title, :eng_name, :type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 60c053997..b7b5e73ac 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -201,6 +201,7 @@ class CoursesService #@course.safe_attributes(current_user,params[:course]) #@course.password = params[:course][:password] @course.tea_id = current_user.id + @course.syllabus_id = params[:syllabus_id].to_i @course.term = params[:term] @course.time = params[:time] @course.end_term = params[:end_term] diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index ddaf17ae8..d3326480f 100644 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -4,12 +4,22 @@
<%=@syllabus.title %>
+ +