diff app/controllers/.svn/text-base/application_controller.rb.svn-base @ 14:1d32c0a0efbf

* Update to SVN trunk (revisions 3892-4040)
author Chris Cannam
date Wed, 25 Aug 2010 16:30:24 +0100
parents 513646585e45
children 40f7cfd4df19
line wrap: on
line diff
--- a/app/controllers/.svn/text-base/application_controller.rb.svn-base	Wed Jul 28 12:47:17 2010 +0100
+++ b/app/controllers/.svn/text-base/application_controller.rb.svn-base	Wed Aug 25 16:30:24 2010 +0100
@@ -201,7 +201,23 @@
   def self.model_object(model)
     write_inheritable_attribute('model_object', model)
   end
-    
+
+  # Filter for bulk issue operations
+  def find_issues
+    @issues = Issue.find_all_by_id(params[:id] || params[:ids])
+    raise ActiveRecord::RecordNotFound if @issues.empty?
+    projects = @issues.collect(&:project).compact.uniq
+    if projects.size == 1
+      @project = projects.first
+    else
+      # TODO: let users bulk edit/move/destroy issues from different projects
+      render_error 'Can not bulk edit/move/destroy issues from different projects'
+      return false
+    end
+  rescue ActiveRecord::RecordNotFound
+    render_404
+  end
+  
   # make sure that the user is a member of the project (or admin) if project is private
   # used as a before_filter for actions that do not require any particular permission on the project
   def check_project_privacy
@@ -218,6 +234,10 @@
     end
   end
 
+  def back_url
+    params[:back_url] || request.env['HTTP_REFERER']
+  end
+
   def redirect_back_or_default(default)
     back_url = CGI.unescape(params[:back_url].to_s)
     if !back_url.blank?
@@ -238,7 +258,7 @@
   def render_403
     @project = nil
     respond_to do |format|
-      format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 }
+      format.html { render :template => "common/403", :layout => use_layout, :status => 403 }
       format.atom { head 403 }
       format.xml { head 403 }
       format.js { head 403 }
@@ -249,7 +269,7 @@
     
   def render_404
     respond_to do |format|
-      format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 }
+      format.html { render :template => "common/404", :layout => use_layout, :status => 404 }
       format.atom { head 404 }
       format.xml { head 404 }
       format.js { head 404 }
@@ -262,7 +282,7 @@
     respond_to do |format|
       format.html { 
         flash.now[:error] = msg
-        render :text => '', :layout => !request.xhr?, :status => 500
+        render :text => '', :layout => use_layout, :status => 500
       }
       format.atom { head 500 }
       format.xml { head 500 }
@@ -270,6 +290,13 @@
       format.json { head 500 }
     end
   end
+
+  # Picks which layout to use based on the request
+  #
+  # @return [boolean, string] name of the layout to use or false for no layout
+  def use_layout
+    request.xhr? ? false : 'base'
+  end
   
   def invalid_authenticity_token
     if api_request?
@@ -345,6 +372,21 @@
     flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
   end
 
+  # Sets the `flash` notice or error based the number of issues that did not save
+  #
+  # @param [Array, Issue] issues all of the saved and unsaved Issues
+  # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
+  def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
+    if unsaved_issue_ids.empty?
+      flash[:notice] = l(:notice_successful_update) unless issues.empty?
+    else
+      flash[:error] = l(:notice_failed_to_save_issues,
+                        :count => unsaved_issue_ids.size,
+                        :total => issues.size,
+                        :ids => '#' + unsaved_issue_ids.join(', #'))
+    end
+  end
+
   # Rescues an invalid query statement. Just in case...
   def query_statement_invalid(exception)
     logger.error "Query::StatementInvalid: #{exception.message}" if logger