diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index ff28a647..589398c0 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AttachmentsController < ApplicationController
- before_filter :find_project, :except => [:upload, :autocomplete]
+ before_filter :find_project, :only => [:show, :download, :thumbnail, :destroy, :delete_homework]#, :except => [:upload, :autocomplete]
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
before_filter :delete_authorize, :only => :destroy
before_filter :authorize_global, :only => :upload
@@ -132,11 +132,40 @@ class AttachmentsController < ApplicationController
end
def autocomplete
+ @project = Project.find_by_id(params[:project_id])
respond_to do |format|
format.js
end
end
+ def add_exist_file_to_project
+ classname = params[:class_name]
+ class_id = params[:class_id]
+ attachments = params[:attachment][:attach]
+
+ obj = Object.const_get(classname).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.container = obj
+ attach_copied_obj.created_on = Time.now
+ @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])
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 8691f547..a3080fbf 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -85,17 +85,82 @@ module AttachmentsHelper
Attachment.tagged_with(tag_name).order('created_on desc')
end
- def render_attachments_for_new_project(project)
+ def render_attachments_for_new_project(project, limit=nil)
# 查询条件
- filename_condition = "trustie" #params[:q]
+ params[:q] ||= ""
+ filename_condition = params[:q]
+
+ attachAll = Attachment.scoped
# 当前项目所有资源
# attachments = Attachment.find_all_by_container_type_and_container_id(project.class, project.id)
- attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
- # 除去当前项目的所有资源
- nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}")
- # 搜索到的资源
- searched_attach = nobelong_attach.where("filename like '%#{filename_condition}%' ")
+ # attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
- return searched_attach.to_yaml
+ # 除去当前项目的所有资源
+ nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}") unless project.blank?
+
+ # 搜索域确定
+ domain = project.nil? ? attachAll : nobelong_attach
+
+ # 搜索到的资源
+ searched_attach = domain.where("filename like '%#{filename_condition}%' ").limit(limit).order('created_on desc')
+ searched_attach = private_filter searched_attach
+ searched_attach = paginateHelper(searched_attach, 10)
+
+ s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
+ links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
+ link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
+
+ return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
+
+ # ================================================================================================
+
+ # attach_count = searched_attach.count
+ # attach_pages = Redmine::Pagination::Paginator.new attach_count, 10, params['page'] #by young
+ # attachs = searched_attach.offset(attach_pages.offset).limit(attach_pages.per_page).all
+
+ # s = content_tag('div', attachments_check_box_tags('attachment[attach][]', attachs), :id => 'attachments')
+ # links = pagination_links_full(attach_pages, attach_count, :per_page_links => false) {|text, parameters, options|
+ # link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
+
+ # return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
+ # return searched_attach.to_json
end
+
+ def attachments_check_box_tags(name, attachs)
+ s = ''
+ attachs.each do |attach|
+ s << "
"
+ end
+ s.html_safe
+ end
+
+ def private_filter resultSet
+ result = resultSet.to_a.dup
+
+ resultSet.map { |res|
+ if(res.container.nil? ||
+ (res.container.class.to_s=="Project" && res.container.is_public == false) ||
+ (res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
+ (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
+ false
+ )
+ result.delete(res)
+ end
+ }
+ result
+ end
+ include Redmine::Pagination
+ def paginateHelper obj, pre_size=10
+ @obj_count = obj.count
+ @obj_pages = Paginator.new @obj_count, pre_size, params['page']
+ if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
+ obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
+ elsif obj.kind_of? Array
+ obj[@obj_pages.offset, @obj_pages.per_page]
+ else
+ logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
+ raise RuntimeError, 'unknow type, Please input you type into this helper.'
+ end
+ end
+
end
diff --git a/app/views/attachments/add_exist_file_to_project.js.erb b/app/views/attachments/add_exist_file_to_project.js.erb
new file mode 100644
index 00000000..58e5690e
--- /dev/null
+++ b/app/views/attachments/add_exist_file_to_project.js.erb
@@ -0,0 +1,17 @@
+<% if @save_flag %>
+ window.location.reload();
+<% else %>
+ // alert('添加文件失败:\n<%=@save_message[0]%>');
+ $('#ajax-modal').html('
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %> | +<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "width: 230px; overflow: hidden; white-space: nowrap;text-overflow: ellipsis;" %> | <%= format_time(file.created_on) %> | <%= number_to_human_size(file.filesize) %> | <%= file.downloads %> | diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index b2cd7705..7eb360d5 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -31,7 +31,7 @@ <% elsif object_flag == '6' %> - <%= image_tag("/images/sidebar/tags.png") %> + <%#= image_tag("/images/sidebar/tags.png") %> <%= link_to (image_tag "/images/sidebar/add.png"), 'javascript:void(0);', :class => "tags_icona", :onclick=>"$('#put-tag-form-#{obj.class}-#{obj.id}').toggle(); readmore(this);" if User.current.logged? %> <%#= toggle_link (image_tag "/images/sidebar/add.png"), "put-tag-form-#{obj.class}-#{obj.id}", {:focus => "put-tag-form-#{obj.class}-#{obj.id} #name"} if User.current.logged? %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 0c179755..5d7f440f 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1150,6 +1150,7 @@ zh: button_export: 导出 label_export_options: "%{export_format} 导出选项" error_attachment_too_big: 该文件无法上传。超过文件大小限制 (%{max_size}) + error_attachment_empty: 文件不能为空 notice_failed_to_save_time_entries: "无法保存下列所选取的 %{total} 个项目中的 %{count} 工时: %{ids}。" label_x_issues: zero: 0 问题 diff --git a/config/routes.rb b/config/routes.rb index 51ac10d8..7633a9c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -386,7 +386,8 @@ RedmineApp::Application.routes.draw do get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/ get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail' get 'attachments/autocomplete' - match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:get, :post] + match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:post] + post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation' resources :attachments, :only => [:show, :destroy] resources :groups do diff --git a/public/themes/redpenny-master/stylesheets/application.css b/public/themes/redpenny-master/stylesheets/application.css index f5507875..c68e36cd 100644 --- a/public/themes/redpenny-master/stylesheets/application.css +++ b/public/themes/redpenny-master/stylesheets/application.css @@ -1898,7 +1898,7 @@ input[type="submit"], .button_submit { font-family: '微软雅黑',Arial,Helvetica,sans-serif; font-size: 12px; color: #fff; - padding: 0px; + padding: 3px 9px; background: #15bccf; border-radius: 4px; border: 1px solid #15bccf;