diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index 0bf9394a..fdb45b03 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -4,7 +4,11 @@ class AppliedProjectController < ApplicationController def applied_join_project @user_id = params[:user_id] @project = Project.find(params[:project_id]) - AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) + @applieds = AppliedProject.where("user_id = ? and project_id = ?", params[:user_id],params[:project_id]) + if @applieds.count == 0 + AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id]) + end + #redirect_to project_path(params[:project_id]) #redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true} respond_to do |format| @@ -16,10 +20,11 @@ class AppliedProjectController < ApplicationController #取消申请 def unapplied_join_project @project = Project.find(params[:project_id]) - @applied = AppliedProject.find(params[:id]) - @applied.destroy - #redirect_to project_path(params[:project_id]) - #redirect_to_referer_or {render :text => ( 'unsubscribe success.'), :layout => true} + #@applied = AppliedProject.find(params[:id]) + #@applied.destroy + + AppliedProject.deleteappiled(params[:user_id], params[:project_id]) + respond_to do |format| format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.js { render :partial => 'set_applied' } diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 5168913a..127fa5d3 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -46,42 +46,55 @@ class MembersController < ApplicationController end def create - members = [] - project_info = [] - user_grades = [] - if params[:membership] - if params[:membership][:user_ids] - attrs = params[:membership].dup - user_ids = attrs.delete(:user_ids) - user_ids.each do |user_id| - members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) - user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id) - ## added by nie - if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") - project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) - # ProjectInfo.create(:name => "test", :user_id => 123) + if params[:refusal_button] + if params[:membership] + if params[:membership][:user_ids] + attrs = params[:membership].dup + user_ids = attrs.delete(:user_ids) + user_ids.each do |user_id| + AppliedProject.deleteappiled(user_id, @project.id) end - ## end end - else - members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) - user_grades << UserGrade.new(:user_id => params[:membership][:user_id], :project_id => @project.id) - ## added by nie - if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") - project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id]) - end - ## end end - @project.members << members - # added by nie - @project.project_infos << project_info - @project.user_grades << user_grades - # end + else + members = [] + project_info = [] + user_grades = [] + if params[:membership] + if params[:membership][:user_ids] + attrs = params[:membership].dup + user_ids = attrs.delete(:user_ids) + user_ids.each do |user_id| + members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) + user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id) + ## added by nie + if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") + project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) + # ProjectInfo.create(:name => "test", :user_id => 123) + end + ## end + AppliedProject.deleteappiled(user_id, @project.id) + end + else + members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) + user_grades << UserGrade.new(:user_id => params[:membership][:user_id], :project_id => @project.id) + ## added by nie + if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") + project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id]) + end + ## end + end + @project.members << members + # added by nie + @project.project_infos << project_info + @project.user_grades << user_grades + # end + end end respond_to do |format| format.html { redirect_to_settings_in_projects } - format.js { @members = members } + format.js { @members = members;@applied_members = members; } format.api { @member = members.first if @member.valid? diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 32fc3dd5..5d270401 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -767,6 +767,7 @@ class ProjectsController < ApplicationController @subPage_title = l :label_member_list @members = @project.member_principals.includes(:roles, :principal).all @members = sort_project_members(@project, @members) + @applied_members = appied_project_members(@project, @members) end @members = paginateHelper @members render :layout => 'base_courses' if @project.project_type == 1 @@ -797,7 +798,20 @@ class ProjectsController < ApplicationController end memberlist end - + + def appied_project_members (project, members) + users = AppliedProject.where(:project_id => project.id). + memberlist = [] + users.each do |user| + members.each do |member| + if member[:user_id] == user[:user_id] + memberlist << member + end + end + end + memberlist + end + def file end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 75676f47..91e05d6a 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -32,4 +32,21 @@ module MembersHelper 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]) + 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, appliedproject_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true + } + + s + content_tag('div', content_tag('ul', links), :class => 'applied_new') + end + end diff --git a/app/models/applied_project.rb b/app/models/applied_project.rb index 04056cad..accbc90e 100644 --- a/app/models/applied_project.rb +++ b/app/models/applied_project.rb @@ -2,5 +2,14 @@ class AppliedProject < ActiveRecord::Base attr_accessible :project_id, :user_id belongs_to :user - belongs_to :project + belongs_to :project + + #删除用户申请 + def self.deleteappiled(userid, projectid) + @applieds = AppliedProject.where("user_id = ? and project_id = ?", userid, projectid) + @applieds.each do |applied| + applied.destroy + end + end + end diff --git a/app/models/principal.rb b/app/models/principal.rb index b6f41d53..15cebdf5 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -72,6 +72,12 @@ class Principal < ActiveRecord::Base } scope :sorted, lambda { order(*Principal.fields_for_order_statement)} + scope :applied_members, lambda {|project| + id = project.id + ids1 = project.applied_projects.map(&:user_id) + where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE user_id in (?))", ids1) + } + before_create :set_default_empty_values def name(formatter = nil) diff --git a/app/models/project.rb b/app/models/project.rb index 5da9f674..1c672c5f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -66,6 +66,7 @@ class Project < ActiveRecord::Base has_one :course_extra, :class_name => 'Course', :foreign_key => :extra,:primary_key => :identifier, :dependent => :destroy has_many :applied_projects + # end #ADDED BY NIE has_many :project_infos, :dependent => :destroy diff --git a/app/views/members/appliedproject.js.erb b/app/views/members/appliedproject.js.erb new file mode 100644 index 00000000..f28558ef --- /dev/null +++ b/app/views/members/appliedproject.js.erb @@ -0,0 +1 @@ +$('#principals_for_applied_member').html('<%= escape_javascript(render_principals_for_applied_members(@project)) %>'); diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb index 828cb7f8..f97e9d0f 100644 --- a/app/views/projects/settings/_members.html.erb +++ b/app/views/projects/settings/_members.html.erb @@ -120,6 +120,30 @@