课程添加成员逻辑更改

This commit is contained in:
nwb 2014-06-16 15:00:35 +08:00
parent 2a4486bf0d
commit b4e78d2b0c
4 changed files with 34 additions and 1 deletions

View File

@ -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])

View File

@ -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|

View File

@ -76,7 +76,7 @@
<%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript autocomplete_course_memberships_path(@course, :format => 'js') }')" %>
<div id="principals_for_new_member">
<%= render_principals_for_new_members(@course) %>
<%= render_principals_for_new_course_members(@course) %>
</div>
<!--show the roles which will select-->
<p style="padding-top: 5px"><%= l(:label_role_plural) %>:

View File

@ -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%>