资源引用 结构搭建 数据创建

hjq_mail
huang 9 years ago
parent 615d0ddbd2
commit 658ea0cf1e

@ -0,0 +1,14 @@
class ApplyResource < ActiveRecord::Base
attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content
belongs_to :user
belongs_to :attachment
has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy
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)
# REDO:发送邮件
# Mailer.run.apply_for_resource_request(self.container_id, User.current)
end
end

@ -35,6 +35,7 @@ class Attachment < ActiveRecord::Base
# end
include UserScoreHelper
has_many :attachment_histories
has_many :apply_resources, :dependent => :destroy
validates :filename, presence: true, length: {maximum: 254}
validates :author, presence: true
@ -536,6 +537,11 @@ class Attachment < ActiveRecord::Base
end
end
# 获取资源申请状态
def get_status_by_attach user_id
ApplyResource.where("user_id =? and attachment_id =?", user_id, self.id).first.try(:status)
end
private
# Physically deletes the file from the file system

@ -109,6 +109,7 @@ class User < Principal
has_many :student_works_scores, :dependent => :destroy
has_many :student_work_projects, :dependent => :destroy
has_many :apply_homeworks, :dependent => :destroy
has_many :apply_resources, :dependent => :destroy
#end
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},

@ -0,0 +1,16 @@
<div>
<div class="ni_con">
<p class="mt30">
<% if state == 2 %>
请求已发送至<%= attachment.author.show_name %>,希望他同意与你分享:)
<% elsif state == 3 %>
您已发送过分享请求,请勿重复发送。
<% end %>
</p>
<div class="ni_btn">
<a href="javascript:" class="tijiao" onclick="hideModal();" style="margin-bottom: 10px; margin-left: 60px; color: #fff;" >
确&nbsp;&nbsp;定
</a>
</div>
</div>
</div>

@ -0,0 +1,28 @@
<div>
<div class="ni_con">
<%= form_tag(apply_for_resource_user_path(:id => User.current.id, :attachment_id => attachment.id), :multipart => true, :remote => true, :name=>"apply_for_homework_form", :id=>'apply_for_homework_form') do %>
<h2>申请分享</h2>
<p style="color: #000;">
申请说明(必选):
<textarea type="text" name="content" id="apply_content" placeholder="请附言,以增加分享的成功机率。" class="apply_content mt10" style="outline:none;"></textarea>
</p>
<span class="c_red ml5 f12" style="display: none" id="apply_content_notice">为增加分享的成功机率,请务必填写申请说明。</span>
<div class="ni_btn">
<a href="javascript:" class="tijiao" onclick="submit_apply_resource();" style="margin-bottom: 20px; margin-left: 60px; color: #fff">
确&nbsp;&nbsp;定
</a>
</div>
<% end %>
</div>
</div>
<script type="application/javascript">
var first_click_apply = true;
function submit_apply_resource(){
if($.trim($("#apply_content").val()) == ""){
$("#apply_content_notice").show();
} else if(first_click_apply) {
first_click_apply = false;
$('#apply_for_homework_form').submit();
}
}
</script>

@ -11,13 +11,22 @@
</li>
<li class="resource-list-name fl">
<%= link_to truncate(attach.filename, :length => 30), download_named_attachment_path(attach.id, attach.filename), :title => attach.filename, :class => 'resourcesBlack resource-list-middle hidden mw280' %>
<% if attach.is_public == 0 && @type == "6" %>
<% if attach.is_public == 0 && @type == "6" && attach.author != User.current %>
<img src="/images/locked.png" alt="私有" title="私有" class="resource-list-middle" height="16" width="16">
<% end %>
</li>
<li class="resource-list-apply fr">
<% if attach.is_public == 0 && @type == "6" %>
<a href="javascript:void(0);" class="green_btn_share c_white" data-remote="true">请求分享</a>
<% if attach.is_public == 0 && @type == "6" && attach.author != User.current %>
<% ah = attach.get_status_by_attach(attach.author_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.status == 2 %>
可引用
<% elsif ah.status == 3 %>
已拒绝
<% end %>
<% else %>
--
<% end %>

@ -0,0 +1,15 @@
<% if @state == 1 %>
hideModal();
alert("您还未登录,请先登录");
<% elsif @state == 2 %>
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/apply_for_resource', :locals => {:attachment => @attachment, :state => @state}) %>');
showModal('ajax-modal', '500px');
$('#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("等待回复");
<% elsif @state == 3 %>
hideModal();
alert("您已申请过该资源");
<% end %>

@ -0,0 +1,10 @@
<% if @state == 1 %>
alert("您还未登录");
<% elsif @state == 2 %>
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/apply_resource', :locals => {:attachment => @attachment}) %>');
showModal('ajax-modal', '500px');
$('#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","30%").css("position","fixed").css("border","3px solid #269ac9");
<% end %>

@ -56,7 +56,7 @@
<a href="<%= user_resource_user_path(@user, :type => '1', :status => 6) %>" class="resource-tab" id="my_resource_list" data-remote="true">我的资源</a>
</li>
<li class="fl resource-switch">
<a href="javascript:void(0);" class="resource-tab" id="private_resource_list" data-remote="true">私有资源</a>
<a href="<%= user_resource_user_path(@user, :type => '1', :status => 6) %>" class="resource-tab" id="private_resource_list" data-remote="true">私有资源</a>
</li>
<li class="fl w680 border-bottom h34">&nbsp;</li>
<li class="fr resource-banner-li border-bottom h34">

@ -561,6 +561,7 @@ RedmineApp::Application.routes.draw do
match 'apply_homework', :to => 'users#apply_homework', :via => :get
match 'user_homeworks', :to => 'users#user_homeworks', :via => :get
match 'student_homeworks', :to => 'users#student_homeworks', :via => :get
get 'apply_resource'
get 'user_import_homeworks'
get 'user_search_homeworks'
get 'choose_user_course'
@ -630,6 +631,7 @@ RedmineApp::Application.routes.draw do
get 'user_ref_homework_search'
get 'show_homework_detail'
post 'apply_for_homework'
post 'apply_for_resource'
# end
end
#resources :blogs

@ -0,0 +1,11 @@
class CreateApplyResources < ActiveRecord::Migration
def change
create_table :apply_resources do |t|
t.integer :status
t.integer :user_id
t.integer :attachment_id
t.timestamps
end
end
end

@ -0,0 +1,6 @@
class AddColumnToApplyResource < ActiveRecord::Migration
def change
add_column :apply_resources, :container_id, :integer
add_column :apply_resources, :container_type, :string
end
end

@ -0,0 +1,6 @@
class AddColumnContentToApplyResource < ActiveRecord::Migration
def change
add_column :apply_resources, :content, :text
add_column :apply_resources, :apply_user_id, :integer
end
end

File diff suppressed because it is too large Load Diff

@ -1134,3 +1134,6 @@ a.st_down{ display: block; width:8px; float:left; height:13px; background:url(..
.likeText{color: #7f7f7f}
.likeNum{color: #7f7f7f}
/*弹框*/
.apply_content{ border:1px solid #ddd;line-height: 16px; height:80px;width:420px; background:#fff; margin-bottom:10px;}

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :apply_resource do
status 1
user_id 1
attachment_id 1
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ApplyResource, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save