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
|
@ -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;" >
|
||||
确 定
|
||||
</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">
|
||||
确 定
|
||||
</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>
|
@ -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 %>
|
@ -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
@ -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…
Reference in new issue