From dd4ef11b3d33c0b2b42309c220e8c0b548efaa8c Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 22 May 2014 11:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=AE=A1=E6=A0=B8=E5=B7=B2=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=95=8C=E9=9D=A2=E5=8F=8A=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/applied_project_controller.rb | 15 ++-- app/controllers/members_controller.rb | 71 +++++++++++-------- app/controllers/projects_controller.rb | 16 ++++- app/helpers/members_helper.rb | 17 +++++ app/models/applied_project.rb | 11 ++- app/models/principal.rb | 6 ++ app/models/project.rb | 1 + app/views/members/appliedproject.js.erb | 1 + app/views/projects/settings/_members.html.erb | 24 +++++++ config/locales/en.yml | 2 + config/locales/zh.yml | 3 + config/routes.rb | 1 + 12 files changed, 132 insertions(+), 36 deletions(-) create mode 100644 app/views/members/appliedproject.js.erb diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index 0bf9394aa..fdb45b030 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 5168913a7..127fa5d3a 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 32fc3dd57..5d270401a 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 75676f475..91e05d6a8 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 04056cadc..accbc90e2 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 b6f41d535..15cebdf53 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 5da9f674e..1c672c5fc 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 000000000..f28558ef6 --- /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 828cb7f8c..f97e9d0f2 100644 --- a/app/views/projects/settings/_members.html.erb +++ b/app/views/projects/settings/_members.html.erb @@ -120,6 +120,30 @@
<% if r.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) %> + +
+ <%= render_principals_for_applied_members(@project) %> +
+ +

<%= l(:label_role_plural) %>: + <% r.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)%> diff --git a/config/locales/en.yml b/config/locales/en.yml index e7d24c329..303e50b93 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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. diff --git a/config/locales/zh.yml b/config/locales/zh.yml index b5d9639db..77a6a005e 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 您还未到邮箱激活 diff --git a/config/routes.rb b/config/routes.rb index 6a4b1d7a3..5db37b55c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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