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.

enumerations_controller.rb 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 EnumerationsController < ApplicationController
  18. layout 'admin'
  19. before_filter :require_admin
  20. before_filter :build_new_enumeration, :only => [:new, :create]
  21. before_filter :find_enumeration, :only => [:edit, :update, :destroy]
  22. helper :custom_fields
  23. def index
  24. end
  25. def new
  26. end
  27. def create
  28. if request.post? && @enumeration.save
  29. flash[:notice] = l(:notice_successful_create)
  30. redirect_to :action => 'index', :type => @enumeration.type
  31. else
  32. render :action => 'new'
  33. end
  34. end
  35. def edit
  36. end
  37. def update
  38. if request.put? && @enumeration.update_attributes(params[:enumeration])
  39. flash[:notice] = l(:notice_successful_update)
  40. redirect_to :action => 'index', :type => @enumeration.type
  41. else
  42. render :action => 'edit'
  43. end
  44. end
  45. def destroy
  46. if !@enumeration.in_use?
  47. # No associated objects
  48. @enumeration.destroy
  49. redirect_to :action => 'index'
  50. return
  51. elsif params[:reassign_to_id]
  52. if reassign_to = @enumeration.class.find_by_id(params[:reassign_to_id])
  53. @enumeration.destroy(reassign_to)
  54. redirect_to :action => 'index'
  55. return
  56. end
  57. end
  58. @enumerations = @enumeration.class.all - [@enumeration]
  59. end
  60. private
  61. def build_new_enumeration
  62. class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
  63. @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
  64. if @enumeration.nil?
  65. render_404
  66. end
  67. end
  68. def find_enumeration
  69. @enumeration = Enumeration.find(params[:id])
  70. rescue ActiveRecord::RecordNotFound
  71. render_404
  72. end
  73. end