diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 91e05d6a8..d1292260f 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -33,6 +33,24 @@ module MembersHelper s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') end + # add by nwb + # 课程可添加的成员列表 + def render_principals_for_new_course_members(course) + scope = Principal.active.sorted.not_member_of_course(course).like(params[:q]) + 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 + + 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_course_memberships_path(course, parameters.merge(:q => params[:q], :format => 'js')), :remote => true + } + + s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') + end + + # 当前申请加入的成员名单 def render_principals_for_applied_members(project) scope = Principal.active.sorted.applied_members(project).like(params[:q]) diff --git a/app/models/principal.rb b/app/models/principal.rb index efe24f034..024480635 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -73,6 +73,17 @@ class Principal < ActiveRecord::Base where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids) end } + + scope :not_member_of_course, lambda {|courses| + courses = [courses] unless courses.is_a?(Array) + if courses.empty? + where("1=0") + else + ids = courses.map(&:id) + where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE course_id IN (?))", ids) + end + } + scope :sorted, lambda { order(*Principal.fields_for_order_statement)} scope :applied_members, lambda {|project| diff --git a/app/views/courses/settings/_members.html.erb b/app/views/courses/settings/_members.html.erb index 30a3fbceb..0879b7956 100644 --- a/app/views/courses/settings/_members.html.erb +++ b/app/views/courses/settings/_members.html.erb @@ -76,7 +76,7 @@ <%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript autocomplete_course_memberships_path(@course, :format => 'js') }')" %>
<%= l(:label_role_plural) %>: diff --git a/app/views/members/autocomplete.js.erb b/app/views/members/autocomplete.js.erb index ba98983d3..e7a52f7f3 100644 --- a/app/views/members/autocomplete.js.erb +++ b/app/views/members/autocomplete.js.erb @@ -1 +1,5 @@ + <% if @project%> $('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_new_members(@project)) %>'); + <% elsif @course%> + $('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_new_course_members(@course)) %>'); + <%end%>