comparison app/controllers/enumerations_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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 class EnumerationsController < ApplicationController 18 class EnumerationsController < ApplicationController
19 layout 'admin' 19 layout 'admin'
20 20
21 before_filter :require_admin 21 before_filter :require_admin, :except => :index
22 before_filter :require_admin_or_api_request, :only => :index
23 before_filter :build_new_enumeration, :only => [:new, :create]
24 before_filter :find_enumeration, :only => [:edit, :update, :destroy]
25 accept_api_auth :index
22 26
23 helper :custom_fields 27 helper :custom_fields
24 include CustomFieldsHelper
25 28
26 def index 29 def index
27 end 30 respond_to do |format|
28 31 format.html
29 verify :method => :post, :only => [ :destroy, :create, :update ], 32 format.api {
30 :redirect_to => { :action => :index } 33 @klass = Enumeration.get_subclass(params[:type])
31 34 if @klass
32 def new 35 @enumerations = @klass.shared.sorted.all
33 begin 36 else
34 @enumeration = params[:type].constantize.new 37 render_404
35 rescue NameError 38 end
36 @enumeration = Enumeration.new 39 }
37 end 40 end
38 end 41 end
39 42
43 def new
44 end
45
40 def create 46 def create
41 @enumeration = Enumeration.new(params[:enumeration]) 47 if request.post? && @enumeration.save
42 @enumeration.type = params[:enumeration][:type]
43 if @enumeration.save
44 flash[:notice] = l(:notice_successful_create) 48 flash[:notice] = l(:notice_successful_create)
45 redirect_to :action => 'index', :type => @enumeration.type 49 redirect_to :action => 'index'
46 else 50 else
47 render :action => 'new' 51 render :action => 'new'
48 end 52 end
49 end 53 end
50 54
51 def edit 55 def edit
52 @enumeration = Enumeration.find(params[:id])
53 end 56 end
54 57
55 def update 58 def update
56 @enumeration = Enumeration.find(params[:id]) 59 if request.put? && @enumeration.update_attributes(params[:enumeration])
57 @enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
58 if @enumeration.update_attributes(params[:enumeration])
59 flash[:notice] = l(:notice_successful_update) 60 flash[:notice] = l(:notice_successful_update)
60 redirect_to :action => 'index', :type => @enumeration.type 61 redirect_to :action => 'index'
61 else 62 else
62 render :action => 'edit' 63 render :action => 'edit'
63 end 64 end
64 end 65 end
65 66
66 def destroy 67 def destroy
67 @enumeration = Enumeration.find(params[:id])
68 if !@enumeration.in_use? 68 if !@enumeration.in_use?
69 # No associated objects 69 # No associated objects
70 @enumeration.destroy 70 @enumeration.destroy
71 redirect_to :action => 'index' 71 redirect_to :action => 'index'
72 return 72 return
75 @enumeration.destroy(reassign_to) 75 @enumeration.destroy(reassign_to)
76 redirect_to :action => 'index' 76 redirect_to :action => 'index'
77 return 77 return
78 end 78 end
79 end 79 end
80 @enumerations = @enumeration.class.find(:all) - [@enumeration] 80 @enumerations = @enumeration.class.all - [@enumeration]
81 #rescue 81 end
82 # flash[:error] = 'Unable to delete enumeration' 82
83 # redirect_to :action => 'index' 83 private
84
85 def build_new_enumeration
86 class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
87 @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
88 if @enumeration.nil?
89 render_404
90 end
91 end
92
93 def find_enumeration
94 @enumeration = Enumeration.find(params[:id])
95 rescue ActiveRecord::RecordNotFound
96 render_404
84 end 97 end
85 end 98 end