您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

attachments_helper.rb 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module AttachmentsHelper
  19. def container_attachments_edit_path(container)
  20. object_attachments_edit_path container.class.name.underscore.pluralize, container.id
  21. end
  22. def container_attachments_path(container)
  23. object_attachments_path container.class.name.underscore.pluralize, container.id
  24. end
  25. # Displays view/delete links to the attachments of the given object
  26. # Options:
  27. # :author -- author names are not displayed if set to false
  28. # :thumbails -- display thumbnails if enabled in settings
  29. def link_to_attachments(container, options = {})
  30. options.assert_valid_keys(:author, :thumbnails)
  31. attachments = if container.attachments.loaded?
  32. container.attachments
  33. else
  34. container.attachments.preload(:author).to_a
  35. end
  36. if attachments.any?
  37. options = {
  38. :editable => container.attachments_editable?,
  39. :deletable => container.attachments_deletable?,
  40. :author => true
  41. }.merge(options)
  42. render :partial => 'attachments/links',
  43. :locals => {
  44. :container => container,
  45. :attachments => attachments,
  46. :options => options,
  47. :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)
  48. }
  49. end
  50. end
  51. def render_pagination
  52. pagination_links_each @paginator do |text, parameters, options|
  53. if att = @attachments[parameters[:page] - 1]
  54. link_to text, named_attachment_path(att, att.filename)
  55. end
  56. end if @paginator
  57. end
  58. def render_api_attachment(attachment, api, options={})
  59. api.attachment do
  60. render_api_attachment_attributes(attachment, api)
  61. options.each { |key, value| eval("api.#{key} value") }
  62. end
  63. end
  64. def render_api_attachment_attributes(attachment, api)
  65. api.id attachment.id
  66. api.filename attachment.filename
  67. api.filesize attachment.filesize
  68. api.content_type attachment.content_type
  69. api.description attachment.description
  70. api.content_url download_named_attachment_url(attachment, attachment.filename)
  71. if attachment.thumbnailable?
  72. api.thumbnail_url thumbnail_url(attachment)
  73. end
  74. if attachment.author
  75. api.author(:id => attachment.author.id, :name => attachment.author.name)
  76. end
  77. api.created_on attachment.created_on
  78. end
  79. end