注意:1、课堂名称 = 课程名称 + 学期信息 + 其它
+正确示例:数据结构2016秋季班级
+错误示例:数据结构班级
+2、如果本学期包含多个班级,只需创建一个课堂
+然后在课堂内部建立不同的分班
+diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 3b660b434..5ad869462 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,7 +151,11 @@ class ChallengesController < ApplicationController end end end - redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]), notice: 'Succeed' + if params[:tab].to_i == 5 + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]), notice: 'Succeed' + else + redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) + end rescue Exception => e flash[:error] = "#{e.message}" redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab]) diff --git a/app/controllers/department_controller.rb b/app/controllers/department_controller.rb index 7e9438843..eeb4a82ba 100644 --- a/app/controllers/department_controller.rb +++ b/app/controllers/department_controller.rb @@ -1,5 +1,7 @@ class DepartmentController < ApplicationController + before_filter :find_department, :only => [:destroy] + #根据部门名字或者拼音来查询 def on_search school = School.find params[:school_id] @@ -95,4 +97,24 @@ class DepartmentController < ApplicationController render :json =>status end + + def destroy + if @department + if UserExtensions.where(:department_id => @department.id).count == 0 + ApplyAddDepartment.where(:department_id=>@department.id).update_all(:status => 2) + @apply_dep = ApplyAddDepartment.where(:department_id=>@department.id).first + @department.destroy + end + respond_to do |format| + format.js + end + end + end + + private + def find_department + @department = Department.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 4bdf16e72..dc33b059d 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -268,7 +268,7 @@ end @menu_type = 6 @sub_type = 2 @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] - @department =Department.where("0=0") + @department = ApplyAddDepartment.where(:status => 1) search=params[:search] if search.blank? @department = @department @@ -288,6 +288,69 @@ end end end + # 新增 + def create_departments + respond_to do |format| + format.js + end + end + + def add_department + department = Department.where(:school_id => params[:school], :name => params[:department]).first + if department.nil? + department = Department.create(:school_id => params[:school],:name => params[:department]) + ApplyAddDepartment.create(:school_id => params[:school], + :status => 1, + :name => params[:department], + :department_id => department.id, + :user_id => User.current.id); + end + redirect_to departments_managements_path + end + + # 修改单位部门列表 + def update_department + dep = Department.find params[:department_id] + apply_schools = ApplyAddDepartment.where(:status => 1, :school_id => dep.school_id) + apply_school_ids = apply_schools.empty? ? "(-1)" : "(" + apply_schools.map{|sc| sc.department_id}.join(',') + ")" + @edit_id = params[:department_id] + @search = params[:search] + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @departments = Department.where("id in #{apply_school_ids} and #{Department.table_name}.name like :p", :p => search) + #@schools = School.all + else + @departments = Department.where("id in #{apply_school_ids}") + end + respond_to do |format| + format.js + end + end + + def edit_departments_school + begin + dep = Department.find(params[:department_id]) + alter_dep = Department.find(params[:alter_dep_id]) + apply_dep = ApplyAddDepartment.where(:department_id => params[:alter_dep_id]) + if dep && alter_dep && dep != alter_dep + # users = UserExtensions.where("department_id = #{dep.id}") + # users.update_all(:department_id => params[:alter_dep_id]) + # dep.destroy + # apply_dep.update_all(:status => 2) + # ApplyAddDepartment.where(:department_id =>params[:departments]).update_all(:department_id=>department_id) + # users = UserExtensions.where("department_id = #{alt_dep.department_id}") + # users.update_all(:department_id => department.id) + apply_dep.destroy_all; + users = UserExtensions.where(:department_id => params[:alter_dep_id]) + users.update_all(:department_id => dep.id) + alter_dep.destroy + end + rescue Exception => e + puts e + end + redirect_to departments_managements_path + end + # 单位列表 def departments_part @menu_type = 6 @@ -373,23 +436,25 @@ end # 部门修改 def all_department - apply_department = ApplyAddDepartment.where("status = 0") + @edit_id = params[:department_id] + @search = params[:search] + dep = ApplyAddDepartment.where(:id => @edit_id).first + apply_department = ApplyAddDepartment.where(:status => 1, :school_id => dep.school_id) apply_department_ids = apply_department.empty? ? "(-1)" : "(" + apply_department.map{|sc| sc.department_id}.join(',') + ")" if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @department = Department.where("id not in #{apply_department_ids} and #{Department.table_name}.name like :p", :p => search) + @department = Department.where("id in #{apply_department_ids} and #{Department.table_name}.name like :p", :p => search) #@schools = School.all else #@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} - @department = Department.where("id not in #{apply_department_ids}") + @department = Department.where("id in #{apply_department_ids}") end - @edit_id = params[:department_id] - @search = params[:search] respond_to do |format| format.js end # redirect_to unit_managements_path end + # 修改 def edit_applied_department aas =ApplyAddDepartment.find(params[:applied_id]) @@ -398,19 +463,19 @@ end department =Department.find params[:department_id] begin #更新消息表的status - applied_message_id = aas.department_id - applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddDepartment") - applied_message.update_all(:status => 4) - aas.update_attribute(:status, 2) - AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddDepartment", :name =>department[0].name ) - users = UserExtensions.where("department_id = #{aas.department_id}") - users.update_all(:department_id => department.id) if aas.department_id != department.id.to_i + applied_message_id = aas.department_id + applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddDepartment") + applied_message.update_all(:status => 4) + aas.update_attribute(:status, 2) + AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddDepartment", :name =>department.name ) + users = UserExtensions.where("department_id = #{aas.department_id}") + users.update_all(:department_id => department.id) aas.department.destroy + ApplyAddDepartment.where(:department_id => aas.department_id).update_all(:department_id => department.id) + Department.where(:department_id => aas.department_id).destroy_all + aas.destroy_all end - ApplyAddDepartment.where(:department_id => aas.department_id).update_all(:department_id => department.id) - Department.where(:department_id => aas.department_id).update_all(:department_id => department.id) - aas.update_attribute(:department_id, department.id) rescue Exception => e puts e end @@ -512,19 +577,20 @@ end school = School.find params[:school_id] begin #更新消息表的status - applied_message_id = aas.school_id - applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools") - applied_message.update_all(:status => 4) - aas.update_attribute(:status, 2) - AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school[0].name ) - users = UserExtensions.where("school_id = #{aas.school_id}") - users.update_all(:school_id => school.id) if aas.school_id != school.id.to_i + applied_message_id = aas.school_id + applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools") + applied_message.update_all(:status => 4) + aas.update_attribute(:status, 2) + AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school.name ) + users = UserExtensions.where("school_id = #{aas.school_id}") + users.update_all(:school_id => school.id) + + ApplyAddDepartment.where(:school_id => aas.school_id).update_all(:school_id => school.id) + Department.where(:school_id => aas.school_id).update_all(:school_id => school.id) aas.school.destroy + aas.update_attribute(:school_id, school.id) end - ApplyAddDepartment.where(:school_id => aas.school_id).update_all(:school_id => school.id) - Department.where(:school_id => aas.school_id).update_all(:school_id => school.id) - aas.update_attribute(:school_id, school.id) rescue Exception => e puts e end @@ -588,7 +654,7 @@ end end end - # 班级列表 + # 课堂列表 def classroom_classment @menu_type = 2 @sub_type = 2 diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 3db2dfb64..236c695f1 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -151,7 +151,7 @@ class MyController < ApplicationController ue = @user.user_extensions @trail_authentication = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization").order("created_at desc").first @authentication = @user.authentication - if @user.nickname.nil? || @user.lastname.nil? || ue.identity.nil? || ue.location.nil? || ue.school_id.nil? + if @user.nickname.nil? || @user.lastname.nil? || ue.try(:identity).nil? || ue.try(:location).nil? || ue.try(:location).nil? @require_auth = true else if User.current.certification != 1 && (@trail_authentication.blank? || (@trail_authentication.status == 2 && (@trail_authentication.updated_at.to_i + 24*60*60) < Time.now.to_i)) diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index ef053bb16..334c880e2 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -1,7 +1,7 @@ class SchoolController < ApplicationController layout 'course_base' before_filter :require_admin, :only => :upload_logo - + before_filter :find_school, :only => [:destroy] def upload uploaded_io = params[:logo] school_id ||= params[:id] @@ -283,4 +283,23 @@ class SchoolController < ApplicationController render :json=>{:status=>status,:id=>params[:id],:province=>province,:city=>city} end + + def destroy + if @school + if UserExtensions.where(:school_id => @school.id).count == 0 + School.where(:id=>@school.id).destroy_all + @school.destroy + end + respond_to do |format| + format.js + end + end + end + + private + def find_school + @school = School.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end end diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb index 4b6a984d0..5ea5c00ec 100644 --- a/app/models/apply_add_department.rb +++ b/app/models/apply_add_department.rb @@ -1,7 +1,8 @@ -class ApplyAddDepartment < ActiveRecord::Base - belongs_to :school - belongs_to :user - attr_accessible :name, :remarks, :status, :school_id, :user_id - has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied - belongs_to :department -end +class ApplyAddDepartment < ActiveRecord::Base + belongs_to :school + belongs_to :user + attr_accessible :name, :remarks, :status, :school_id, :user_id, :department_id + has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied + belongs_to :department + # status: 0表示未批准; status:1表示已批准; status: 2表示已更改; status: 3表示已拒绝; status: 4表示已更改后废除的部门 +end diff --git a/app/views/account/change_or_bind.html.erb b/app/views/account/change_or_bind.html.erb index c102daf20..4050c8a1b 100644 --- a/app/views/account/change_or_bind.html.erb +++ b/app/views/account/change_or_bind.html.erb @@ -34,7 +34,7 @@
-