custom_fields_controller.rb
78 lines
| 2.4 KiB
| text/x-ruby
|
RubyLexer
|
r2272 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r330 | # | ||
# 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. | ||||
|
r6781 | # | ||
|
r330 | # 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. | ||||
|
r6781 | # | ||
|
r330 | # 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 CustomFieldsController < ApplicationController | ||||
|
r3062 | layout 'admin' | ||
|
r6781 | |||
|
r330 | before_filter :require_admin | ||
|
r8024 | before_filter :build_new_custom_field, :only => [:new, :create] | ||
before_filter :find_custom_field, :only => [:edit, :update, :destroy] | ||||
|
r10 | |||
|
r2 | def index | ||
|
r612 | @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } | ||
|
r330 | @tab = params[:tab] || 'IssueCustomField' | ||
|
r2 | end | ||
|
r6781 | |||
|
r330 | def new | ||
|
r8024 | end | ||
|
r6781 | |||
|
r8024 | def create | ||
|
r330 | if request.post? and @custom_field.save | ||
flash[:notice] = l(:notice_successful_create) | ||||
|
r2535 | call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) | ||
|
r2272 | redirect_to :action => 'index', :tab => @custom_field.class.name | ||
|
r5491 | else | ||
|
r8024 | render :action => 'new' | ||
|
r330 | end | ||
end | ||||
def edit | ||||
|
r8024 | end | ||
def update | ||||
if request.put? and @custom_field.update_attributes(params[:custom_field]) | ||||
|
r330 | flash[:notice] = l(:notice_successful_update) | ||
|
r2535 | call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) | ||
|
r2272 | redirect_to :action => 'index', :tab => @custom_field.class.name | ||
|
r5491 | else | ||
|
r8024 | render :action => 'edit' | ||
|
r330 | end | ||
end | ||||
|
r6781 | |||
|
r2 | def destroy | ||
|
r8024 | @custom_field.destroy | ||
|
r2272 | redirect_to :action => 'index', :tab => @custom_field.class.name | ||
|
r330 | rescue | ||
|
r3513 | flash[:error] = l(:error_can_not_delete_custom_field) | ||
|
r2272 | redirect_to :action => 'index' | ||
|
r330 | end | ||
|
r8024 | |||
private | ||||
def build_new_custom_field | ||||
@custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) | ||||
if @custom_field.nil? | ||||
render_404 | ||||
end | ||||
end | ||||
def find_custom_field | ||||
@custom_field = CustomField.find(params[:id]) | ||||
rescue ActiveRecord::RecordNotFound | ||||
render_404 | ||||
end | ||||
|
r2 | end | ||