申请资源消息资源发布这收到消息
This commit is contained in:
parent
658ea0cf1e
commit
f3f75a57bd
|
@ -311,6 +311,30 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 处理资源引用请求
|
||||
# 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
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#处理引用作业的请求
|
||||
#status 1 同意 2 拒绝
|
||||
def dealwith_apply_homework
|
||||
|
@ -419,6 +443,19 @@ class UsersController < ApplicationController
|
|||
end
|
||||
# end
|
||||
|
||||
# 资源分享请求弹框
|
||||
def apply_resource
|
||||
if User.current.logged?
|
||||
@attachment = Attachment.find params[:attachment_id]
|
||||
@state = 2
|
||||
else
|
||||
@state = 1
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#引用作业请求弹框
|
||||
def apply_homework
|
||||
if User.current.logged?
|
||||
|
@ -432,6 +469,27 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 申请引用资源
|
||||
def apply_for_resource
|
||||
if User.current.logged?
|
||||
@attachment = Attachment.where("id =?", params[:attachment_id].to_i).first
|
||||
unless @attachment.nil?
|
||||
ar = ApplyResource.where("user_id = ? and attachment_id = ?", User.current.id, params[:attacment_id].to_i)
|
||||
if ar.empty?
|
||||
ApplyResource.create(:user_id => params[:id].to_i, :attachment_id => params[:attachment_id].to_i, :status => true, :container_id => @attachment.container_id, :container_type => @attachment.container_type, :content => params[:content], :apply_user_id => @attachment.author_id)
|
||||
@state = 2
|
||||
else
|
||||
@state = 3
|
||||
end
|
||||
end
|
||||
else
|
||||
@state = 1
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#申请引用非公开作业
|
||||
def apply_for_homework
|
||||
if User.current.logged?
|
||||
|
@ -2608,7 +2666,7 @@ class UsersController < ApplicationController
|
|||
|
||||
# 获取公共资源
|
||||
def get_public_resources user_course_ids, user_project_ids, order, score
|
||||
attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取公共资源搜索
|
||||
|
@ -2637,6 +2695,17 @@ class UsersController < ApplicationController
|
|||
and is_publish = 1 and container_id is not null)" ).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我的私有资源分享结果
|
||||
def get_my_private_resources apply_ids, resource_type, order, score
|
||||
attachments = Attachment.where("id in (#{apply_ids.empty? ? '0': apply_ids.join(',')}) and container_type in(#{resource_type})").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我的私有资源分享结果
|
||||
def get_course_private_resources author_id, user_course_ids, order, score
|
||||
apply_id = ApplyResource.where("user_id =?", author_id).map{|ar| ar.attachment_id}
|
||||
attachments = Attachment.where("user_id =? and attachment_id =?")
|
||||
end
|
||||
|
||||
# 获取我的课程资源中搜索结果
|
||||
def get_course_resources_search author_id, user_course_ids, order, score, search
|
||||
attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+
|
||||
|
@ -2646,12 +2715,12 @@ class UsersController < ApplicationController
|
|||
|
||||
# 获取公共资源中课程资源
|
||||
def get_course_resources_public user_course_ids, order, score
|
||||
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1)").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取公共资源中课程资源搜索结果
|
||||
def get_course_resources_public_search user_course_ids, order, score, search
|
||||
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我的项目资源
|
||||
|
@ -2670,12 +2739,12 @@ class UsersController < ApplicationController
|
|||
|
||||
# 获取公共资源的项目资源
|
||||
def get_project_resources_public user_project_ids, order, score
|
||||
attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("container_type = 'Project' and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取公共资源的项目资源搜索
|
||||
def get_project_resources_public_search user_project_ids, order, score, search
|
||||
attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("(container_type = 'Project' and container_id is not null) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我上传的附件
|
||||
|
@ -2693,13 +2762,13 @@ class UsersController < ApplicationController
|
|||
# 获取公共资源中我上传的附件
|
||||
def get_attch_resources_public order, score
|
||||
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
|
||||
and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取公共资源中我上传的附件
|
||||
def get_attch_resources_public_search order, score, search
|
||||
attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')
|
||||
and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我的用户类型资源
|
||||
|
@ -2714,12 +2783,12 @@ class UsersController < ApplicationController
|
|||
|
||||
# 获取我的用户类型资源
|
||||
def get_principal_resources_public order, score
|
||||
attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("container_type = 'Principal'and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 获取我的用户类型资源
|
||||
def get_principal_resources_public_search order, score, search
|
||||
attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
attchments = Attachment.where("(container_type = 'Principal'and container_id is not null) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}")
|
||||
end
|
||||
|
||||
# 资源库 分为全部 课程资源 项目资源 附件
|
||||
|
@ -2761,6 +2830,20 @@ class UsersController < ApplicationController
|
|||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
|
||||
end
|
||||
elsif params[:type] == "2" # 私有资源
|
||||
apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
|
||||
# apply_id = ApplyResource.where("user_id =?", author_id).map{|ar| ar.attachment_id}
|
||||
if params[:status] == "2"
|
||||
resource_type = "'Course'"
|
||||
elsif params[:status] == "3"
|
||||
resource_type = "'Project'"
|
||||
elsif params[:status] == "5"
|
||||
resource_type = "'Principal'"
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
resource_type = "'Project','OrgSubfield','Principal','Course'"
|
||||
end
|
||||
@attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
|
||||
end
|
||||
@status = params[:status]
|
||||
@type = params[:type]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class ApplyResource < ActiveRecord::Base
|
||||
# status:1. 等待回复 2.审核通过 3.已拒绝
|
||||
attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content
|
||||
belongs_to :user
|
||||
belongs_to :attachment
|
||||
|
@ -6,7 +7,7 @@ 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.user_id, :course_id => self.container_id, :viewed => false, :status => 5)
|
||||
self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => self.container_id, :viewed => false, :status => 5)
|
||||
# REDO:发送邮件
|
||||
# Mailer.run.apply_for_resource_request(self.container_id, User.current)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<li class="homepageNewsPortrait fl">
|
||||
<div class="navHomepageLogo fl">
|
||||
<%= link_to image_tag(url_to_avatar(ma.course_message.user), :width => "30", :height => "30"), user_path(ma.course_message.user) %>
|
||||
</div>
|
||||
</li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>
|
||||
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">申请引用资源:</span>
|
||||
</li>
|
||||
<li class="<%=(ma.apply_result == 0 || ma.apply_result.nil?) ? 'homepageHomeworkContent2' : 'homepageHomeworkContent' %> fl">
|
||||
<% content = ma.course_message.content.nil? ? '' : ':'+ ma.course_message.content.to_s %>
|
||||
<a title="<%= 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.attachment.try(:name)}"+"\"#{content}" %>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="<%=(ma.apply_result == 0 || ma.apply_result.nil?) ? 'homepageHomeworkContentWarn2' : 'homepageHomeworkContentWarn' %> fl">
|
||||
<span id="deal_info_<%=ma.id%>">
|
||||
<% 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' %>
|
||||
<% elsif ma.apply_result == 1 %>
|
||||
您已经同意了该申请
|
||||
<% elsif ma.apply_result == 2 %>
|
||||
您已经拒绝了该申请
|
||||
<%end %>
|
||||
</span>
|
||||
</li>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
|
@ -15,16 +15,16 @@
|
|||
<img src="/images/locked.png" alt="私有" title="私有" class="resource-list-middle" height="16" width="16">
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="resource-list-apply fr">
|
||||
<li class="resource-list-apply fr" id="resource_apply_status_<%=attach.id %>">
|
||||
<% if attach.is_public == 0 && @type == "6" && attach.author != User.current %>
|
||||
<% ah = attach.get_status_by_attach(attach.author_id) %>
|
||||
<% ah = attach.get_status_by_attach(User.current.id) %>
|
||||
<% if ah.nil? %>
|
||||
<%= link_to("请求分享", apply_resource_user_path(User.current.id, :attachment_id => attach.id), :class => 'green_btn_share c_white', :remote => true) %>
|
||||
<% elsif ah.status == 1 %>
|
||||
<% elsif ah == 1 %>
|
||||
等待回复
|
||||
<% elsif ah.status == 2 %>
|
||||
<% elsif ah == 2 %>
|
||||
可引用
|
||||
<% elsif ah.status == 3 %>
|
||||
<% elsif ah == 3 %>
|
||||
已拒绝
|
||||
<% end %>
|
||||
<% else %>
|
||||
|
|
|
@ -234,6 +234,12 @@
|
|||
<%= render :partial => 'apply_homework_course_message', :locals => {:ma => ma} %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<!--资源申请-->
|
||||
<% if ma.course_message_type == "ApplyResource" %>
|
||||
<ul class="homepageNewsList fl" id="course_message_homework_<%=ma.id %>">
|
||||
<%= render :partial => 'apply_resource_course_message', :locals => {:ma => ma} %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if ma.course_message_type == "HomeworkCommon" && ma.status == 6 %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><div class="navHomepageLogo fl"><%= image_tag(url_to_avatar(User.find(ma.apply_user_id)), width: "30px", height: "30px", class: "mt3") %></div></a></li>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<%#= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5), id="resource_type_user", :remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %>
|
||||
</li>
|
||||
<div id="my_files_resource">
|
||||
<% if @type != "6" %>
|
||||
<% unless (@type == "6" || @type == "2") %>
|
||||
<li>
|
||||
<a href="<%= resource_search_user_path(:id => @user.id, :type => @type, :status => 4, :search => @switch_search) %>" id="resource_type_file" class="resourcesTypeAtt resourcesGrey" data-method="get" data-remote="true">附件 </a>
|
||||
<%#= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4), id="resource_type_file", :remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
|
||||
|
|
|
@ -8,7 +8,7 @@ $('#ajax-modal').siblings().remove();
|
|||
$('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
|
||||
"<a href='javascript:' onclick='hideModal();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
|
||||
$('#ajax-modal').parent().css("top","30%").css("left","50%").css("position","fixed").css("border","3px solid #269ac9");
|
||||
$("#homework_apply_status_<%= @attachment.id %>").html("等待回复");
|
||||
$("#resource_apply_status_<%= @attachment.id %>").html("等待回复");
|
||||
<% elsif @state == 3 %>
|
||||
hideModal();
|
||||
alert("您已申请过该资源");
|
||||
|
|
Loading…
Reference in New Issue