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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 IssueCategoriesController < ApplicationController
  18. menu_item :settings
  19. model_object IssueCategory
  20. before_filter :find_model_object, :except => [:index, :new, :create]
  21. before_filter :find_project_from_association, :except => [:index, :new, :create]
  22. before_filter :find_project_by_project_id, :only => [:index, :new, :create]
  23. before_filter :authorize
  24. accept_api_auth :index, :show, :create, :update, :destroy
  25. def index
  26. respond_to do |format|
  27. format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
  28. format.api { @categories = @project.issue_categories.all }
  29. end
  30. end
  31. def show
  32. respond_to do |format|
  33. format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
  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 do
  43. render :update do |page|
  44. page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal'
  45. page << "showModal('ajax-modal', '600px');"
  46. page << "Form.Element.focus('issue_category_name');"
  47. end
  48. end
  49. end
  50. end
  51. def create
  52. @category = @project.issue_categories.build
  53. @category.safe_attributes = params[:issue_category]
  54. if @category.save
  55. respond_to do |format|
  56. format.html do
  57. flash[:notice] = l(:notice_successful_create)
  58. redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
  59. end
  60. format.js do
  61. render(:update) {|page|
  62. page << 'hideModal();'
  63. # IE doesn't support the replace_html rjs method for select box options
  64. page.replace "issue_category_id",
  65. content_tag('select', content_tag('option') + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
  66. }
  67. end
  68. format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
  69. end
  70. else
  71. respond_to do |format|
  72. format.html { render :action => 'new'}
  73. format.js do
  74. render :update do |page|
  75. page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal'
  76. page << "Form.Element.focus('version_name');"
  77. end
  78. end
  79. format.api { render_validation_errors(@category) }
  80. end
  81. end
  82. end
  83. def edit
  84. end
  85. def update
  86. @category.safe_attributes = params[:issue_category]
  87. if @category.save
  88. respond_to do |format|
  89. format.html {
  90. flash[:notice] = l(:notice_successful_update)
  91. redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
  92. }
  93. format.api { head :ok }
  94. end
  95. else
  96. respond_to do |format|
  97. format.html { render :action => 'edit' }
  98. format.api { render_validation_errors(@category) }
  99. end
  100. end
  101. end
  102. def destroy
  103. @issue_count = @category.issues.size
  104. if @issue_count == 0 || params[:todo] || api_request?
  105. reassign_to = nil
  106. if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
  107. reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
  108. end
  109. @category.destroy(reassign_to)
  110. respond_to do |format|
  111. format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
  112. format.api { head :ok }
  113. end
  114. return
  115. end
  116. @categories = @project.issue_categories - [@category]
  117. end
  118. private
  119. # Wrap ApplicationController's find_model_object method to set
  120. # @category instead of just @issue_category
  121. def find_model_object
  122. super
  123. @category = @object
  124. end
  125. end