From f267a3daf8c52e0dc4ad5d74e4ce00e1a04ece67 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 26 Nov 2014 16:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E7=94=A8=E8=AF=BE=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E5=B7=B2=E6=9C=89=E7=9A=84=E8=B5=84=E6=BA=90=E6=97=B6=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=B5=84=E6=BA=90=E5=B7=B2=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 6 ++++++ app/helpers/attachments_helper.rb | 9 +++++++++ app/views/attachments/add_exist_file_to_courses.js.erb | 4 +++- config/locales/zh.yml | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) 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: ",此资源引用失败! " +