添加项目管理员审核已申请用户界面及逻辑
This commit is contained in:
parent
80e84069a1
commit
dd4ef11b3d
|
@ -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' }
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
@ -798,6 +799,19 @@ class ProjectsController < ApplicationController
|
|||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$('#principals_for_applied_member').html('<%= escape_javascript(render_principals_for_applied_members(@project)) %>');
|
|
@ -120,6 +120,30 @@
|
|||
|
||||
<div class="splitcontentright">
|
||||
<% if r.any? %>
|
||||
<% if @project.applied_projects.any? %>
|
||||
<div id="applied_project_block">
|
||||
<%= form_for(@applied_members, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %>
|
||||
<fieldset>
|
||||
<legend><%= l(:label_apply_project) %></legend>
|
||||
|
||||
<div id="principals_for_applied_member">
|
||||
<%= render_principals_for_applied_members(@project) %>
|
||||
</div>
|
||||
<!--show the roles which will select-->
|
||||
<p style="padding-top: 5px"><%= l(:label_role_plural) %>:
|
||||
<% r.each do |role| %>
|
||||
|
||||
<label><%= check_box_tag 'membership[role_ids][]', role.id %> <%= h role %></label>
|
||||
<% end %></p>
|
||||
|
||||
<p><%= submit_tag l(:label_approve), :id => 'member-add-submit' %>
|
||||
<%= submit_tag l(:label_refusal), :name => "refusal_button", :id => 'member-refusal-submit' %>
|
||||
</p>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_for(@member, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %>
|
||||
<fieldset><legend><%=l(:label_member_new)%></legend>
|
||||
|
||||
|
|
|
@ -147,6 +147,8 @@ en:
|
|||
general_pdf_encoding: UTF-8
|
||||
general_first_day_of_week: '7'
|
||||
|
||||
label_approve: Approve
|
||||
label_refusal: Refusal
|
||||
notice_account_updated: Account was successfully updated.
|
||||
notice_account_invalid_creditentials: Invalid user or password
|
||||
notice_account_password_updated: Password was successfully updated.
|
||||
|
|
|
@ -155,6 +155,9 @@ zh:
|
|||
general_pdf_encoding: gb18030
|
||||
general_first_day_of_week: '7'
|
||||
|
||||
label_approve: 批准
|
||||
label_refusal: 拒绝
|
||||
|
||||
notice_account_updated: 帐号更新成功
|
||||
notice_account_invalid_creditentials: 无效的用户名或密码
|
||||
notice_account_invalid_creditentials_new: 您还未到邮箱激活
|
||||
|
|
|
@ -300,6 +300,7 @@ RedmineApp::Application.routes.draw do
|
|||
resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do
|
||||
collection do
|
||||
get 'autocomplete'
|
||||
get 'appliedproject'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue