annotate .svn/pristine/34/34f59b6c99dab380ca3ed7001d4ae58c9c6a2f50.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 class CustomFieldsController < ApplicationController
Chris@1494 19 layout 'admin'
Chris@1494 20
Chris@1494 21 before_filter :require_admin
Chris@1494 22 before_filter :build_new_custom_field, :only => [:new, :create]
Chris@1494 23 before_filter :find_custom_field, :only => [:edit, :update, :destroy]
Chris@1494 24 accept_api_auth :index
Chris@1494 25
Chris@1494 26 def index
Chris@1494 27 respond_to do |format|
Chris@1494 28 format.html {
Chris@1494 29 @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
Chris@1494 30 @tab = params[:tab] || 'IssueCustomField'
Chris@1494 31 }
Chris@1494 32 format.api {
Chris@1494 33 @custom_fields = CustomField.all
Chris@1494 34 }
Chris@1494 35 end
Chris@1494 36 end
Chris@1494 37
Chris@1494 38 def new
Chris@1494 39 end
Chris@1494 40
Chris@1494 41 def create
Chris@1494 42 if @custom_field.save
Chris@1494 43 flash[:notice] = l(:notice_successful_create)
Chris@1494 44 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
Chris@1494 45 redirect_to custom_fields_path(:tab => @custom_field.class.name)
Chris@1494 46 else
Chris@1494 47 render :action => 'new'
Chris@1494 48 end
Chris@1494 49 end
Chris@1494 50
Chris@1494 51 def edit
Chris@1494 52 end
Chris@1494 53
Chris@1494 54 def update
Chris@1494 55 if @custom_field.update_attributes(params[:custom_field])
Chris@1494 56 flash[:notice] = l(:notice_successful_update)
Chris@1494 57 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
Chris@1494 58 redirect_to custom_fields_path(:tab => @custom_field.class.name)
Chris@1494 59 else
Chris@1494 60 render :action => 'edit'
Chris@1494 61 end
Chris@1494 62 end
Chris@1494 63
Chris@1494 64 def destroy
Chris@1494 65 begin
Chris@1494 66 @custom_field.destroy
Chris@1494 67 rescue
Chris@1494 68 flash[:error] = l(:error_can_not_delete_custom_field)
Chris@1494 69 end
Chris@1494 70 redirect_to custom_fields_path(:tab => @custom_field.class.name)
Chris@1494 71 end
Chris@1494 72
Chris@1494 73 private
Chris@1494 74
Chris@1494 75 def build_new_custom_field
Chris@1494 76 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
Chris@1494 77 if @custom_field.nil?
Chris@1494 78 render_404
Chris@1494 79 else
Chris@1494 80 @custom_field.default_value = nil
Chris@1494 81 end
Chris@1494 82 end
Chris@1494 83
Chris@1494 84 def find_custom_field
Chris@1494 85 @custom_field = CustomField.find(params[:id])
Chris@1494 86 rescue ActiveRecord::RecordNotFound
Chris@1494 87 render_404
Chris@1494 88 end
Chris@1494 89 end