To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / enumerations_controller.rb @ 912:5e80956cc792

History | View | Annotate | Download (2.53 KB)

1 909:cbb26bc654de Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  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 0:513646585e45 Chris
  before_filter :require_admin
22
23
  helper :custom_fields
24
  include CustomFieldsHelper
25 909:cbb26bc654de Chris
26 0:513646585e45 Chris
  def index
27
  end
28
29
  verify :method => :post, :only => [ :destroy, :create, :update ],
30 909:cbb26bc654de Chris
         :redirect_to => { :action => :index }
31 0:513646585e45 Chris
32
  def new
33
    begin
34
      @enumeration = params[:type].constantize.new
35
    rescue NameError
36 909:cbb26bc654de Chris
      @enumeration = Enumeration.new
37 0:513646585e45 Chris
    end
38
  end
39
40
  def create
41
    @enumeration = Enumeration.new(params[:enumeration])
42
    @enumeration.type = params[:enumeration][:type]
43
    if @enumeration.save
44
      flash[:notice] = l(:notice_successful_create)
45 909:cbb26bc654de Chris
      redirect_to :action => 'index', :type => @enumeration.type
46 0:513646585e45 Chris
    else
47
      render :action => 'new'
48
    end
49
  end
50
51
  def edit
52
    @enumeration = Enumeration.find(params[:id])
53
  end
54
55
  def update
56
    @enumeration = Enumeration.find(params[:id])
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 909:cbb26bc654de Chris
      redirect_to :action => 'index', :type => @enumeration.type
61 0:513646585e45 Chris
    else
62
      render :action => 'edit'
63
    end
64
  end
65 909:cbb26bc654de Chris
66 0:513646585e45 Chris
  def destroy
67
    @enumeration = Enumeration.find(params[:id])
68
    if !@enumeration.in_use?
69
      # No associated objects
70
      @enumeration.destroy
71
      redirect_to :action => 'index'
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
        redirect_to :action => 'index'
77 441:cbce1fd3b1b7 Chris
        return
78 0:513646585e45 Chris
      end
79
    end
80
    @enumerations = @enumeration.class.find(:all) - [@enumeration]
81
  #rescue
82
  #  flash[:error] = 'Unable to delete enumeration'
83
  #  redirect_to :action => 'index'
84
  end
85
end