diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 31463d691..89a96a836 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,6 +25,7 @@ class AttachmentsController < ApplicationController #before_filter :login_without_softapplication, only: [:download] accept_api_auth :show, :download, :upload require 'iconv' + include AttachmentsHelper def show @@ -346,8 +347,13 @@ class AttachmentsController < ApplicationController def add_exist_file_to_courses file = Attachment.find(params[:file_id]) courses = params[:courses][:course] + @message = "" courses.each do |course| c = Course.find(course); + if course_contains_attachment?(c,file) + @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed) + next + end attach_copied_obj = file.copy attach_copied_obj.tag_list.add(file.tag_list) # tag关联 attach_copied_obj.container = c diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3c882d393..f631f56ff 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -67,6 +67,15 @@ module AttachmentsHelper end end + def course_contains_attachment? course,attachment + course.attachments.each do |att| + if att.id == attachment.id || att.copy_from == attachment.copy_from || att.copy_from = attachment.id || att.id == attachment.copy_from + return true + end + end + false + end + private def deletable? container, user=User.current diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb index 23761647f..761111cec 100644 --- a/app/views/attachments/add_exist_file_to_courses.js.erb +++ b/app/views/attachments/add_exist_file_to_courses.js.erb @@ -1,5 +1,7 @@ -<% if !@save_flag%> +<% if !@save_flag && @save_message %> $("#error_show").html("<%= @save_message.join(', ') %>"); +<% elsif @message || @message != "" %> + $("#error_show").html("<%= @message %>"); <% else %> closeModal(); <% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7d6cc85b2..0ec623217 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2205,3 +2205,7 @@ zh: label_my_score: 我的评分 field_open_anonymous_evaluation: 是否使用匿评 label_course_empty_select: 尚未选择课程! + label_course_prompt: 课程: + label_contain_resource: 已包含资源: + label_quote_resource_failed: ",此资源引用失败! " +