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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2016 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. def container_attachments_edit_path(container)
  21. object_attachments_edit_path container.class.name.underscore.pluralize, container.id
  22. end
  23. def container_attachments_path(container)
  24. object_attachments_path container.class.name.underscore.pluralize, container.id
  25. end
  26. # Displays view/delete links to the attachments of the given object
  27. # Options:
  28. # :author -- author names are not displayed if set to false
  29. # :thumbails -- display thumbnails if enabled in settings
  30. def link_to_attachments(container, options = {})
  31. options.assert_valid_keys(:author, :thumbnails)
  32. attachments = if container.attachments.loaded?
  33. container.attachments
  34. else
  35. container.attachments.preload(:author).to_a
  36. end
  37. if attachments.any?
  38. options = {
  39. :editable => container.attachments_editable?,
  40. :deletable => container.attachments_deletable?,
  41. :author => true
  42. }.merge(options)
  43. render :partial => 'attachments/links',
  44. :locals => {
  45. :container => container,
  46. :attachments => attachments,
  47. :options => options,
  48. :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)
  49. }
  50. end
  51. end
  52. def render_api_attachment(attachment, api, options={})
  53. api.attachment do
  54. render_api_attachment_attributes(attachment, api)
  55. options.each { |key, value| eval("api.#{key} value") }
  56. end
  57. end
  58. def render_api_attachment_attributes(attachment, api)
  59. api.id attachment.id
  60. api.filename attachment.filename
  61. api.filesize attachment.filesize
  62. api.content_type attachment.content_type
  63. api.description attachment.description
  64. api.content_url download_named_attachment_url(attachment, attachment.filename)
  65. if attachment.thumbnailable?
  66. api.thumbnail_url thumbnail_url(attachment)
  67. end
  68. if attachment.author
  69. api.author(:id => attachment.author.id, :name => attachment.author.name)
  70. end
  71. api.created_on attachment.created_on
  72. end
  73. end