From 94b36e227c50c071e51040ba05bef02ed25560ff Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 2 Aug 2016 13:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=B6=88=E6=81=AF=E5=88=B7=E6=96=B0=EF=BC=8C=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=E5=85=B6=E5=AE=83=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E6=B6=88=E6=81=AF=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/members_controller.rb | 27 +++++++++++++------ .../members/allow_to_join_project.js.erb | 2 +- .../refused_allow_to_join_project.js.erb | 2 +- .../users/_applied_project_content.html.erb | 15 +++++++++++ .../_user_message_applide_action.html.erb | 1 + .../users/_user_message_applied.html.erb | 21 ++------------- 6 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 app/views/users/_applied_project_content.html.erb diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 0a76cfb78..9cac4de3d 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -75,13 +75,19 @@ class MembersController < ApplicationController project.members << members project.project_infos << project_info project.user_grades << user_grades unless user_grades.first.user_id.nil? - @applied_message.update_attribute(:status, 2) + + # 添加成功后所有管理员收到的消息状态都要更新 + applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1, + :applied_type => "AppliedProject") + applied_messages.update_all(:status => 7) + @applied_message = AppliedMessage.find(params[:applied_message_id]) # 添加成功后,申请人收到消息 AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id , - :status => 6, :viewed => true, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id) + :status => 6, :viewed => false, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id) + # 添加成功后,批准人收到消息 - AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id , - :status => 7, :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) + # AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id , + # :status => 7, :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) rescue Exception => e puts e end @@ -95,14 +101,19 @@ class MembersController < ApplicationController # status(1:申请的消息;2:已操作过该消息(包括同意或者拒绝,消息状态更新);3:拒绝消息;4:被拒人收到消息;5:拒绝者收到消息;6:同意后申请人收到消息;7:同意后批准人收到消息) def refused_allow_to_join_project @applied_message = AppliedMessage.find(params[:applied_message_id]) - @applied_message.update_attribute(:status, 3) + # @applied_message.update_attribute(:status, 3) applied_project = @applied_message.applied # 发送消息给被拒者,user_id对应的收到信息的用户 AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4, :viewed => true, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id) - # 发送消息给拒绝者 - AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5, - :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) + + # 拒绝功后所有管理员收到的消息状态都要更新 + applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1, + :applied_type => "AppliedProject") + applied_messages.update_all(:status => 5) + @applied_message = AppliedMessage.find(params[:applied_message_id]) + # AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5, + # :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id) applied_project.delete end diff --git a/app/views/members/allow_to_join_project.js.erb b/app/views/members/allow_to_join_project.js.erb index cbd37e188..222511942 100644 --- a/app/views/members/allow_to_join_project.js.erb +++ b/app/views/members/allow_to_join_project.js.erb @@ -1,5 +1,5 @@ <% if @flash_message %> alert("<%= @flash_message %>"); <% else%> - $("#applied_project_<%= @applied_message.id %>").html('<%= render :partial => "users/user_message_applide_action", :locals =>{:ma => @applied_message} %>'); + $("#applied_project_<%= @applied_message.id %>").html('<%= escape_javascript(render :partial => 'users/applied_project_content', :locals => {:ma => @applied_message}) %>'); <% end%> diff --git a/app/views/members/refused_allow_to_join_project.js.erb b/app/views/members/refused_allow_to_join_project.js.erb index 109ed3a62..57211334f 100644 --- a/app/views/members/refused_allow_to_join_project.js.erb +++ b/app/views/members/refused_allow_to_join_project.js.erb @@ -1 +1 @@ -$("#applied_project_<%= @applied_message.id %>").html('<%= render :partial => "users/user_message_applide_action", :locals =>{:ma => @applied_message} %>'); \ No newline at end of file +$("#applied_project_<%= @applied_message.id %>").html('<%= escape_javascript(render :partial => 'users/applied_project_content', :locals => {:ma => @applied_message}) %>'); \ No newline at end of file diff --git a/app/views/users/_applied_project_content.html.erb b/app/views/users/_applied_project_content.html.erb new file mode 100644 index 000000000..2d9c7b109 --- /dev/null +++ b/app/views/users/_applied_project_content.html.erb @@ -0,0 +1,15 @@ +
  • + <%=link_to image_tag(url_to_avatar(applied_project_users(ma)), :width => "30", :height => "30"), user_path(applied_project_users(ma)), :target => '_blank' %> +
  • +
  • + <%= render :partial => "users/user_message_applide_users", :locals =>{:ma => ma} %> +
  • +
  • + 以“<%= applied_project_message_type(ma.role) %>”身份加入<% project = Project.find(ma.project_id) %> + <%= link_to project.name, project_path(ma.project_id), :class => "link-blue", :target => '_blank', :title => "#{project.name}" %> + +
  • +
  • + <%= render :partial => "users/user_message_applide_action", :locals =>{:ma => ma} %> +
  • +
  • <%= time_tag(ma.created_at).html_safe %>
  • \ No newline at end of file diff --git a/app/views/users/_user_message_applide_action.html.erb b/app/views/users/_user_message_applide_action.html.erb index 48e479b22..a8b5598fa 100644 --- a/app/views/users/_user_message_applide_action.html.erb +++ b/app/views/users/_user_message_applide_action.html.erb @@ -1,3 +1,4 @@ +<% ma = ma.nil? ? @applied_message : ma %> <% if allow_to_show(ma) %> <%= link_to "同意", allow_to_join_project_project_memberships_path(:project_id => ma.project_id, :applied_message_id => ma.id), :remote => true, :method => :post, :class => "link-blue"%> | <%= link_to "拒绝", refused_allow_to_join_project_project_memberships_path(:project_id => ma.project_id, :applied_message_id => ma.id), :remote => true, :method => :get, :class => "link-blue" %> diff --git a/app/views/users/_user_message_applied.html.erb b/app/views/users/_user_message_applied.html.erb index dbe01c4b4..6d853f01c 100644 --- a/app/views/users/_user_message_applied.html.erb +++ b/app/views/users/_user_message_applied.html.erb @@ -47,25 +47,8 @@ <% end %> <% elsif ma && ma.applied_type == "AppliedProject" %> -