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 @ 1535:e2c122809c5c

History | View | Annotate | Download (2.68 KB)

1 909:cbb26bc654de Chris
# Redmine - project management software
2 1494:e248c7af89ec Chris
# Copyright (C) 2006-2014  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 1464:261b3d9a4903 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 1464:261b3d9a4903 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 1464:261b3d9a4903 Chris
      redirect_to enumerations_path
72 441:cbce1fd3b1b7 Chris
      return
73 1464:261b3d9a4903 Chris
    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 0:513646585e45 Chris
    end
78 1464:261b3d9a4903 Chris
    @enumerations = @enumeration.class.system.all - [@enumeration]
79 1115:433d4f72a19b Chris
  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 0:513646585e45 Chris
  end
96
end