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_field_enumerations_controller.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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 CustomFieldEnumerationsController < ApplicationController
  18. layout 'admin'
  19. self.main_menu = false
  20. before_action :require_admin
  21. before_action :find_custom_field
  22. before_action :find_enumeration, :only => :destroy
  23. helper :custom_fields
  24. def index
  25. @values = @custom_field.enumerations.order(:position)
  26. end
  27. def create
  28. @value = @custom_field.enumerations.build
  29. @value.safe_attributes = params[:custom_field_enumeration]
  30. @value.save
  31. respond_to do |format|
  32. format.html { redirect_to custom_field_enumerations_path(@custom_field) }
  33. format.js
  34. end
  35. end
  36. def update_each
  37. saved = CustomFieldEnumeration.update_each(@custom_field, params[:custom_field_enumerations]) do |enumeration, enumeration_attributes|
  38. enumeration.safe_attributes = enumeration_attributes
  39. end
  40. if saved
  41. flash[:notice] = l(:notice_successful_update)
  42. end
  43. redirect_to :action => 'index'
  44. end
  45. def destroy
  46. reassign_to = @custom_field.enumerations.find_by_id(params[:reassign_to_id])
  47. if reassign_to.nil? && @value.in_use?
  48. @enumerations = @custom_field.enumerations - [@value]
  49. render :action => 'destroy'
  50. return
  51. end
  52. @value.destroy(reassign_to)
  53. redirect_to custom_field_enumerations_path(@custom_field)
  54. end
  55. private
  56. def find_custom_field
  57. @custom_field = CustomField.find(params[:custom_field_id])
  58. rescue ActiveRecord::RecordNotFound
  59. render_404
  60. end
  61. def find_enumeration
  62. @value = @custom_field.enumerations.find(params[:id])
  63. rescue ActiveRecord::RecordNotFound
  64. render_404
  65. end
  66. end