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 @ 1534:b31caaed9d4d

History | View | Annotate | Download (2.68 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2014  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].present? && (reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id].to_i))
74
      @enumeration.destroy(reassign_to)
75
      redirect_to enumerations_path
76
      return
77
    end
78
    @enumerations = @enumeration.class.system.all - [@enumeration]
79
  end
80

    
81
  private
82

    
83
  def build_new_enumeration
84
    class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
85
    @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
86
    if @enumeration.nil?
87
      render_404
88
    end
89
  end
90

    
91
  def find_enumeration
92
    @enumeration = Enumeration.find(params[:id])
93
  rescue ActiveRecord::RecordNotFound
94
    render_404
95
  end
96
end