From 4a9eec0ccec9a220be803da7522264a78ad30343 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 28 Jul 2016 14:42:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A1=B9=E7=9B=AE=E9=82=80?= =?UTF-8?q?=E8=AF=B7=E5=8F=8A=E5=85=AC=E5=85=B1=E5=BC=B9=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/applied_project_controller.rb | 14 ++++++----- app/helpers/watchers_helper.rb | 8 +++--- app/models/project.rb | 5 ++++ .../_applied_join_project.html.erb | 10 ++++---- .../_applied_project_tip.js.erb | 25 +++++++++++++++++++ .../applied_join_project.js.erb | 8 +++--- .../applied_project_info.js.erb | 2 ++ config/locales/projects/zh.yml | 2 +- .../20160728041943_add_qrcode_to_project.rb | 5 ++++ db/schema.rb | 14 ++++++++++- public/javascripts/application.js | 24 ++++++++++-------- public/stylesheets/css/popup.css | 10 +++++--- 12 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 app/views/applied_project/_applied_project_tip.js.erb create mode 100644 db/migrate/20160728041943_add_qrcode_to_project.rb diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index 9ae3a5c4e..d8e6c5f12 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -2,9 +2,8 @@ class AppliedProjectController < ApplicationController #申请加入项目 def applied_join_project - + @project = Project.find_by_id(params[:object_id]) # @user_id = params[:user_id] - # @project = Project.find_by_id(params[:project_id]) # if params[:project_join] # if @project # user = User.find @user_id @@ -51,13 +50,16 @@ class AppliedProjectController < ApplicationController @flag = 1 elsif User.current.member_of?(@project) @flag = 2 - elsif params[:member_manager] != "on" || params[:member_developer] != "on" || params[:member_reporter] != "on" + elsif params[:member].nil? @flag = 3 else @flag = 4 - end - if @flag == 4 - + applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => params[:project_id]) + # 申请成功则给项目管理员发送邮件及发送消息 + Mailer.run.applied_project(appliedproject) + @project.managers.each do |member| + AppliedMessage.create(:user_id => member.user_id, :status => true, :applied_id => applied_project.id, :applied_type => "AppliedProject", :viewed => true) + end end end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 8c2db4005..254ce1ad7 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -368,13 +368,13 @@ module WatchersHelper def join_in_project_link(project, user, options=[]) applied = project.applied_projects.find_by_user_id(user.id) text = applied ? l(:label_unapply_project) : l(:label_apply_project) - url = applied ? unapplied_join_project_path(:object_id => project.id) : applied_join_project_path(:object_id => project.id) - method = applied ? 'delete' : 'post' + url = applied_join_project_path(:object_id => project.id) + method = 'post' @applied_flag = project.instance_of?(Project) if applied - link = link_to(text, url, :remote => true, :method => method, :class => "sy_btn_grey fl", :id => "#{project.id}") + link = "text" else - link = link_to(text, url, :remote => true, :method => method, :id => "#{project.id}", :class => "sy_btn_grey fl") + link = link_to(text, url, :remote => true, :method => method, :id => "#{project.id}", :class => "pr_join_a") end link.html_safe # if applied diff --git a/app/models/project.rb b/app/models/project.rb index 520407589..edeee4f33 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -268,6 +268,11 @@ class Project < ActiveRecord::Base notified.collect(&:mail) end + # 返回为member类型数组 + def managers + self.members.includes(:roles).select{|member| member.roles[0].try(:name) == "Manager"} + end + def initialize(attributes=nil, *args) super diff --git a/app/views/applied_project/_applied_join_project.html.erb b/app/views/applied_project/_applied_join_project.html.erb index 435be7f5e..ad2d020c2 100644 --- a/app/views/applied_project/_applied_join_project.html.erb +++ b/app/views/applied_project/_applied_join_project.html.erb @@ -1,10 +1,10 @@

欢迎加入项目

- +
- <%= form_tag( url_for(:controller => 'applied_project', :action => 'applied_project_info', :project_id => @project.id), :id => 'project_applied_form') do %> + <%= form_tag( url_for(:controller => 'applied_project', :action => 'applied_project_info', :project_id => @project.id), :remote => true, :id => 'project_applied_form') do %>