To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / attachments_helper.rb @ 912:5e80956cc792

History | View | Annotate | Download (1.88 KB)

1 909:cbb26bc654de Chris
# encoding: utf-8
2
#
3 441:cbce1fd3b1b7 Chris
# Redmine - project management software
4
# Copyright (C) 2006-2011  Jean-Philippe Lang
5 0:513646585e45 Chris
#
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 441:cbce1fd3b1b7 Chris
#
11 0:513646585e45 Chris
# 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 441:cbce1fd3b1b7 Chris
#
16 0:513646585e45 Chris
# 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
20
module AttachmentsHelper
21
  # Displays view/delete links to the attachments of the given object
22
  # Options:
23
  #   :author -- author names are not displayed if set to false
24
  def link_to_attachments(container, options = {})
25
    options.assert_valid_keys(:author)
26 441:cbce1fd3b1b7 Chris
27 0:513646585e45 Chris
    if container.attachments.any?
28
      options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
29
      render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
30
    end
31
  end
32 441:cbce1fd3b1b7 Chris
33 909:cbb26bc654de Chris
  def render_api_attachment(attachment, api)
34
    api.attachment do
35
      api.id attachment.id
36
      api.filename attachment.filename
37
      api.filesize attachment.filesize
38
      api.content_type attachment.content_type
39
      api.description attachment.description
40
      api.content_url url_for(:controller => 'attachments', :action => 'download', :id => attachment, :filename => attachment.filename, :only_path => false)
41
      api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
42
      api.created_on attachment.created_on
43 119:8661b858af72 Chris
    end
44 0:513646585e45 Chris
  end
45
end