修正课程资源库关联已有资源功能

This commit is contained in:
nwb 2014-07-02 09:11:45 +08:00
parent 138211efba
commit 2b855badf9
4 changed files with 48 additions and 1 deletions

View File

@ -197,6 +197,35 @@ class AttachmentsController < ApplicationController
end
end
def add_exist_file_to_course
class_id = params[:class_id]
attachments = params[:attachment][:attach]
obj = Course.find_by_id(class_id)
attachments.collect do |attach_id|
ori = Attachment.find_by_id(attach_id)
next if ori.blank?
attach_copied_obj = ori.copy
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
format.js
end
end
private
def find_project
@attachment = Attachment.find(params[:id])

View File

@ -0,0 +1,17 @@
<% if @save_flag %>
window.location.reload();
<% else %>
// alert('添加文件失败:\n<%=@save_message[0]%>');
$('#ajax-modal').html('<h3 class="title">添加文件失败</h3><%=@save_message.join(', ')%>');
var el = $('#ajax-modal').first();
var title = el.find('h3.title').text();
el.dialog({
width: '200px',
modal: true,
resizable: false,
dialogClass: 'modal',
title: title
});
<% end %>

View File

@ -40,7 +40,7 @@
<%= text_field_tag(:attach_search) %>
<%#= submit_tag("Search") %>
<% end -%>
<%= form_tag attach_relation_path(:format => 'js'),
<%= form_tag course_attach_relation_path(:format => 'js'),
method: :post,
remote: true,
id: "relation_file_form",

View File

@ -510,6 +510,7 @@ RedmineApp::Application.routes.draw do
get 'attachments/autocomplete'
match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:post]
post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation'
post 'attachments/courserelationfile', to: 'attachments#add_exist_file_to_course', as: 'course_attach_relation'
get 'attachments/renderTag/:attchmentId', :to => 'attachments#renderTag', :attchmentId => /\d+/
resources :attachments, :only => [:show, :destroy] do
collection do