To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / enumerations_controller.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (2.69 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | |
| 21 | 1115:433d4f72a19b | Chris | 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 | 0:513646585e45 | Chris | |
| 27 | helper :custom_fields
|
||
| 28 | 909:cbb26bc654de | Chris | |
| 29 | 0:513646585e45 | Chris | def index |
| 30 | 1115:433d4f72a19b | Chris | 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 | 0:513646585e45 | Chris | end
|
| 41 | end
|
||
| 42 | |||
| 43 | 1115:433d4f72a19b | Chris | def new |
| 44 | end
|
||
| 45 | |||
| 46 | 0:513646585e45 | Chris | def create |
| 47 | 1115:433d4f72a19b | Chris | if request.post? && @enumeration.save |
| 48 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_create) |
| 49 | 1295:622f24f53b42 | Chris | redirect_to enumerations_path |
| 50 | 0:513646585e45 | Chris | else
|
| 51 | render :action => 'new' |
||
| 52 | end
|
||
| 53 | end
|
||
| 54 | |||
| 55 | def edit |
||
| 56 | end
|
||
| 57 | |||
| 58 | def update |
||
| 59 | 1115:433d4f72a19b | Chris | if request.put? && @enumeration.update_attributes(params[:enumeration]) |
| 60 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_update) |
| 61 | 1295:622f24f53b42 | Chris | redirect_to enumerations_path |
| 62 | 0:513646585e45 | Chris | else
|
| 63 | render :action => 'edit' |
||
| 64 | end
|
||
| 65 | end
|
||
| 66 | 909:cbb26bc654de | Chris | |
| 67 | 0:513646585e45 | Chris | def destroy |
| 68 | if !@enumeration.in_use? |
||
| 69 | # No associated objects
|
||
| 70 | @enumeration.destroy
|
||
| 71 | 1295:622f24f53b42 | Chris | redirect_to enumerations_path |
| 72 | 441:cbce1fd3b1b7 | Chris | return
|
| 73 | 0:513646585e45 | Chris | elsif params[:reassign_to_id] |
| 74 | if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id]) |
||
| 75 | @enumeration.destroy(reassign_to)
|
||
| 76 | 1295:622f24f53b42 | Chris | redirect_to enumerations_path |
| 77 | 441:cbce1fd3b1b7 | Chris | return
|
| 78 | 0:513646585e45 | Chris | end
|
| 79 | end
|
||
| 80 | 1295:622f24f53b42 | Chris | @enumerations = @enumeration.class.system.all - [@enumeration] |
| 81 | 1115:433d4f72a19b | Chris | 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 | 0:513646585e45 | Chris | end
|
| 98 | end |