diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index b6fed88af..7542ef3ee 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -315,20 +315,18 @@ class UsersController < ApplicationController
# status
def deal_with_apply_resource
@msg = CourseMessage.find(params[:msg_id])
- ah = ApplyHomework.where("user_id = ? and homework_common_id = ?",@msg.apply_user_id, @msg.course_message_id)
- case params[:agree]
- when 'Y'
- unless ah.empty?
- ah.first.update_column('status', 2)
- CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
- @msg.update_attributes(:apply_result=>1,:viewed=>1)
- end
- when 'N'
- unless ah.empty?
- ah.first.update_column('status', 3)
- CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
- @msg.update_attributes(:apply_result=>2,:viewed=>1)
- end
+ ar = ApplyResource.where("id = ?", @msg.course_message_id).first
+ unless ar.nil?
+ case params[:agree]
+ when 'Y'
+ ar.update_column('status', 2)
+ @msg.update_attributes(:apply_result => 1, :viewed => 1)
+ ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 2, :status => 1)
+ when 'N'
+ ar.update_column('status', 3)
+ @msg.update_attributes(:apply_result => 2, :viewed => 1)
+ ar.course_messages << CourseMessage.new(:user_id => ar.user_id, :course_id => -1, :viewed => false, :apply_result => 3, :status => 1)
+ end
end
respond_to do |format|
format.js
diff --git a/app/models/apply_resource.rb b/app/models/apply_resource.rb
index ac65c0e3d..df646166c 100644
--- a/app/models/apply_resource.rb
+++ b/app/models/apply_resource.rb
@@ -7,9 +7,13 @@ class ApplyResource < ActiveRecord::Base
after_create :act_as_apply_resource_message
def act_as_apply_resource_message
- self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => self.container_id, :viewed => false, :status => 5)
+ self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, )
# REDO:发送邮件
# Mailer.run.apply_for_resource_request(self.container_id, User.current)
end
+ def find_attachment attachment_id
+ Attachment.find(attachment_id)
+ end
+
end
diff --git a/app/models/course_message.rb b/app/models/course_message.rb
index 703da936b..59fcfe456 100644
--- a/app/models/course_message.rb
+++ b/app/models/course_message.rb
@@ -1,5 +1,7 @@
class CourseMessage < ActiveRecord::Base
# status说明: status在课程不同的类型,区分不同的功能 status = 9 作品的提交记录
+ # ApplyResource status:
+ # 0: 发送申请 1:回复允许申请 2:拒绝申请消息
# HomeworkCommon:status:
# nil:发布了作业; 1:作业截止时间到了提醒!;2:开启匿评; 3:关闭匿评; 4:匿评开始失败; 5:申请引用作业, 6:申请结果
# apply_user_id: 申请者的用户id
diff --git a/app/views/users/_apply_resource_course_message.html.erb b/app/views/users/_apply_resource_course_message.html.erb
index 154ae3172..55dcb4d22 100644
--- a/app/views/users/_apply_resource_course_message.html.erb
+++ b/app/views/users/_apply_resource_course_message.html.erb
@@ -9,16 +9,16 @@
<% content = ma.course_message.content.nil? ? '' : ':'+ ma.course_message.content.to_s %>
- " class = "<%= ma.viewed == 0 ? "newsBlack" : "newsGrey "%>">
- <%= ma.course_message.user.show_name + "申请引用资源\""+"#{ma.course_message.attachment.try(:name)}"+"\"#{content}" %>
+ " class = "<%= ma.viewed == 0 ? "newsBlack" : "newsGrey "%>">
+ <%= ma.course_message.user.show_name + "申请引用资源\""+"#{ma.course_message.user.try(:name)}"+"\"#{content}" %>
-
- <% if ma.apply_result == 0 || ma.apply_result.nil?%>
- <%= link_to '同意', dealwith_apply_homework_user_path(User.current,:agree => 'Y', :msg_id => ma.id), :remote => 'true' %> |
- <%= link_to '拒绝', dealwith_apply_homework_user_path(User.current, :agree => 'N', :msg_id => ma.id), :remote => 'true' %>
+
+ <% if ma.apply_result == 0 || ma.apply_result.nil? %>
+ <%= link_to '同意', deal_with_apply_resource_user_path(User.current, :agree => 'Y', :msg_id => ma.id, :apply_user_id => ma.course_message.apply_user_id), :remote => 'true' %> |
+ <%= link_to '拒绝', deal_with_apply_resource_user_path(User.current, :agree => 'N', :msg_id => ma.id, :apply_user_id => ma.course_message.apply_user_id), :remote => 'true' %>
<% elsif ma.apply_result == 1 %>
您已经同意了该申请
<% elsif ma.apply_result == 2 %>
diff --git a/app/views/users/_apply_resource_course_message_reply.html.erb b/app/views/users/_apply_resource_course_message_reply.html.erb
new file mode 100644
index 000000000..4869c4393
--- /dev/null
+++ b/app/views/users/_apply_resource_course_message_reply.html.erb
@@ -0,0 +1,21 @@
+
+ -
+ <% owner = User.find(ma.course_message.apply_user_id) %>
+
+ <%= link_to image_tag(url_to_avatar(owner), :width => "30", :height => "30", class: "mt3"), user_path(owner) %>
+
+
+ -
+ <%= link_to owner.show_name, user_path(owner), :class => "newsBlue homepageNewsPublisher" %>
+ "><%= ma.apply_result == 1 ? '同意' : '拒绝'%>引用资源:
+
+ -
+ <% link_str = ma.apply_result == 1 ?
+ '您申请引用资源"'+ ma.course_message.find_attachment(ma.course_message.apply_user_id).try(:filename) + '"的申请已通过'
+ :
+ '您申请引用资源"'+ ma.course_message.find_attachment(ma.course_message.apply_user_id).try(:filename) + '"的申请被婉拒' %>
+ <%= link_to link_str, user_resource_user_path(User.current, :type => 2), :title => link_str,:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey "}" %>
+
+
+ - <%= time_tag(ma.created_at).html_safe %>
+
\ No newline at end of file
diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb
index 9befe2b0b..8e3aa4873 100644
--- a/app/views/users/_user_message_course.html.erb
+++ b/app/views/users/_user_message_course.html.erb
@@ -235,11 +235,17 @@
<% end %>
- <% if ma.course_message_type == "ApplyResource" %>
-
+ <% if ma.course_message_type == "ApplyResource" && ma.status == 0 %>
+
<%= render :partial => 'apply_resource_course_message', :locals => {:ma => ma} %>
<% end %>
+
+ <% if ma.course_message_type == "ApplyResource" && ma.status == 1 %>
+
+ <%= render :partial => 'apply_resource_course_message_reply', :locals => {:ma => ma} %>
+
+ <% end %>
<% if ma.course_message_type == "HomeworkCommon" && ma.status == 6 %>
<%= image_tag(url_to_avatar(User.find(ma.apply_user_id)), width: "30px", height: "30px", class: "mt3") %>
diff --git a/app/views/users/deal_with_apply_resource.js.erb b/app/views/users/deal_with_apply_resource.js.erb
new file mode 100644
index 000000000..dbf07217c
--- /dev/null
+++ b/app/views/users/deal_with_apply_resource.js.erb
@@ -0,0 +1 @@
+$("#apply_resource_message_<%= @msg.id %>").html('<%= escape_javascript(render :partial => 'users/apply_resource_course_message', :locals => {:ma => @msg}) %>');
\ No newline at end of file
diff --git a/app/views/users/user_resource.html.erb b/app/views/users/user_resource.html.erb
index f7e239d97..0bd5724c1 100644
--- a/app/views/users/user_resource.html.erb
+++ b/app/views/users/user_resource.html.erb
@@ -56,7 +56,7 @@
我的资源
- 私有资源
+ 私有资源
diff --git a/config/routes.rb b/config/routes.rb
index 85e3198a3..98d90c753 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -623,6 +623,7 @@ RedmineApp::Application.routes.draw do
post 'import_resources_to_homework'
get 'dealwith_apply_request'
get 'dealwith_apply_homework'
+ get 'deal_with_apply_resource'
get 'store_selected_resource'
get 'user_organizations'
get 'search_user_orgs'