You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

attachments_helper.rb 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2012 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. module AttachmentsHelper
  20. # Displays view/delete links to the attachments of the given object
  21. # Options:
  22. # :author -- author names are not displayed if set to false
  23. def link_to_attachments(container, options = {})
  24. options.assert_valid_keys(:author)
  25. if container.attachments.any?
  26. options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
  27. render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
  28. end
  29. end
  30. def render_api_attachment(attachment, api)
  31. api.attachment do
  32. api.id attachment.id
  33. api.filename attachment.filename
  34. api.filesize attachment.filesize
  35. api.content_type attachment.content_type
  36. api.description attachment.description
  37. api.content_url url_for(:controller => 'attachments', :action => 'download', :id => attachment, :filename => attachment.filename, :only_path => false)
  38. api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
  39. api.created_on attachment.created_on
  40. end
  41. end
  42. end