class EcsController < ApplicationController before_filter :require_login before_filter :find_school, :except => [:get_navigation_url] before_filter :school_manager, :except => [:department, :get_navigation_url] layout 'base_ec' def department @template_major = EcMajorSchool.where(:template_major => true).first @school_managers = @school.users @is_school_manager = User.current.admin? || User.current.business? || @school.users.where(:id => User.current.id).count > 0 # 学校管理员 @major_schools = @school.ec_major_schools.where(:template_major => false) unless @is_school_manager ec_major_school_ids = EcMajorSchoolUser.where(:user_id => User.current.id).pluck(:ec_major_school_id) ec_course_major_ids = EcYear.where(:id => EcCourse.where(:id => EcCourseUser.where(:user_id => User.current.id).pluck(:ec_course_id)).pluck(:ec_year_id)).pluck(:ec_major_school_id) @major_schools = @major_schools.where(:id => (ec_major_school_ids + ec_course_major_ids).uniq) end @major_count = @major_schools.count if !@is_school_manager && @major_count == 0 render_403 else if params[:search].present? major_ids = EcMajor.where("name like '%#{params[:search]}%' or code like '%#{params[:search]}%'").pluck(:id) @major_schools = @major_schools.where(:ec_major_id => major_ids) end @obj_count = @major_schools.count @limit = 10 @is_remote = true @obj_pages = Paginator.new @obj_count, @limit, params['page'] || 1 @offset ||= @obj_pages.offset @major_schools = paginateHelper @major_schools, @limit respond_to do |format| format.js format.html end end end # 搜索专业 def search_major @major_ids = @school.ec_majors.pluck(:id) # 去除已经添加的专业 @majors = EcMajor.where("(concat(name, code) like '%#{params[:search]}%')").limit(10) end # 添加专业 def add_major major_ids = params[:major_ids] major_ids.each do |id| EcMajorSchool.create(ec_major_id: id, school_id: params[:school_id]) end render :json => {status: 1} end # 获取工程认证头部url # GET: /ecs/get_navigation_url def get_navigation_url ec_user = EcSchoolUser.where(:user_id => User.current.id).first ec_url = "#{department_ecs_path(:school_id => ec_user.school_id)}" if ec_user render :json => {ec_url: ec_url} end private def find_school @school = School.find(params[:school_id]) end def school_manager unless User.current.admin? || User.current.business? || @school.users.where(:id => User.current.id).count > 0 render_403 end end end