This commit is contained in:
z9hang 2014-07-02 11:33:00 +08:00
commit fe3861c1d7
7 changed files with 62 additions and 10 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

@ -256,14 +256,14 @@ class TagsController < ApplicationController
# 获取有某类对象的tag总数
def get_tags_size
@issues_tags_num = Issue.tag_counts.size
@projects_tags_num = Project.tag_counts.size
@users_tags_num = User.tag_counts.size
@bids_tags_num = Bid.tag_counts.size
forum_tags_num = Forum.tag_counts.size
attachment_tags_num = Attachment.tag_counts.size
@open_source_projects_num = OpenSourceProject.tag_counts.size
@contests_tags_num = Contest.tag_counts.size
@issues_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Issue").count
@projects_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Project").count
@users_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"User").count
@bids_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Bid").count
forum_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Forum").count
attachment_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Attachment").count
@open_source_projects_num = ActsAsTaggableOn::Tagging.where(taggable_type:"OpenSourceProject").count
@contests_tags_num = ActsAsTaggableOn::Tagging.where(taggable_type:"Contest").count
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num, forum_tags_num, attachment_tags_num, @contests_tags_num, @open_source_projects_num
end

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

@ -29,7 +29,7 @@
</div>
</div>
</div>
<div class="debug">
<div class="debug hidden">
<%= debug(params) if Rails.env.development? %>
<script src="http://s4.cnzz.com/z_stat.php?id=1000482288&web_id=1000482288" language="JavaScript"></script>

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

View File

@ -0,0 +1,5 @@
class AddTagTypeIndexToTagging < ActiveRecord::Migration
def change
add_index :taggings, :taggable_type
end
end