@@ -1,64 +1,69 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2015 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 | if container.attachments.any? | |
|
38 | options = {:deletable => container.attachments_deletable?, :author => true}.merge(options) | |
|
37 | attachments = container.attachments.preload(:author).to_a | |
|
38 | if attachments.any? | |
|
39 | options = { | |
|
40 | :editable => container.attachments_editable?, | |
|
41 | :deletable => container.attachments_deletable?, | |
|
42 | :author => true | |
|
43 | }.merge(options) | |
|
39 | 44 | render :partial => 'attachments/links', |
|
40 | 45 | :locals => { |
|
41 | 46 | :container => container, |
|
42 |
:attachments => |
|
|
47 | :attachments => attachments, | |
|
43 | 48 | :options => options, |
|
44 | 49 | :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?) |
|
45 | 50 | } |
|
46 | 51 | end |
|
47 | 52 | end |
|
48 | 53 | |
|
49 | 54 | def render_api_attachment(attachment, api) |
|
50 | 55 | api.attachment do |
|
51 | 56 | api.id attachment.id |
|
52 | 57 | api.filename attachment.filename |
|
53 | 58 | api.filesize attachment.filesize |
|
54 | 59 | api.content_type attachment.content_type |
|
55 | 60 | api.description attachment.description |
|
56 | 61 | api.content_url download_named_attachment_url(attachment, attachment.filename) |
|
57 | 62 | if attachment.thumbnailable? |
|
58 | 63 | api.thumbnail_url thumbnail_url(attachment) |
|
59 | 64 | end |
|
60 | 65 | api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author |
|
61 | 66 | api.created_on attachment.created_on |
|
62 | 67 | end |
|
63 | 68 | end |
|
64 | 69 | end |
@@ -1,38 +1,38 | |||
|
1 | 1 | <div class="attachments"> |
|
2 | 2 | <div class="contextual"> |
|
3 | 3 | <%= link_to image_tag('edit.png'), |
|
4 | 4 | container_attachments_edit_path(container), |
|
5 |
:title => l(:label_edit_attachments) if |
|
|
5 | :title => l(:label_edit_attachments) if options[:editable] %> | |
|
6 | 6 | </div> |
|
7 | 7 | <% for attachment in attachments %> |
|
8 | 8 | <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> |
|
9 | 9 | <% if attachment.is_text? %> |
|
10 | 10 | <%= link_to image_tag('magnifier.png'), |
|
11 | 11 | :controller => 'attachments', :action => 'show', |
|
12 | 12 | :id => attachment, :filename => attachment.filename %> |
|
13 | 13 | <% end %> |
|
14 | 14 | <%= h(" - #{attachment.description}") unless attachment.description.blank? %> |
|
15 | 15 | <span class="size">(<%= number_to_human_size attachment.filesize %>)</span> |
|
16 | 16 | <% if options[:deletable] %> |
|
17 | 17 | <%= link_to image_tag('delete.png'), attachment_path(attachment), |
|
18 | 18 | :data => {:confirm => l(:text_are_you_sure)}, |
|
19 | 19 | :method => :delete, |
|
20 | 20 | :class => 'delete', |
|
21 | 21 | :title => l(:button_delete) %> |
|
22 | 22 | <% end %> |
|
23 | 23 | <% if options[:author] %> |
|
24 | 24 | <span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span> |
|
25 | 25 | <% end %> |
|
26 | 26 | </p> |
|
27 | 27 | <% end %> |
|
28 | 28 | <% if defined?(thumbnails) && thumbnails %> |
|
29 | 29 | <% images = attachments.select(&:thumbnailable?) %> |
|
30 | 30 | <% if images.any? %> |
|
31 | 31 | <div class="thumbnails"> |
|
32 | 32 | <% images.each do |attachment| %> |
|
33 | 33 | <div><%= thumbnail_tag(attachment) %></div> |
|
34 | 34 | <% end %> |
|
35 | 35 | </div> |
|
36 | 36 | <% end %> |
|
37 | 37 | <% end %> |
|
38 | 38 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now