diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index d371ed4cb..664dc4cf5 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -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 += "
" + 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}")
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 0cd7d77c2..68f7cc9cb 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -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
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 9a622316a..ccbf7099a 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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
diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb
index 276786fb7..bd023f6d0 100644
--- a/app/helpers/files_helper.rb
+++ b/app/helpers/files_helper.rb
@@ -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 << "
"
+ end
+ end
+ s.html_safe
+ end
+
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user,file
result = false
diff --git a/app/views/attachments/add_exist_file_to_org_subfield.js.erb b/app/views/attachments/add_exist_file_to_org_subfield.js.erb
new file mode 100644
index 000000000..4c4208f76
--- /dev/null
+++ b/app/views/attachments/add_exist_file_to_org_subfield.js.erb
@@ -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 %>
\ No newline at end of file
diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb
index 750aed9ae..029570047 100644
--- a/app/views/files/_org_subfield_list.html.erb
+++ b/app/views/files/_org_subfield_list.html.erb
@@ -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 %>
diff --git a/app/views/files/_show_quote_resource_org_subfield.html.erb b/app/views/files/_show_quote_resource_org_subfield.html.erb
new file mode 100644
index 000000000..ab2eb318d
--- /dev/null
+++ b/app/views/files/_show_quote_resource_org_subfield.html.erb
@@ -0,0 +1,31 @@
+