custom_fields_controller.rb 1.97 KB
Newer Older
1
#-- encoding: UTF-8
2 3
#-- copyright
# ChiliProject is a project management system.
4
#
Holger Just's avatar
Holger Just committed
5
# Copyright (C) 2010-2013 the ChiliProject Team
6
#
7 8 9 10
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
11
#
12 13 14
# See doc/COPYRIGHT.rdoc for more details.
#++

15
class CustomFieldsController < ApplicationController
16
  layout 'admin'
17

18
  before_filter :require_admin
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
19

Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
20
  def index
21
    @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
22
    @tab = params[:tab] || 'IssueCustomField'
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
23
  end
24

25
  def new
26 27 28 29 30 31
    @custom_field = begin
      if params[:type].to_s.match(/.+CustomField$/)
        params[:type].to_s.constantize.new(params[:custom_field])
      end
    rescue
    end
32
    (redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
33

34 35
    if request.post? and @custom_field.save
      flash[:notice] = l(:notice_successful_create)
36
      call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
37
      redirect_to :action => 'index', :tab => @custom_field.class.name
38 39
    else
      @trackers = Tracker.find(:all, :order => 'position')
40 41 42 43 44 45 46
    end
  end

  def edit
    @custom_field = CustomField.find(params[:id])
    if request.post? and @custom_field.update_attributes(params[:custom_field])
      flash[:notice] = l(:notice_successful_update)
47
      call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
48
      redirect_to :action => 'index', :tab => @custom_field.class.name
49 50
    else
      @trackers = Tracker.find(:all, :order => 'position')
51 52
    end
  end
53

Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
54
  def destroy
55
    @custom_field = CustomField.find(params[:id]).destroy
56
    redirect_to :action => 'index', :tab => @custom_field.class.name
57
  rescue
58
    flash[:error] = l(:error_can_not_delete_custom_field)
59
    redirect_to :action => 'index'
60
  end
Jean-Philippe Lang's avatar
Jean-Philippe Lang committed
61
end