2011-08-31 16:20:21 +04:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 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
|
|
|
|
2012-10-17 21:29:27 +04:00
|
|
|
before_filter :require_admin, :except => :index
|
|
|
|
before_filter :require_admin_or_api_request, :only => :index
|
2011-12-11 14:26:12 +04:00
|
|
|
before_filter :build_new_enumeration, :only => [:new, :create]
|
|
|
|
before_filter :find_enumeration, :only => [:edit, :update, :destroy]
|
2012-10-17 21:29:27 +04:00
|
|
|
accept_api_auth :index
|
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
|
2012-10-17 21:29:27 +04: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 22:11:03 +04:00
|
|
|
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)
|
2012-10-17 21:29:27 +04:00
|
|
|
redirect_to :action => 'index'
|
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)
|
2012-10-17 21:29:27 +04:00
|
|
|
redirect_to :action => 'index'
|
2006-06-28 22:11:03 +04:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
2011-08-31 16:20:21 +04:00
|
|
|
|
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
|