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 / custom_fields_controller.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (2.42 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  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 CustomFieldsController < ApplicationController
19
  layout 'admin'
20 909:cbb26bc654de Chris
21 0:513646585e45 Chris
  before_filter :require_admin
22 1115:433d4f72a19b Chris
  before_filter :build_new_custom_field, :only => [:new, :create]
23
  before_filter :find_custom_field, :only => [:edit, :update, :destroy]
24 0:513646585e45 Chris
25
  def index
26 1295:622f24f53b42 Chris
    @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
27 0:513646585e45 Chris
    @tab = params[:tab] || 'IssueCustomField'
28
  end
29 909:cbb26bc654de Chris
30 0:513646585e45 Chris
  def new
31 1115:433d4f72a19b Chris
  end
32 909:cbb26bc654de Chris
33 1115:433d4f72a19b Chris
  def create
34 1295:622f24f53b42 Chris
    if @custom_field.save
35 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_create)
36
      call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
37 1295:622f24f53b42 Chris
      redirect_to custom_fields_path(:tab => @custom_field.class.name)
38 441:cbce1fd3b1b7 Chris
    else
39 1115:433d4f72a19b Chris
      render :action => 'new'
40 0:513646585e45 Chris
    end
41
  end
42
43
  def edit
44 1115:433d4f72a19b Chris
  end
45
46
  def update
47 1295:622f24f53b42 Chris
    if @custom_field.update_attributes(params[:custom_field])
48 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_update)
49
      call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
50 1295:622f24f53b42 Chris
      redirect_to custom_fields_path(:tab => @custom_field.class.name)
51 441:cbce1fd3b1b7 Chris
    else
52 1115:433d4f72a19b Chris
      render :action => 'edit'
53 0:513646585e45 Chris
    end
54
  end
55 909:cbb26bc654de Chris
56 0:513646585e45 Chris
  def destroy
57 1295:622f24f53b42 Chris
    begin
58
      @custom_field.destroy
59
    rescue
60
      flash[:error] = l(:error_can_not_delete_custom_field)
61
    end
62
    redirect_to custom_fields_path(:tab => @custom_field.class.name)
63 0:513646585e45 Chris
  end
64 1115:433d4f72a19b Chris
65
  private
66
67
  def build_new_custom_field
68
    @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
69
    if @custom_field.nil?
70
      render_404
71 1295:622f24f53b42 Chris
    else
72
      @custom_field.default_value = nil
73 1115:433d4f72a19b Chris
    end
74
  end
75
76
  def find_custom_field
77
    @custom_field = CustomField.find(params[:id])
78
  rescue ActiveRecord::RecordNotFound
79
    render_404
80
  end
81 0:513646585e45 Chris
end