class IssueCategoriesController < ApplicationController
layout 'base'
before_filter :find_project, :authorize
+
+ verify :method => :post, :only => :destroy
def edit
if request.post? and @category.update_attributes(params[:category])
end
def destroy
- @category.destroy
- redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
- rescue
- flash[:error] = "Categorie can't be deleted"
- redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
+ @issue_count = @category.issues.size
+ if @issue_count == 0
+ # No issue assigned to this category
+ @category.destroy
+ redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
+ elsif params[:todo]
+ reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id]) if params[:todo] == 'reassign'
+ @category.destroy(reassign_to)
+ redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories'
+ end
+ @categories = @project.issue_categories - [@category]
end
private
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueCategory < ActiveRecord::Base
- before_destroy :check_integrity
belongs_to :project
belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
-
+ has_many :issues, :foreign_key => 'category_id', :dependent => :nullify
+
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
-private
- def check_integrity
- raise "Can't delete category" if Issue.find(:first, :conditions => ["category_id=?", self.id])
+ alias :destroy_without_reassign :destroy
+
+ # Destroy the category
+ # If a category is specified, issues are reassigned to this category
+ def destroy(reassign_to = nil)
+ if reassign_to && reassign_to.is_a?(IssueCategory) && reassign_to.project == self.project
+ Issue.update_all("category_id = #{reassign_to.id}", "category_id = #{id}")
+ end
+ destroy_without_reassign
end
end
--- /dev/null
+<h2><%=l(:label_issue_category)%>: <%=h @category.name %></h2>
+
+<% form_tag({}) do %>
+<div class="box">
+<p><strong><%= l(:text_issue_category_destroy_question, @issue_count) %></strong></p>
+<p><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_issue_category_destroy_assignments) %><br />
+<% if @categories.size > 0 %>
+<%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_issue_category_reassign_to) %>:
+<%= select_tag 'reassign_to_id', options_from_collection_for_select(@categories, 'id', 'name') %></p>
+<% end %>
+</div>
+
+<%= submit_tag l(:button_apply) %>
+<%= link_to l(:button_cancel), :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' %>
+<% end %>
<td><%=h(category.name) %></td>
<td><%=h(category.assigned_to.name) if category.assigned_to %></td>
<td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'issue_categories', :action => 'edit', :id => category }, :class => 'icon icon-edit' %></small></td>
- <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td>
+ <td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => category}, :method => :post, :class => 'icon icon-del' %></small></td>
</tr>
<% end %>
<% end %>
text_issue_added: Публикувана е нова задача с номер %s.
text_issue_updated: Задача %s е обновена.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Мениджър
default_role_developper: Разработчик
text_issue_added: Ticket %s wurde erstellt.
text_issue_updated: Ticket %s wurde aktualisiert.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Manager
default_role_developper: Developer
text_issue_added: Issue %s has been reported.
text_issue_updated: Issue %s has been updated.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Manager
default_role_developper: Developer
text_issue_added: Issue %s has been reported.
text_issue_updated: Issue %s has been updated.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Manager
default_role_developper: Desarrollador
text_issue_added: La demande %s a été soumise.
text_issue_updated: La demande %s a été mise à jour.
text_wiki_destroy_confirmation: Etes-vous sûr de vouloir supprimer ce wiki et tout son contenu ?
+text_issue_category_destroy_question: Des demandes (%d) sont affectées à cette catégories. Que voulez-vous faire ?
+text_issue_category_destroy_assignments: N'affecter les demandes à aucune autre catégorie
+text_issue_category_reassign_to: Réaffecter les demandes à cette catégorie
default_role_manager: Manager
default_role_developper: Développeur
text_issue_added: "E' stata segnalata l'anomalia %s."
text_issue_updated: "L'anomalia %s e' stata aggiornata."
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Manager
default_role_developper: Sviluppatore
text_issue_added: 問題 %s が報告されました。
text_issue_updated: 問題 %s が更新されました。
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: 管理者
default_role_developper: 開発者
text_issue_added: Issue %s is gerapporteerd.
text_issue_updated: Issue %s is gewijzigd.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Manager
default_role_developper: Ontwikkelaar
text_issue_added: Tarefa %s foi incluída.\r
text_issue_updated: Tarefa %s foi alterada.\r
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?\r
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?\r
+text_issue_category_destroy_assignments: Remove category assignments\r
+text_issue_category_reassign_to: Reassing issues to this category\r
\r
default_role_manager: Analista de Negocio ou Gerente de Projeto\r
default_role_developper: Desenvolvedor\r
text_issue_added: Tarefa %s foi incluída.
text_issue_updated: Tarefa %s foi alterada.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Analista de Negócio ou Gerente de Projeto
default_role_developper: Desenvolvedor
text_issue_added: Brist %s har rapporterats.
text_issue_updated: Brist %s har uppdaterats.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: Förvaltare
default_role_developper: Utvecklare
text_issue_added: %s ѱ
text_issue_updated: %s Ѹ
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
+text_issue_category_destroy_question: Some issues (%d) are assigned to this category. What do you want to do ?
+text_issue_category_destroy_assignments: Remove category assignments
+text_issue_category_reassign_to: Reassing issues to this category
default_role_manager: 管理员
default_role_developper: 开发人员
--- /dev/null
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IssueCategoryTest < Test::Unit::TestCase
+ fixtures :issue_categories, :issues
+
+ def setup
+ @category = IssueCategory.find(1)
+ end
+
+ def test_destroy
+ issue = @category.issues.first
+ @category.destroy
+ # Make sure the category was nullified on the issue
+ assert_nil issue.reload.category
+ end
+
+ def test_destroy_with_reassign
+ issue = @category.issues.first
+ reassign_to = IssueCategory.find(2)
+ @category.destroy(reassign_to)
+ # Make sure the issue was reassigned
+ assert_equal reassign_to, issue.reload.category
+ end
+end