From bb44430b631eba1d33b218c97cb5d506073aeb08 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 21 Apr 2009 12:19:56 +0000 Subject: Ask user what to do with child pages when deleting a parent wiki page (#3202). 3 options are available: * move child pages as root pages * move child pages to another parent page * delete all descendants git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2676 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wiki_controller.rb | 24 +++++++++++++++++++++++- app/helpers/wiki_helper.rb | 13 +++++++++++++ app/models/wiki_page.rb | 2 +- app/views/wiki/destroy.rhtml | 19 +++++++++++++++++++ app/views/wiki/edit.rhtml | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 app/views/wiki/destroy.rhtml (limited to 'app') diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 1a480e4bd..9c624462a 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -131,9 +131,31 @@ class WikiController < ApplicationController render_404 unless @annotate end - # remove a wiki page and its history + # Removes a wiki page and its history + # Children can be either set as root pages, removed or reassigned to another parent page def destroy return render_403 unless editable? + + @descendants_count = @page.descendants.size + if @descendants_count > 0 + case params[:todo] + when 'nullify' + # Nothing to do + when 'destroy' + # Removes all its descendants + @page.descendants.each(&:destroy) + when 'reassign' + # Reassign children to another parent page + reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i) + return unless reassign_to + @page.children.each do |child| + child.update_attribute(:parent, reassign_to) + end + else + @reassignable_to = @wiki.pages - @page.self_and_descendants + return + end + end @page.destroy redirect_to :action => 'special', :id => @project, :page => 'Page_index' end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index c692c748b..009d6f8cb 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -17,6 +17,19 @@ module WikiHelper + def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) + s = '' + pages.select {|p| p.parent == parent}.each do |page| + attrs = "value='#{page.id}'" + attrs << " selected='selected'" if selected == page + indent = (level > 0) ? (' ' * level * 2 + '» ') : nil + + s << "\n" + + wiki_page_options_for_select(pages, selected, page, level + 1) + end + s + end + def html_diff(wdiff) words = wdiff.words.collect{|word| h(word)} words_add = 0 diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index f8bbcdebd..19858dbd4 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,7 +22,7 @@ class WikiPage < ActiveRecord::Base belongs_to :wiki has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy acts_as_attachable :delete_permission => :delete_wiki_pages_attachments - acts_as_tree :order => 'title' + acts_as_tree :dependent => :nullify, :order => 'title' acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"}, :description => :text, diff --git a/app/views/wiki/destroy.rhtml b/app/views/wiki/destroy.rhtml new file mode 100644 index 000000000..f552c69a5 --- /dev/null +++ b/app/views/wiki/destroy.rhtml @@ -0,0 +1,19 @@ +

<%=h @page.pretty_title %>

+ +<% form_tag({}) do %> +
+

<%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %>

+


+ +<% if @reassignable_to.any? %> +
+: +<%= select_tag 'reassign_to_id', wiki_page_options_for_select(@reassignable_to), + :onclick => "$('todo_reassign').checked = true;" %> +<% end %> +

+
+ +<%= submit_tag l(:button_apply) %> +<%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :id => @project, :page => @page.title %> +<% end %> diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml index 19f3bd5ae..6a949e2aa 100644 --- a/app/views/wiki/edit.rhtml +++ b/app/views/wiki/edit.rhtml @@ -1,4 +1,4 @@ -

<%= @page.pretty_title %>

+

<%=h @page.pretty_title %>

<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> <%= f.hidden_field :version %> -- cgit v1.2.3