From e5fec207aa3a869ca4078a72f9a441739a469fd3 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 10 Jun 2014 08:47:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=AD=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6=E4=B8=BA=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E8=AF=BE=E7=A8=8B=E6=88=90=E5=91=98=E3=80=81=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E3=80=81=E8=80=81=E5=B8=88=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=202.=E6=96=B0=E5=BB=BA=E4=BD=9C=E4=B8=9A=E6=97=B6=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E9=A1=B9=E7=9B=AE=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=203.=E5=A2=9E=E5=8A=A0checkbox=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 21 ++++++++++++ app/controllers/homework_users_controller.rb | 13 +++++++- app/helpers/courses_helper.rb | 17 ++-------- app/helpers/homework_attach_helper.rb | 33 ++++++++++++------- app/helpers/members_helper.rb | 2 +- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index f7564a2d..074a6d91 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -60,7 +60,15 @@ class HomeworkAttachController < ApplicationController def new @bid = Bid.find(params[:id]) if User.current.admin? || User.current.member_of?(@bid.courses.first) + @members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]}) + + #@all_user = [] + #@bid.courses.first.members.each do |member| + # @all_user << member.user + #end @homework = HomeworkAttach.new + #@homework_user = members_for_homework(@homework) + User.current + #@members = @all_user - @homework_user respond_to do |format| format.html # new.html.erb format.json { render json: @homework } @@ -70,6 +78,19 @@ class HomeworkAttachController < ApplicationController end end + #获取指定作业的所有成员 + def members_for_homework homework + people = [] + if homework != nil + people << homework.user + homework.homework_users do |homework_user| + people << homework_user.user + end + else + end + people + end + def edit @homework = HomeworkAttach.find(params[:id]) if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) diff --git a/app/controllers/homework_users_controller.rb b/app/controllers/homework_users_controller.rb index cb55d965..5f473b42 100644 --- a/app/controllers/homework_users_controller.rb +++ b/app/controllers/homework_users_controller.rb @@ -1,3 +1,14 @@ class HomeworkUsersController < ApplicationController - + #新增数据 + def create option + user = HomeworkUser.new option + user.save + user + end + #删除数据 + def destory homework_user + user = HomeworkUser.find homework_user + user.destroy + user + end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 326ea873..cc207e84 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -138,24 +138,11 @@ module CoursesHelper end #判断制定用户是不是当前课程的老师 def is_course_teacher user,course - people = [] - course.members.each do |member| - role_id = member.roles.first.id - if TeacherRoles.include? role_id - people << member.user - end - end - people.include?(user) + searchPeopleByRoles(course, TeacherRoles).include?(user) end #当前用户是不是指定课程的学生 def is_cur_course_student? course - people = [] - course.members.each do |member| - if StudentRoles.include? member.roles.first.id - people << member.user - end - end - people.include?(User.current) + searchPeopleByRoles(course, StudentRoles).include?(User.current) end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 8dc3eadb..ed8d0949 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -9,7 +9,7 @@ module HomeworkAttachHelper end #作业添加、编辑界面的tab页 def homework_settings_tabs f - @project = Project.find 205 + @project = Project.find 76 @f = f tabs = [{:name => 'info', :action => :edit_homework, :partial => 'homework_attach/edit_homework', :label => :label_information_plural}, {:name => 'members', :action => :homework_member, :partial => 'homework_attach/homework_member', :label => :label_member_plural} @@ -17,18 +17,27 @@ module HomeworkAttachHelper #tabs.select {|tab| User.current.allowed_to?(tab[:action], @homework)} end - def render_principals_for_new_members(project) - scope = Principal.active.sorted.not_member_of(project).like(params[:q]) - principal_count = scope.count - principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young - principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all - - s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') - - links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| - link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true - } + #作业可选成员列表分页 + def render_new_members_for_homework members + #scope = Principal.active.sorted.not_member_of(project).like(params[:q]) + #scope = project.members + principal_count = members.count + limit = 10 + principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young + offset ||= principal_pages.offset + principals = members[offset, limit] + s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') + links = pagination_links_full(principal_pages, principal_count, :per_page_links => false,:remote => true) s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') end + + #扩展的checkbox生成 + def member_check_box_tags_ex(name, principals) + s = '' + principals.each do |member| + s << "\n" + end + s.html_safe + end end \ No newline at end of file diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 91e05d6a..79748386 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -36,7 +36,7 @@ module MembersHelper # 当前申请加入的成员名单 def render_principals_for_applied_members(project) scope = Principal.active.sorted.applied_members(project).like(params[:q]) - principal_count = scope.count + principal_count = scope.count principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all