diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-15 16:52:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-15 16:52:32 +0000 |
commit | fa969504d4529ca9b2ceadf3c56f09b171c9170e (patch) | |
tree | b0f3feff09ffafd1c5d8339b228eab4e18fedb3f /app | |
parent | 3c6ddc9cecc250b3853025ca8b10a964bed0ff97 (diff) | |
download | redmine-fa969504d4529ca9b2ceadf3c56f09b171c9170e.tar.gz redmine-fa969504d4529ca9b2ceadf3c56f09b171c9170e.zip |
A category with assigned issue can now be deleted. 2 options are proposed:
* remove assignments (issues are set to 'no category')
* reassign issues to another category (if at least an other category exists)
If no issue is assigned to the category, it's deleted silently.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@733 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issue_categories_controller.rb | 18 | ||||
-rw-r--r-- | app/models/issue_category.rb | 16 | ||||
-rw-r--r-- | app/views/issue_categories/destroy.rhtml | 15 | ||||
-rw-r--r-- | app/views/projects/settings/_issue_categories.rhtml | 2 |
4 files changed, 40 insertions, 11 deletions
diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index 29a3f02af..2c1c6657b 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -18,6 +18,8 @@ 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]) @@ -27,11 +29,17 @@ class IssueCategoriesController < ApplicationController 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 diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb index fb2c099a1..1abcf4c32 100644 --- a/app/models/issue_category.rb +++ b/app/models/issue_category.rb @@ -16,15 +16,21 @@ # 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 diff --git a/app/views/issue_categories/destroy.rhtml b/app/views/issue_categories/destroy.rhtml new file mode 100644 index 000000000..a563736e2 --- /dev/null +++ b/app/views/issue_categories/destroy.rhtml @@ -0,0 +1,15 @@ +<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 %> diff --git a/app/views/projects/settings/_issue_categories.rhtml b/app/views/projects/settings/_issue_categories.rhtml index bad330e20..c1e77e9cc 100644 --- a/app/views/projects/settings/_issue_categories.rhtml +++ b/app/views/projects/settings/_issue_categories.rhtml @@ -12,7 +12,7 @@ <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 %> |