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 @ 1361:7c0909052511

History | View | Annotate | Download (2.69 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2012  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 :action => 'index'
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 :action => 'index'
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 :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.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