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

History | View | Annotate | Download (2.62 KB)

1 0:513646585e45 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 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 1464:261b3d9a4903 Chris
  accept_api_auth :index
25 0:513646585e45 Chris
26
  def index
27 1464:261b3d9a4903 Chris
    respond_to do |format|
28
      format.html {
29
        @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
30
      }
31
      format.api {
32
        @custom_fields = CustomField.all
33
      }
34
    end
35 0:513646585e45 Chris
  end
36 909:cbb26bc654de Chris
37 0:513646585e45 Chris
  def new
38 1517:dffacf8a6908 Chris
    @custom_field.field_format = 'string' if @custom_field.field_format.blank?
39
    @custom_field.default_value = nil
40 1115:433d4f72a19b Chris
  end
41 909:cbb26bc654de Chris
42 1115:433d4f72a19b Chris
  def create
43 1464:261b3d9a4903 Chris
    if @custom_field.save
44 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_create)
45
      call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
46 1464:261b3d9a4903 Chris
      redirect_to custom_fields_path(:tab => @custom_field.class.name)
47 441:cbce1fd3b1b7 Chris
    else
48 1115:433d4f72a19b Chris
      render :action => 'new'
49 0:513646585e45 Chris
    end
50
  end
51
52
  def edit
53 1115:433d4f72a19b Chris
  end
54
55
  def update
56 1464:261b3d9a4903 Chris
    if @custom_field.update_attributes(params[:custom_field])
57 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_update)
58
      call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
59 1464:261b3d9a4903 Chris
      redirect_to custom_fields_path(:tab => @custom_field.class.name)
60 441:cbce1fd3b1b7 Chris
    else
61 1115:433d4f72a19b Chris
      render :action => 'edit'
62 0:513646585e45 Chris
    end
63
  end
64 909:cbb26bc654de Chris
65 0:513646585e45 Chris
  def destroy
66 1464:261b3d9a4903 Chris
    begin
67
      @custom_field.destroy
68
    rescue
69
      flash[:error] = l(:error_can_not_delete_custom_field)
70
    end
71
    redirect_to custom_fields_path(:tab => @custom_field.class.name)
72 0:513646585e45 Chris
  end
73 1115:433d4f72a19b Chris
74
  private
75
76
  def build_new_custom_field
77
    @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
78
    if @custom_field.nil?
79 1517:dffacf8a6908 Chris
      render :action => 'select_type'
80 1115:433d4f72a19b Chris
    end
81
  end
82
83
  def find_custom_field
84
    @custom_field = CustomField.find(params[:id])
85
  rescue ActiveRecord::RecordNotFound
86
    render_404
87
  end
88 0:513646585e45 Chris
end