comparison app/controllers/custom_fields_controller.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
17 17
18 class CustomFieldsController < ApplicationController 18 class CustomFieldsController < ApplicationController
19 layout 'admin' 19 layout 'admin'
20 20
21 before_filter :require_admin 21 before_filter :require_admin
22 before_filter :build_new_custom_field, :only => [:new, :create]
23 before_filter :find_custom_field, :only => [:edit, :update, :destroy]
22 24
23 def index 25 def index
24 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } 26 @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
25 @tab = params[:tab] || 'IssueCustomField' 27 @tab = params[:tab] || 'IssueCustomField'
26 end 28 end
27 29
28 def new 30 def new
29 @custom_field = begin 31 end
30 if params[:type].to_s.match(/.+CustomField$/)
31 params[:type].to_s.constantize.new(params[:custom_field])
32 end
33 rescue
34 end
35 (redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
36 32
33 def create
37 if request.post? and @custom_field.save 34 if request.post? and @custom_field.save
38 flash[:notice] = l(:notice_successful_create) 35 flash[:notice] = l(:notice_successful_create)
39 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field) 36 call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
40 redirect_to :action => 'index', :tab => @custom_field.class.name 37 redirect_to :action => 'index', :tab => @custom_field.class.name
41 else 38 else
42 @trackers = Tracker.find(:all, :order => 'position') 39 render :action => 'new'
43 end 40 end
44 end 41 end
45 42
46 def edit 43 def edit
47 @custom_field = CustomField.find(params[:id]) 44 end
48 if request.post? and @custom_field.update_attributes(params[:custom_field]) 45
46 def update
47 if request.put? and @custom_field.update_attributes(params[:custom_field])
49 flash[:notice] = l(:notice_successful_update) 48 flash[:notice] = l(:notice_successful_update)
50 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field) 49 call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
51 redirect_to :action => 'index', :tab => @custom_field.class.name 50 redirect_to :action => 'index', :tab => @custom_field.class.name
52 else 51 else
53 @trackers = Tracker.find(:all, :order => 'position') 52 render :action => 'edit'
54 end 53 end
55 end 54 end
56 55
57 def destroy 56 def destroy
58 @custom_field = CustomField.find(params[:id]).destroy 57 @custom_field.destroy
59 redirect_to :action => 'index', :tab => @custom_field.class.name 58 redirect_to :action => 'index', :tab => @custom_field.class.name
60 rescue 59 rescue
61 flash[:error] = l(:error_can_not_delete_custom_field) 60 flash[:error] = l(:error_can_not_delete_custom_field)
62 redirect_to :action => 'index' 61 redirect_to :action => 'index'
63 end 62 end
63
64 private
65
66 def build_new_custom_field
67 @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
68 if @custom_field.nil?
69 render_404
70 end
71 end
72
73 def find_custom_field
74 @custom_field = CustomField.find(params[:id])
75 rescue ActiveRecord::RecordNotFound
76 render_404
77 end
64 end 78 end