@@ -1,64 +1,69 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module AttachmentsHelper |
|
20 | module AttachmentsHelper | |
21 |
|
21 | |||
22 | def container_attachments_edit_path(container) |
|
22 | def container_attachments_edit_path(container) | |
23 | object_attachments_edit_path container.class.name.underscore.pluralize, container.id |
|
23 | object_attachments_edit_path container.class.name.underscore.pluralize, container.id | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def container_attachments_path(container) |
|
26 | def container_attachments_path(container) | |
27 | object_attachments_path container.class.name.underscore.pluralize, container.id |
|
27 | object_attachments_path container.class.name.underscore.pluralize, container.id | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | # Displays view/delete links to the attachments of the given object |
|
30 | # Displays view/delete links to the attachments of the given object | |
31 | # Options: |
|
31 | # Options: | |
32 | # :author -- author names are not displayed if set to false |
|
32 | # :author -- author names are not displayed if set to false | |
33 | # :thumbails -- display thumbnails if enabled in settings |
|
33 | # :thumbails -- display thumbnails if enabled in settings | |
34 | def link_to_attachments(container, options = {}) |
|
34 | def link_to_attachments(container, options = {}) | |
35 | options.assert_valid_keys(:author, :thumbnails) |
|
35 | options.assert_valid_keys(:author, :thumbnails) | |
36 |
|
36 | |||
37 | if container.attachments.any? |
|
37 | attachments = container.attachments.preload(:author).to_a | |
38 | options = {:deletable => container.attachments_deletable?, :author => true}.merge(options) |
|
38 | if attachments.any? | |
|
39 | options = { | |||
|
40 | :editable => container.attachments_editable?, | |||
|
41 | :deletable => container.attachments_deletable?, | |||
|
42 | :author => true | |||
|
43 | }.merge(options) | |||
39 | render :partial => 'attachments/links', |
|
44 | render :partial => 'attachments/links', | |
40 | :locals => { |
|
45 | :locals => { | |
41 | :container => container, |
|
46 | :container => container, | |
42 |
:attachments => |
|
47 | :attachments => attachments, | |
43 | :options => options, |
|
48 | :options => options, | |
44 | :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?) |
|
49 | :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?) | |
45 | } |
|
50 | } | |
46 | end |
|
51 | end | |
47 | end |
|
52 | end | |
48 |
|
53 | |||
49 | def render_api_attachment(attachment, api) |
|
54 | def render_api_attachment(attachment, api) | |
50 | api.attachment do |
|
55 | api.attachment do | |
51 | api.id attachment.id |
|
56 | api.id attachment.id | |
52 | api.filename attachment.filename |
|
57 | api.filename attachment.filename | |
53 | api.filesize attachment.filesize |
|
58 | api.filesize attachment.filesize | |
54 | api.content_type attachment.content_type |
|
59 | api.content_type attachment.content_type | |
55 | api.description attachment.description |
|
60 | api.description attachment.description | |
56 | api.content_url download_named_attachment_url(attachment, attachment.filename) |
|
61 | api.content_url download_named_attachment_url(attachment, attachment.filename) | |
57 | if attachment.thumbnailable? |
|
62 | if attachment.thumbnailable? | |
58 | api.thumbnail_url thumbnail_url(attachment) |
|
63 | api.thumbnail_url thumbnail_url(attachment) | |
59 | end |
|
64 | end | |
60 | api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author |
|
65 | api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author | |
61 | api.created_on attachment.created_on |
|
66 | api.created_on attachment.created_on | |
62 | end |
|
67 | end | |
63 | end |
|
68 | end | |
64 | end |
|
69 | end |
@@ -1,38 +1,38 | |||||
1 | <div class="attachments"> |
|
1 | <div class="attachments"> | |
2 | <div class="contextual"> |
|
2 | <div class="contextual"> | |
3 | <%= link_to image_tag('edit.png'), |
|
3 | <%= link_to image_tag('edit.png'), | |
4 | container_attachments_edit_path(container), |
|
4 | container_attachments_edit_path(container), | |
5 |
:title => l(:label_edit_attachments) if |
|
5 | :title => l(:label_edit_attachments) if options[:editable] %> | |
6 | </div> |
|
6 | </div> | |
7 | <% for attachment in attachments %> |
|
7 | <% for attachment in attachments %> | |
8 | <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> |
|
8 | <p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%> | |
9 | <% if attachment.is_text? %> |
|
9 | <% if attachment.is_text? %> | |
10 | <%= link_to image_tag('magnifier.png'), |
|
10 | <%= link_to image_tag('magnifier.png'), | |
11 | :controller => 'attachments', :action => 'show', |
|
11 | :controller => 'attachments', :action => 'show', | |
12 | :id => attachment, :filename => attachment.filename %> |
|
12 | :id => attachment, :filename => attachment.filename %> | |
13 | <% end %> |
|
13 | <% end %> | |
14 | <%= h(" - #{attachment.description}") unless attachment.description.blank? %> |
|
14 | <%= h(" - #{attachment.description}") unless attachment.description.blank? %> | |
15 | <span class="size">(<%= number_to_human_size attachment.filesize %>)</span> |
|
15 | <span class="size">(<%= number_to_human_size attachment.filesize %>)</span> | |
16 | <% if options[:deletable] %> |
|
16 | <% if options[:deletable] %> | |
17 | <%= link_to image_tag('delete.png'), attachment_path(attachment), |
|
17 | <%= link_to image_tag('delete.png'), attachment_path(attachment), | |
18 | :data => {:confirm => l(:text_are_you_sure)}, |
|
18 | :data => {:confirm => l(:text_are_you_sure)}, | |
19 | :method => :delete, |
|
19 | :method => :delete, | |
20 | :class => 'delete', |
|
20 | :class => 'delete', | |
21 | :title => l(:button_delete) %> |
|
21 | :title => l(:button_delete) %> | |
22 | <% end %> |
|
22 | <% end %> | |
23 | <% if options[:author] %> |
|
23 | <% if options[:author] %> | |
24 | <span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span> |
|
24 | <span class="author"><%= h(attachment.author) %>, <%= format_time(attachment.created_on) %></span> | |
25 | <% end %> |
|
25 | <% end %> | |
26 | </p> |
|
26 | </p> | |
27 | <% end %> |
|
27 | <% end %> | |
28 | <% if defined?(thumbnails) && thumbnails %> |
|
28 | <% if defined?(thumbnails) && thumbnails %> | |
29 | <% images = attachments.select(&:thumbnailable?) %> |
|
29 | <% images = attachments.select(&:thumbnailable?) %> | |
30 | <% if images.any? %> |
|
30 | <% if images.any? %> | |
31 | <div class="thumbnails"> |
|
31 | <div class="thumbnails"> | |
32 | <% images.each do |attachment| %> |
|
32 | <% images.each do |attachment| %> | |
33 | <div><%= thumbnail_tag(attachment) %></div> |
|
33 | <div><%= thumbnail_tag(attachment) %></div> | |
34 | <% end %> |
|
34 | <% end %> | |
35 | </div> |
|
35 | </div> | |
36 | <% end %> |
|
36 | <% end %> | |
37 | <% end %> |
|
37 | <% end %> | |
38 | </div> |
|
38 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now