组织资源栏目的文件可以被引用至当前组织下的资源栏目

This commit is contained in:
ouyangxuhua 2015-12-17 14:51:02 +08:00
parent acb604883d
commit de229c0f1c
10 changed files with 118 additions and 1 deletions

View File

@ -438,6 +438,46 @@ class AttachmentsController < ApplicationController
end
end
def add_exist_file_to_org_subfield
file = Attachment.find(params[:file_id])
org_subfields = params[:org_subfields][:org_subfield]
@message = ""
org_subfields.each do |org_subfield|
s = OrgSubfield.find(org_subfield)
if s.attachments.include?file
if @message && @message == ""
@message += l(:label_resource_subfield_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
else
@message += "<br/>" + l(:label_resource_subfield_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
next
end
end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = s
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id : file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = s
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
update_quotes attach_copied_obj
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:label_resource_subfield_empty_select)
respond_to do |format|
format.js
end
end
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")

View File

@ -412,6 +412,12 @@ class FilesController < ApplicationController
@can_quote = attachment_candown @file
end
def quote_resource_show_org_subfield
@file = Attachment.find(params[:id])
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@can_quote = attachment_candown @file
end
def new
@versions = @project.versions.sort
@course_tag = @project.project_type

View File

@ -1924,6 +1924,8 @@ module ApplicationHelper
elsif attachment.container.is_a?(Course)
course = attachment.container
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
elsif attachment.container.is_a?(OrgSubfield)
candown = true
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
attachment.container.board.course
course = attachment.container.board.course

View File

@ -67,6 +67,17 @@ module FilesHelper
s.html_safe
end
#带勾选框的组织资源栏目列表
def org_subfields_check_box_tags(name,org_subfields,attachment)
s = ''
org_subfields.each do |org_subfield|
if !org_subfield.attachments.include?attachment
s << "<label>#{ check_box_tag name, org_subfield.id, false, :id => nil } #{h org_subfield.name}</label><br/>"
end
end
s.html_safe
end
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user,file
result = false

View File

@ -0,0 +1,8 @@
<% if !@save_flag && @save_message %>
$("#error_show").html("<%= @save_message.join(', ') %>");
<% elsif @message && @message != "" %>
$("#error_show").html("<%= @message.html_safe %>");
<% else %>
closeModal();
location.reload();
<% end %>

View File

@ -28,6 +28,11 @@
download_named_attachment_path(file.id, file.filename),
:title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
<% if User.current.logged? %>
<% if !@org_subfield.attachments.all.include?file %>
<%= link_to("选入栏目",quote_resource_show_org_subfield_org_subfield_file_path(:org_subfield_id => @org_subfield.id, :id => file.id),:class => "f_l re_select c_lorange",:remote => true) %>
<% else %>
<%= link_to("选入组织其他栏目",quote_resource_show_org_subfield_org_subfield_file_path(:org_subfield_id => @org_subfield.id, :id => file.id),:class => "f_l re_select c_lorange",:remote => true) %>
<% end %>
<%= file_preview_tag(file, class: 'f_l re_open', style:'text-align: center;') %>
<% end %>
</div>

View File

@ -0,0 +1,31 @@
<div id="popbox_upload" style="margin-top: -30px;margin-left: -20px;margin-right: -10px;">
<div class="upload_con">
<h2>将此资源引入组织资源栏目</h2>
<% if error == '403' %>
<div class="upload_box">
<div style="color: red;">您没有权限引用此资源</div>
</div>
<% else %>
<div class="upload_box">
<div id="error_show" style="color: red;"></div>
<%= form_tag attachments_add_exist_file_to_org_subfield_path,
method: :post,
remote: true,
id: "relation_file_form" do %>
<%= hidden_field_tag(:file_id, file.id) %>
<%= content_tag('div', org_subfields_check_box_tags('org_subfields[org_subfield][]',org_subfield.organization.org_subfields.where("field_type='Resource'"),file), :id => 'org_subfields')%>
<a id="submit_quote" href="javascript:void(0)" class="blue_btn fl c_white" onclick="submit_quote();">引&nbsp;&nbsp;用</a><a href="javascript:void(0)" class="blue_btn grey_btn fl c_white" onclick="closeModal();">取&nbsp;&nbsp;消</a>
<% end -%>
</div>
<% end %>
</div>
</div>
<script>
function submit_quote()
{
$('#submit_quote').parent().submit();
}
</script>

View File

@ -0,0 +1,11 @@
<% if @can_quote %>
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_org_subfield',:locals => {:org_subfield => @org_subfield,:file => @file,:error => ''}) %>');
<% else %>
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource_org_subfield',:locals => {:org_subfield => @org_subfield,:file => @file,:error => '403'}) %>');
<% end %>
showModal('ajax-modal', '513px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 480px;'><img src='/images/bid/close.png' width='26px' height='26px' /></a>");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("popbox_polls");

View File

@ -1969,9 +1969,11 @@ zh:
label_my_score: 我的评分
field_open_anonymous_evaluation: 是否使用匿评
label_course_empty_select: 尚未选择课程!
label_resource_subfield_empty_select: 尚未选择资源栏目!
label_project_empty_select: 尚未选择项目!
label_course_prompt: 课程:
label_project_prompt: 项目:
label_resource_subfield_prompt: 资源栏目:
label_contain_resource: 已包含资源:
label_quote_resource_failed: ",此资源引用失败! "
label_file_lost: 以下无法成功下载,请联系相关人员重新上传:

View File

@ -81,7 +81,7 @@ RedmineApp::Application.routes.draw do
match "subfield_upload_file", :via => :post
end
member do
match "quote_resource_show", :via => [:get]
match "quote_resource_show_org_subfield", :via => [:get]
end
end
end
@ -807,6 +807,7 @@ RedmineApp::Application.routes.draw do
post 'attachments/relationfiles', to: 'attachments#add_exist_file_to_projects', as: 'attach_relations'
post 'attachments/courserelationfile', to: 'attachments#add_exist_file_to_course', as: 'course_attach_relation'
post 'attachments/courserelationfiles', to: 'attachments#add_exist_file_to_courses', as: 'course_attach_relations'
match 'attachments/add_exist_file_to_org_subfield'
get 'attachments/renderTag/:attchmentId', :to => 'attachments#renderTag', :attchmentId => /\d+/
resources :attachments, :only => [:show, :destroy] do
collection do