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.

issue_categories_controller.rb 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 IssueCategoriesController < ApplicationController
  18. menu_item :settings
  19. model_object IssueCategory
  20. before_action :find_model_object, :except => [:index, :new, :create]
  21. before_action :find_project_from_association, :except => [:index, :new, :create]
  22. before_action :find_project_by_project_id, :only => [:index, :new, :create]
  23. before_action :authorize
  24. accept_api_auth :index, :show, :create, :update, :destroy
  25. def index
  26. respond_to do |format|
  27. format.html { redirect_to_settings_in_projects }
  28. format.api { @categories = @project.issue_categories.to_a }
  29. end
  30. end
  31. def show
  32. respond_to do |format|
  33. format.html { redirect_to_settings_in_projects }
  34. format.api
  35. end
  36. end
  37. def new
  38. @category = @project.issue_categories.build
  39. @category.safe_attributes = params[:issue_category]
  40. respond_to do |format|
  41. format.html
  42. format.js
  43. end
  44. end
  45. def create
  46. @category = @project.issue_categories.build
  47. @category.safe_attributes = params[:issue_category]
  48. if @category.save
  49. respond_to do |format|
  50. format.html do
  51. flash[:notice] = l(:notice_successful_create)
  52. redirect_to_settings_in_projects
  53. end
  54. format.js
  55. format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
  56. end
  57. else
  58. respond_to do |format|
  59. format.html { render :action => 'new'}
  60. format.js { render :action => 'new'}
  61. format.api { render_validation_errors(@category) }
  62. end
  63. end
  64. end
  65. def edit
  66. end
  67. def update
  68. @category.safe_attributes = params[:issue_category]
  69. if @category.save
  70. respond_to do |format|
  71. format.html {
  72. flash[:notice] = l(:notice_successful_update)
  73. redirect_to_settings_in_projects
  74. }
  75. format.api { render_api_ok }
  76. end
  77. else
  78. respond_to do |format|
  79. format.html { render :action => 'edit' }
  80. format.api { render_validation_errors(@category) }
  81. end
  82. end
  83. end
  84. def destroy
  85. @issue_count = @category.issues.size
  86. if @issue_count == 0 || params[:todo] || api_request?
  87. reassign_to = nil
  88. if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
  89. reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
  90. end
  91. @category.destroy(reassign_to)
  92. respond_to do |format|
  93. format.html { redirect_to_settings_in_projects }
  94. format.api { render_api_ok }
  95. end
  96. return
  97. end
  98. @categories = @project.issue_categories - [@category]
  99. end
  100. private
  101. def redirect_to_settings_in_projects
  102. redirect_to settings_project_path(@project, :tab => 'categories')
  103. end
  104. # Wrap ApplicationController's find_model_object method to set
  105. # @category instead of just @issue_category
  106. def find_model_object
  107. super
  108. @category = @object
  109. end
  110. end