diff app/controllers/trackers_controller.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 513646585e45
children 433d4f72a19b
line wrap: on
line diff
--- a/app/controllers/trackers_controller.rb	Fri Feb 24 18:36:29 2012 +0000
+++ b/app/controllers/trackers_controller.rb	Fri Feb 24 19:09:32 2012 +0000
@@ -1,33 +1,46 @@
 # Redmine - project management software
-# Copyright (C) 2006-2009  Jean-Philippe Lang
+# Copyright (C) 2006-2011  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
 # as published by the Free Software Foundation; either version 2
 # of the License, or (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class TrackersController < ApplicationController
   layout 'admin'
-  
-  before_filter :require_admin
 
-  verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
+  before_filter :require_admin, :except => :index
+  before_filter :require_admin_or_api_request, :only => :index
+  accept_api_auth :index
 
   def index
-    @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
-    render :action => "index", :layout => false if request.xhr?
+    respond_to do |format|
+      format.html {
+        @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
+        render :action => "index", :layout => false if request.xhr?
+      }
+      format.api {
+        @trackers = Tracker.all
+      }
+    end
   end
 
   def new
+    @tracker ||= Tracker.new(params[:tracker])
+    @trackers = Tracker.find :all, :order => 'position'
+    @projects = Project.find(:all)
+  end
+
+  def create
     @tracker = Tracker.new(params[:tracker])
     if request.post? and @tracker.save
       # workflow copy
@@ -38,20 +51,27 @@
       redirect_to :action => 'index'
       return
     end
-    @trackers = Tracker.find :all, :order => 'position'
-    @projects = Project.find(:all)
+    new
+    render :action => 'new'
   end
 
   def edit
+    @tracker ||= Tracker.find(params[:id])
+    @projects = Project.find(:all)
+  end
+  
+  def update
     @tracker = Tracker.find(params[:id])
-    if request.post? and @tracker.update_attributes(params[:tracker])
+    if request.put? and @tracker.update_attributes(params[:tracker])
       flash[:notice] = l(:notice_successful_update)
       redirect_to :action => 'index'
       return
     end
-    @projects = Project.find(:all)
+    edit
+    render :action => 'edit'
   end
-  
+
+  verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
   def destroy
     @tracker = Tracker.find(params[:id])
     unless @tracker.issues.empty?
@@ -60,5 +80,5 @@
       @tracker.destroy
     end
     redirect_to :action => 'index'
-  end  
+  end
 end