diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index c4c1f8922..e20a5a868 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -78,8 +78,8 @@ 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 diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 85f9a64ad..95327edd1 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -19,23 +19,37 @@ module HomeworkAttachHelper 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] + principals = paginateHelper members,10 + #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') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options| + link_to text, new_homework_attach_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true } + return 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" + s << "
" end s.html_safe end + + def paginateHelper obj, pre_size=20 + @obj_count = obj.count + @obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page'] + if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation + obj.limit(@obj_pages.per_page).offset(@obj_pages.offset) + elsif obj.kind_of? Array + obj[@obj_pages.offset, @obj_pages.per_page] + else + logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" + raise RuntimeError, 'unknow type, Please input you type into this helper.' + end + end end \ No newline at end of file diff --git a/app/views/homework_attach/_homework_member.html.erb b/app/views/homework_attach/_homework_member.html.erb index f69f9edff..ed268f652 100644 --- a/app/views/homework_attach/_homework_member.html.erb +++ b/app/views/homework_attach/_homework_member.html.erb @@ -1,131 +1,30 @@ <%= error_messages_for 'member' %> -<% - roles = Role.givable.all - if @project.project_type == Project::ProjectType_course - roles = roles[3..5] - else - roles = roles[0..2] - end - members = @project.member_principals.includes(:roles, :principal).all.sort -%> - -
- <% if members.any? %> - - - - - - - <%= call_hook(:view_projects_settings_members_table_header, :project => @project) %> +
+
<%= l(:label_user) %><%= l(:label_role_plural) %>
+ + + + + + + + + + + - - - <% members.each do |member| %> - <% next if member.new_record? %> - - - - - <% if @project.project_type == 1 %> - <% if member.roles.first.to_s == "Manager" %> - - <% else %> - - <% end %> - <% else %> - - <% end %> - - <%= call_hook(:view_projects_settings_members_table_row, {:project => @project, :member => member}) %> - - <% end; reset_cycle %> - -
<%= l(:label_user) %><%= l(:label_role_plural) %>
<%= link_to_user User.current %> 发布人员
<%= link_to_user member.principal %> - - <%= h member.roles.sort.collect(&:to_s).join(', ') %> - - <%= form_for(member, {:as => :membership, :remote => true, :url => membership_path(member), - :method => :put, - :html => {:id => "member-#{member.id}-roles-form", :class => 'hol'}} - ) do |f| %> - -

- <% roles.each do |role| %> -
- <% end %>

- <%= hidden_field_tag 'membership[role_ids][]', '' %> -

<%= submit_tag l(:button_change), :class => "small" %> - <%= link_to_function l(:button_cancel), - "$('#member-#{member.id}-roles').show(); $('#member-#{member.id}-roles-form').hide(); return false;" - %>

- <% end %> -
- <%= link_to_function l(:button_edit), - "$('#member-#{member.id}-roles').hide(); $('#member-#{member.id}-roles-form').show(); return false;", - :class => 'icon icon-edit' %> - <%= delete_link membership_path(member), - :remote => true, - :data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {}) if member.deletable? %> - - <%= link_to_function l(:button_edit), - "$('#member-#{member.id}-roles').hide(); $('#member-#{member.id}-roles-form').show(); return false;", - :class => 'icon icon-edit' %> - <%= delete_link membership_path(member), - :remote => true, - :data => (!User.current.admin? && member.include?(User.current) ? {:confirm => l(:text_own_membership_delete_confirmation)} : {}) if member.deletable? %> -
- <% else %> -

<%= l(:label_no_data) %>

- <% end %> + +
-
- <% if roles.any? %> - <% if @project.applied_projects.any? %> -
- <%= form_for(@applied_members, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %> -
- <%= l(:label_apply_project) %> +
+
+ <%= l(:label_member_new) %> -
- <%= render_principals_for_applied_members(@project) %> -
- -

<%= l(:label_role_plural) %>: - <% roles.each do |role| %> - - - <% end %>

- -

<%= submit_tag l(:label_approve), :id => 'member-add-submit' %> - <%= submit_tag l(:label_refusal), :name => "refusal_button", :id => 'member-refusal-submit' %> -

-
- <% end %> -
- <% end %> - - <%= form_for(@member, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %> -
- <%= l(:label_member_new) %> - -

<%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %>

- <%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript autocomplete_project_memberships_path(@project, :format => 'js') }')" %> - -
- <%= render_principals_for_new_members(@project) %> -
- -

<%= l(:label_role_plural) %>: - <% roles.each do |role| %> - - - <% end %>

- -

<%= submit_tag l(:button_add), :id => 'member-add-submit' %>

-
- <% end %> - <% end %> +

<%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %>

+
+ <%= render_new_members_for_homework(members) %> +
+

<%= submit_tag l(:button_add), :id => 'member-add-submit' %>

+
diff --git a/app/views/homework_attach/_new_homework.html.erb b/app/views/homework_attach/_new_homework.html.erb index 9ff3e2ffe..de749d182 100644 --- a/app/views/homework_attach/_new_homework.html.erb +++ b/app/views/homework_attach/_new_homework.html.erb @@ -1,5 +1,4 @@
-

标 题: <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb index 0ead4babd..07475f58d 100644 --- a/app/views/homework_attach/new.html.erb +++ b/app/views/homework_attach/new.html.erb @@ -36,8 +36,8 @@ <%= render :partial => "new_homework",:locals => {:f => f} %>

-
- <%= render :partial => "homework_member" %> +