| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2013-01-12 09:29:31 +00:00
										 |  |  | # Copyright (C) 2006-2013  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # 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. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # 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. | 
					
						
							| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # 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 EnumerationsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2009-12-17 18:21:02 +00:00
										 |  |  |   layout 'admin' | 
					
						
							| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-17 17:29:27 +00:00
										 |  |  |   before_filter :require_admin, :except => :index | 
					
						
							|  |  |  |   before_filter :require_admin_or_api_request, :only => :index | 
					
						
							| 
									
										
										
										
											2011-12-11 10:26:12 +00:00
										 |  |  |   before_filter :build_new_enumeration, :only => [:new, :create] | 
					
						
							|  |  |  |   before_filter :find_enumeration, :only => [:edit, :update, :destroy] | 
					
						
							| 
									
										
										
										
											2012-10-17 17:29:27 +00:00
										 |  |  |   accept_api_auth :index | 
					
						
							| 
									
										
										
										
											2009-10-21 22:34:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   helper :custom_fields | 
					
						
							| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2012-10-17 17:29:27 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html | 
					
						
							|  |  |  |       format.api { | 
					
						
							|  |  |  |         @klass = Enumeration.get_subclass(params[:type]) | 
					
						
							|  |  |  |         if @klass | 
					
						
							|  |  |  |           @enumerations = @klass.shared.sorted.all | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           render_404 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							| 
									
										
										
										
											2011-12-11 10:26:12 +00:00
										 |  |  |     if request.post? && @enumeration.save | 
					
						
							| 
									
										
										
										
											2006-07-29 19:54:22 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_create) | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       redirect_to enumerations_path | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'new' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def edit | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def update | 
					
						
							| 
									
										
										
										
											2011-12-11 10:26:12 +00:00
										 |  |  |     if request.put? && @enumeration.update_attributes(params[:enumeration]) | 
					
						
							| 
									
										
										
										
											2006-07-29 19:54:22 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       redirect_to enumerations_path | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'edit' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-31 12:20:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def destroy | 
					
						
							| 
									
										
										
										
											2008-06-17 19:10:54 +00:00
										 |  |  |     if !@enumeration.in_use? | 
					
						
							|  |  |  |       # No associated objects | 
					
						
							|  |  |  |       @enumeration.destroy | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |       redirect_to enumerations_path | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |       return | 
					
						
							| 
									
										
										
										
											2008-06-17 19:10:54 +00:00
										 |  |  |     elsif params[:reassign_to_id] | 
					
						
							| 
									
										
										
										
											2010-03-02 20:03:09 +00:00
										 |  |  |       if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id]) | 
					
						
							| 
									
										
										
										
											2008-06-17 19:10:54 +00:00
										 |  |  |         @enumeration.destroy(reassign_to) | 
					
						
							| 
									
										
										
										
											2012-12-11 17:51:30 +00:00
										 |  |  |         redirect_to enumerations_path | 
					
						
							| 
									
										
										
										
											2011-05-01 23:15:03 +00:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2008-06-17 19:10:54 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-01 16:43:51 +00:00
										 |  |  |     @enumerations = @enumeration.class.system.all - [@enumeration] | 
					
						
							| 
									
										
										
										
											2011-12-11 10:26:12 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def build_new_enumeration | 
					
						
							|  |  |  |     class_name = params[:enumeration] && params[:enumeration][:type] || params[:type] | 
					
						
							|  |  |  |     @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration]) | 
					
						
							|  |  |  |     if @enumeration.nil? | 
					
						
							|  |  |  |       render_404 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def find_enumeration | 
					
						
							|  |  |  |     @enumeration = Enumeration.find(params[:id]) | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |