2011-08-31 16:20:21 +04:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
2007-03-12 20:59:02 +03: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 16:20:21 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03: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 16:20:21 +04:00
|
|
|
#
|
2007-03-12 20:59:02 +03: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 21:21:02 +03:00
|
|
|
layout 'admin'
|
2011-08-31 16:20:21 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
before_filter :require_admin
|
2011-12-11 14:26:12 +04:00
|
|
|
before_filter :build_new_enumeration, :only => [:new, :create]
|
|
|
|
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
|
2009-10-22 02:34:22 +04:00
|
|
|
|
|
|
|
helper :custom_fields
|
2011-08-31 16:20:21 +04:00
|
|
|
|
2006-06-28 22:11:03 +04:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-12-11 14:26:12 +04:00
|
|
|
if request.post? && @enumeration.save
|
2006-07-29 23:54:22 +04:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2011-11-29 00:23:57 +04:00
|
|
|
redirect_to :action => 'index', :type => @enumeration.type
|
2006-06-28 22:11:03 +04:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-12-11 14:26:12 +04:00
|
|
|
if request.put? && @enumeration.update_attributes(params[:enumeration])
|
2006-07-29 23:54:22 +04:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2011-11-29 00:23:57 +04:00
|
|
|
redirect_to :action => 'index', :type => @enumeration.type
|
2006-06-28 22:11:03 +04:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:20:21 +04:00
|
|
|
|
2011-12-11 14:26:12 +04:00
|
|
|
verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
|
2006-06-28 22:11:03 +04:00
|
|
|
def destroy
|
2008-06-17 23:10:54 +04:00
|
|
|
if !@enumeration.in_use?
|
|
|
|
# No associated objects
|
|
|
|
@enumeration.destroy
|
|
|
|
redirect_to :action => 'index'
|
2011-05-02 03:15:03 +04:00
|
|
|
return
|
2008-06-17 23:10:54 +04:00
|
|
|
elsif params[:reassign_to_id]
|
2010-03-02 23:03:09 +03:00
|
|
|
if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
|
2008-06-17 23:10:54 +04:00
|
|
|
@enumeration.destroy(reassign_to)
|
|
|
|
redirect_to :action => 'index'
|
2011-05-02 03:15:03 +04:00
|
|
|
return
|
2008-06-17 23:10:54 +04:00
|
|
|
end
|
|
|
|
end
|
2011-12-11 14:26:12 +04:00
|
|
|
@enumerations = @enumeration.class.all - [@enumeration]
|
|
|
|
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 22:11:03 +04:00
|
|
|
end
|
|
|
|
end
|