Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: class EnumerationsController < ApplicationController Chris@909: layout 'admin' Chris@909: Chris@909: before_filter :require_admin Chris@909: Chris@909: helper :custom_fields Chris@909: include CustomFieldsHelper Chris@909: Chris@909: def index Chris@909: end Chris@909: Chris@909: verify :method => :post, :only => [ :destroy, :create, :update ], Chris@909: :redirect_to => { :action => :index } Chris@909: Chris@909: def new Chris@909: begin Chris@909: @enumeration = params[:type].constantize.new Chris@909: rescue NameError Chris@909: @enumeration = Enumeration.new Chris@909: end Chris@909: end Chris@909: Chris@909: def create Chris@909: @enumeration = Enumeration.new(params[:enumeration]) Chris@909: @enumeration.type = params[:enumeration][:type] Chris@909: if @enumeration.save Chris@909: flash[:notice] = l(:notice_successful_create) Chris@909: redirect_to :action => 'index', :type => @enumeration.type Chris@909: else Chris@909: render :action => 'new' Chris@909: end Chris@909: end Chris@909: Chris@909: def edit Chris@909: @enumeration = Enumeration.find(params[:id]) Chris@909: end Chris@909: Chris@909: def update Chris@909: @enumeration = Enumeration.find(params[:id]) Chris@909: @enumeration.type = params[:enumeration][:type] if params[:enumeration][:type] Chris@909: if @enumeration.update_attributes(params[:enumeration]) Chris@909: flash[:notice] = l(:notice_successful_update) Chris@909: redirect_to :action => 'index', :type => @enumeration.type Chris@909: else Chris@909: render :action => 'edit' Chris@909: end Chris@909: end Chris@909: Chris@909: def destroy Chris@909: @enumeration = Enumeration.find(params[:id]) Chris@909: if !@enumeration.in_use? Chris@909: # No associated objects Chris@909: @enumeration.destroy Chris@909: redirect_to :action => 'index' Chris@909: return Chris@909: elsif params[:reassign_to_id] Chris@909: if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id]) Chris@909: @enumeration.destroy(reassign_to) Chris@909: redirect_to :action => 'index' Chris@909: return Chris@909: end Chris@909: end Chris@909: @enumerations = @enumeration.class.find(:all) - [@enumeration] Chris@909: #rescue Chris@909: # flash[:error] = 'Unable to delete enumeration' Chris@909: # redirect_to :action => 'index' Chris@909: end Chris@909: end