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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # redMine - project management software
  2. # Copyright (C) 2006 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 'base'
  19. before_filter :require_admin
  20. def index
  21. list
  22. render :action => 'list' unless request.xhr?
  23. end
  24. def list
  25. @custom_field_pages, @custom_fields = paginate :custom_fields, :per_page => 15
  26. render :action => "list", :layout => false if request.xhr?
  27. end
  28. def new
  29. case params[:type]
  30. when "IssueCustomField"
  31. @custom_field = IssueCustomField.new(params[:custom_field])
  32. @custom_field.trackers = Tracker.find(params[:tracker_ids]) if params[:tracker_ids]
  33. when "UserCustomField"
  34. @custom_field = UserCustomField.new(params[:custom_field])
  35. when "ProjectCustomField"
  36. @custom_field = ProjectCustomField.new(params[:custom_field])
  37. else
  38. redirect_to :action => 'list'
  39. return
  40. end
  41. if request.post? and @custom_field.save
  42. flash[:notice] = l(:notice_successful_create)
  43. redirect_to :action => 'list'
  44. end
  45. @trackers = Tracker.find(:all)
  46. end
  47. def edit
  48. @custom_field = CustomField.find(params[:id])
  49. if request.post? and @custom_field.update_attributes(params[:custom_field])
  50. if @custom_field.is_a? IssueCustomField
  51. @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
  52. end
  53. flash[:notice] = l(:notice_successful_update)
  54. redirect_to :action => 'list'
  55. end
  56. @trackers = Tracker.find(:all)
  57. end
  58. def destroy
  59. CustomField.find(params[:id]).destroy
  60. redirect_to :action => 'list'
  61. rescue
  62. flash[:notice] = "Unable to delete custom field"
  63. redirect_to :action => 'list'
  64. end
  65. end