You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom_fields_controller.rb 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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. class CustomFieldsController < ApplicationController
  18. layout 'admin'
  19. before_filter :require_admin
  20. before_filter :build_new_custom_field, :only => [:new, :create]
  21. before_filter :find_custom_field, :only => [:edit, :update, :destroy]
  22. def index
  23. @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
  24. @tab = params[:tab] || 'IssueCustomField'
  25. end
  26. def new
  27. end
  28. def create
  29. if request.post? and @custom_field.save
  30. flash[:notice] = l(:notice_successful_create)
  31. call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
  32. redirect_to :action => 'index', :tab => @custom_field.class.name
  33. else
  34. render :action => 'new'
  35. end
  36. end
  37. def edit
  38. end
  39. def update
  40. if request.put? and @custom_field.update_attributes(params[:custom_field])
  41. flash[:notice] = l(:notice_successful_update)
  42. call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
  43. redirect_to :action => 'index', :tab => @custom_field.class.name
  44. else
  45. render :action => 'edit'
  46. end
  47. end
  48. def destroy
  49. @custom_field.destroy
  50. redirect_to :action => 'index', :tab => @custom_field.class.name
  51. rescue
  52. flash[:error] = l(:error_can_not_delete_custom_field)
  53. redirect_to :action => 'index'
  54. end
  55. private
  56. def build_new_custom_field
  57. @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
  58. if @custom_field.nil?
  59. render_404
  60. end
  61. end
  62. def find_custom_field
  63. @custom_field = CustomField.find(params[:id])
  64. rescue ActiveRecord::RecordNotFound
  65. render_404
  66. end
  67. end