Mercurial > hg > soundsoftware-site
diff app/controllers/documents_controller.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | 5f33065ddc4b |
children | 622f24f53b42 |
line wrap: on
line diff
--- a/app/controllers/documents_controller.rb Wed Jun 27 14:54:18 2012 +0100 +++ b/app/controllers/documents_controller.rb Mon Jan 07 12:01:42 2013 +0000 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,9 +18,9 @@ class DocumentsController < ApplicationController default_search_scope :documents model_object Document - before_filter :find_project, :only => [:index, :new] - before_filter :find_model_object, :except => [:index, :new] - before_filter :find_project_from_association, :except => [:index, :new] + before_filter :find_project_by_project_id, :only => [:index, :new, :create] + before_filter :find_model_object, :except => [:index, :new, :create] + before_filter :find_project_from_association, :except => [:index, :new, :create] before_filter :authorize helper :attachments @@ -49,25 +49,36 @@ def new @document = @project.documents.build @document.safe_attributes = params[:document] - if request.post? and @document.save - attachments = Attachment.attach_files(@document, params[:attachments]) + end + + def create + @document = @project.documents.build + @document.safe_attributes = params[:document] + @document.save_attachments(params[:attachments]) + if @document.save render_attachment_warning_if_needed(@document) flash[:notice] = l(:notice_successful_create) redirect_to :action => 'index', :project_id => @project + else + render :action => 'new' end end def edit - @categories = DocumentCategory.active #TODO: use it in the views + end + + def update @document.safe_attributes = params[:document] - if request.post? and @document.save + if request.put? and @document.save flash[:notice] = l(:notice_successful_update) redirect_to :action => 'show', :id => @document + else + render :action => 'edit' end end def destroy - @document.destroy + @document.destroy if request.delete? redirect_to :controller => 'documents', :action => 'index', :project_id => @project end @@ -75,14 +86,9 @@ attachments = Attachment.attach_files(@document, params[:attachments]) render_attachment_warning_if_needed(@document) - Mailer.deliver_attachments_added(attachments[:files]) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') + if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') + Mailer.attachments_added(attachments[:files]).deliver + end redirect_to :action => 'show', :id => @document end - -private - def find_project - @project = Project.find(params[:project_id]) - rescue ActiveRecord::RecordNotFound - render_404 - end end