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