Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

documents_controller.rb 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # redMine - project management software
  2. # Copyright (C) 2006 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. class DocumentsController < ApplicationController
  18. layout 'base'
  19. before_filter :find_project, :authorize
  20. def show
  21. @attachments = @document.attachments.find(:all, :order => "created_on DESC")
  22. end
  23. def edit
  24. @categories = Enumeration::get_values('DCAT')
  25. if request.post? and @document.update_attributes(params[:document])
  26. flash[:notice] = l(:notice_successful_update)
  27. redirect_to :action => 'show', :id => @document
  28. end
  29. end
  30. def destroy
  31. @document.destroy
  32. redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
  33. end
  34. def download
  35. @attachment = @document.attachments.find(params[:attachment_id])
  36. @attachment.increment_download
  37. send_file @attachment.diskfile, :filename => @attachment.filename
  38. rescue
  39. flash.now[:notice] = l(:notice_file_not_found)
  40. render :text => "", :layout => true, :status => 404
  41. end
  42. def add_attachment
  43. # Save the attachment
  44. if params[:attachment][:file].size > 0
  45. @attachment = @document.attachments.build(params[:attachment])
  46. @attachment.author_id = self.logged_in_user.id if self.logged_in_user
  47. @attachment.save
  48. end
  49. redirect_to :action => 'show', :id => @document
  50. end
  51. def destroy_attachment
  52. @document.attachments.find(params[:attachment_id]).destroy
  53. redirect_to :action => 'show', :id => @document
  54. end
  55. private
  56. def find_project
  57. @document = Document.find(params[:id])
  58. @project = @document.project
  59. end
  60. end