Mercurial > hg > soundsoftware-site
comparison .svn/pristine/18/18f24048551fce41db8feba1bc192158d946b808.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 class EnumerationsController < ApplicationController | |
19 layout 'admin' | |
20 | |
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 | |
26 | |
27 helper :custom_fields | |
28 | |
29 def index | |
30 respond_to do |format| | |
31 format.html | |
32 format.api { | |
33 @klass = Enumeration.get_subclass(params[:type]) | |
34 if @klass | |
35 @enumerations = @klass.shared.sorted.all | |
36 else | |
37 render_404 | |
38 end | |
39 } | |
40 end | |
41 end | |
42 | |
43 def new | |
44 end | |
45 | |
46 def create | |
47 if request.post? && @enumeration.save | |
48 flash[:notice] = l(:notice_successful_create) | |
49 redirect_to enumerations_path | |
50 else | |
51 render :action => 'new' | |
52 end | |
53 end | |
54 | |
55 def edit | |
56 end | |
57 | |
58 def update | |
59 if request.put? && @enumeration.update_attributes(params[:enumeration]) | |
60 flash[:notice] = l(:notice_successful_update) | |
61 redirect_to enumerations_path | |
62 else | |
63 render :action => 'edit' | |
64 end | |
65 end | |
66 | |
67 def destroy | |
68 if !@enumeration.in_use? | |
69 # No associated objects | |
70 @enumeration.destroy | |
71 redirect_to enumerations_path | |
72 return | |
73 elsif params[:reassign_to_id] | |
74 if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id]) | |
75 @enumeration.destroy(reassign_to) | |
76 redirect_to enumerations_path | |
77 return | |
78 end | |
79 end | |
80 @enumerations = @enumeration.class.system.all - [@enumeration] | |
81 end | |
82 | |
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 | |
97 end | |
98 end |