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 @ 1304:6137548ba453

History | View | Annotate | Download (2.53 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
22

    
23
  helper :custom_fields
24
  include CustomFieldsHelper
25

    
26
  def index
27
  end
28

    
29
  verify :method => :post, :only => [ :destroy, :create, :update ],
30
         :redirect_to => { :action => :index }
31

    
32
  def new
33
    begin
34
      @enumeration = params[:type].constantize.new
35
    rescue NameError
36
      @enumeration = Enumeration.new
37
    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
      redirect_to :action => 'index', :type => @enumeration.type
46
    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
      redirect_to :action => 'index', :type => @enumeration.type
61
    else
62
      render :action => 'edit'
63
    end
64
  end
65

    
66
  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
      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 :action => 'index'
77
        return
78
      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