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 / controllers / files_controller.rb @ 1270:b2f7f52a164d

History | View | Annotate | Download (2.07 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
class FilesController < ApplicationController
19
  menu_item :files
20

    
21
  before_filter :find_project_by_project_id
22
  before_filter :authorize
23

    
24
  helper :sort
25
  include SortHelper
26

    
27
  def index
28
    sort_init 'active', 'desc'
29
    sort_update 'filename' => "#{Attachment.table_name}.filename",
30
                'active' => "#{Attachment.table_name}.active",
31
                'created_on' => "#{Attachment.table_name}.created_on",
32
                'size' => "#{Attachment.table_name}.filesize",
33
                'downloads' => "#{Attachment.table_name}.downloads"
34

    
35
    @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
36
    @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
37
    render :layout => !request.xhr?
38
  end
39

    
40
  def new
41
    @versions = @project.versions.sort
42
  end
43

    
44
  def create
45
    container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
46
    attachments = Attachment.attach_files(container, params[:attachments])
47
    render_attachment_warning_if_needed(container)
48

    
49
    if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
50
      Mailer.attachments_added(attachments[:files]).deliver
51
    end
52
    redirect_to project_files_path(@project)
53
  end
54

    
55
end