##// END OF EJS Templates
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
Jean-Philippe Lang -
r2584:bb44430b631e
parent child
Show More
@@ -0,0 +1,19
1 <h2><%=h @page.pretty_title %></h2>
2
3 <% form_tag({}) do %>
4 <div class="box">
5 <p><strong><%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %></strong></p>
6 <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_wiki_page_nullify_children) %></label><br />
7 <label><%= radio_button_tag 'todo', 'destroy', false %> <%= l(:text_wiki_page_destroy_children) %></label>
8 <% if @reassignable_to.any? %>
9 <br />
10 <label><%= radio_button_tag 'todo', 'reassign', false %> <%= l(:text_wiki_page_reassign_children) %></label>:
11 <%= select_tag 'reassign_to_id', wiki_page_options_for_select(@reassignable_to),
12 :onclick => "$('todo_reassign').checked = true;" %>
13 <% end %>
14 </p>
15 </div>
16
17 <%= submit_tag l(:button_apply) %>
18 <%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :id => @project, :page => @page.title %>
19 <% end %>
@@ -131,9 +131,31 class WikiController < ApplicationController
131 render_404 unless @annotate
131 render_404 unless @annotate
132 end
132 end
133
133
134 # remove a wiki page and its history
134 # Removes a wiki page and its history
135 # Children can be either set as root pages, removed or reassigned to another parent page
135 def destroy
136 def destroy
136 return render_403 unless editable?
137 return render_403 unless editable?
138
139 @descendants_count = @page.descendants.size
140 if @descendants_count > 0
141 case params[:todo]
142 when 'nullify'
143 # Nothing to do
144 when 'destroy'
145 # Removes all its descendants
146 @page.descendants.each(&:destroy)
147 when 'reassign'
148 # Reassign children to another parent page
149 reassign_to = @wiki.pages.find_by_id(params[:reassign_to_id].to_i)
150 return unless reassign_to
151 @page.children.each do |child|
152 child.update_attribute(:parent, reassign_to)
153 end
154 else
155 @reassignable_to = @wiki.pages - @page.self_and_descendants
156 return
157 end
158 end
137 @page.destroy
159 @page.destroy
138 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
160 redirect_to :action => 'special', :id => @project, :page => 'Page_index'
139 end
161 end
@@ -17,6 +17,19
17
17
18 module WikiHelper
18 module WikiHelper
19
19
20 def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
21 s = ''
22 pages.select {|p| p.parent == parent}.each do |page|
23 attrs = "value='#{page.id}'"
24 attrs << " selected='selected'" if selected == page
25 indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil
26
27 s << "<option value='#{page.id}'>#{indent}#{h page.pretty_title}</option>\n" +
28 wiki_page_options_for_select(pages, selected, page, level + 1)
29 end
30 s
31 end
32
20 def html_diff(wdiff)
33 def html_diff(wdiff)
21 words = wdiff.words.collect{|word| h(word)}
34 words = wdiff.words.collect{|word| h(word)}
22 words_add = 0
35 words_add = 0
@@ -22,7 +22,7 class WikiPage < ActiveRecord::Base
22 belongs_to :wiki
22 belongs_to :wiki
23 has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
23 has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
24 acts_as_attachable :delete_permission => :delete_wiki_pages_attachments
24 acts_as_attachable :delete_permission => :delete_wiki_pages_attachments
25 acts_as_tree :order => 'title'
25 acts_as_tree :dependent => :nullify, :order => 'title'
26
26
27 acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
27 acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
28 :description => :text,
28 :description => :text,
@@ -1,4 +1,4
1 <h2><%= @page.pretty_title %></h2>
1 <h2><%=h @page.pretty_title %></h2>
2
2
3 <% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %>
3 <% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %>
4 <%= f.hidden_field :version %>
4 <%= f.hidden_field :version %>
@@ -784,3 +784,7 bg:
784 label_date_from_to: From {{start}} to {{end}}
784 label_date_from_to: From {{start}} to {{end}}
785 label_greater_or_equal: ">="
785 label_greater_or_equal: ">="
786 label_less_or_equal: <=
786 label_less_or_equal: <=
787 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
788 text_wiki_page_reassign_children: Reassign child pages to this parent page
789 text_wiki_page_nullify_children: Keep child pages as root pages
790 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -817,3 +817,7 bs:
817 label_descending: Opadajuće
817 label_descending: Opadajuće
818 label_greater_or_equal: ">="
818 label_greater_or_equal: ">="
819 label_less_or_equal: <=
819 label_less_or_equal: <=
820 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
821 text_wiki_page_reassign_children: Reassign child pages to this parent page
822 text_wiki_page_nullify_children: Keep child pages as root pages
823 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -787,3 +787,7 ca:
787 enumeration_activities: Activitats (seguidor de temps)
787 enumeration_activities: Activitats (seguidor de temps)
788 label_greater_or_equal: ">="
788 label_greater_or_equal: ">="
789 label_less_or_equal: <=
789 label_less_or_equal: <=
790 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
791 text_wiki_page_reassign_children: Reassign child pages to this parent page
792 text_wiki_page_nullify_children: Keep child pages as root pages
793 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -790,3 +790,7 cs:
790 label_date_from_to: Od {{start}} do {{end}}
790 label_date_from_to: Od {{start}} do {{end}}
791 label_greater_or_equal: ">="
791 label_greater_or_equal: ">="
792 label_less_or_equal: <=
792 label_less_or_equal: <=
793 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
794 text_wiki_page_reassign_children: Reassign child pages to this parent page
795 text_wiki_page_nullify_children: Keep child pages as root pages
796 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -817,3 +817,7 da:
817 label_date_from_to: From {{start}} to {{end}}
817 label_date_from_to: From {{start}} to {{end}}
818 label_greater_or_equal: ">="
818 label_greater_or_equal: ">="
819 label_less_or_equal: <=
819 label_less_or_equal: <=
820 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
821 text_wiki_page_reassign_children: Reassign child pages to this parent page
822 text_wiki_page_nullify_children: Keep child pages as root pages
823 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -816,3 +816,7 de:
816 label_date_from_to: From {{start}} to {{end}}
816 label_date_from_to: From {{start}} to {{end}}
817 label_greater_or_equal: ">="
817 label_greater_or_equal: ">="
818 label_less_or_equal: <=
818 label_less_or_equal: <=
819 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
820 text_wiki_page_reassign_children: Reassign child pages to this parent page
821 text_wiki_page_nullify_children: Keep child pages as root pages
822 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -761,6 +761,10 en:
761 text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
761 text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
762 text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
762 text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
763 text_custom_field_possible_values_info: 'One line for each value'
763 text_custom_field_possible_values_info: 'One line for each value'
764 text_wiki_page_destroy_question: "This page has {{descendants}} child page(s) and descendant(s). What do you want to do?"
765 text_wiki_page_nullify_children: "Keep child pages as root pages"
766 text_wiki_page_destroy_children: "Delete child pages and all their descendants"
767 text_wiki_page_reassign_children: "Reassign child pages to this parent page"
764
768
765 default_role_manager: Manager
769 default_role_manager: Manager
766 default_role_developper: Developer
770 default_role_developper: Developer
@@ -837,3 +837,7 es:
837 label_date_from_to: From {{start}} to {{end}}
837 label_date_from_to: From {{start}} to {{end}}
838 label_greater_or_equal: ">="
838 label_greater_or_equal: ">="
839 label_less_or_equal: <=
839 label_less_or_equal: <=
840 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
841 text_wiki_page_reassign_children: Reassign child pages to this parent page
842 text_wiki_page_nullify_children: Keep child pages as root pages
843 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -827,3 +827,7 fi:
827 label_date_from_to: From {{start}} to {{end}}
827 label_date_from_to: From {{start}} to {{end}}
828 label_greater_or_equal: ">="
828 label_greater_or_equal: ">="
829 label_less_or_equal: <=
829 label_less_or_equal: <=
830 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
831 text_wiki_page_reassign_children: Reassign child pages to this parent page
832 text_wiki_page_nullify_children: Keep child pages as root pages
833 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -791,6 +791,10 fr:
791 text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés."
791 text_repository_usernames_mapping: "Vous pouvez sélectionner ou modifier l'utilisateur Redmine associé à chaque nom d'utilisateur figurant dans l'historique du dépôt.\nLes utilisateurs avec le même identifiant ou la même adresse mail seront automatiquement associés."
792 text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.'
792 text_diff_truncated: '... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.'
793 text_custom_field_possible_values_info: 'Une ligne par valeur'
793 text_custom_field_possible_values_info: 'Une ligne par valeur'
794 text_wiki_page_destroy_question: "Cette page possède {{descendants}} sous-page(s) et descendante(s). Que voulez-vous faire ?"
795 text_wiki_page_nullify_children: "Conserver les sous-pages en tant que pages racines"
796 text_wiki_page_destroy_children: "Supprimer les sous-pages et toutes leurs descedantes"
797 text_wiki_page_reassign_children: "Réaffecter les sous-pages à cette page"
794
798
795 default_role_manager: Manager
799 default_role_manager: Manager
796 default_role_developper: Développeur
800 default_role_developper: Développeur
@@ -816,3 +816,7 gl:
816 label_date_from_to: From {{start}} to {{end}}
816 label_date_from_to: From {{start}} to {{end}}
817 label_greater_or_equal: ">="
817 label_greater_or_equal: ">="
818 label_less_or_equal: <=
818 label_less_or_equal: <=
819 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
820 text_wiki_page_reassign_children: Reassign child pages to this parent page
821 text_wiki_page_nullify_children: Keep child pages as root pages
822 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -799,3 +799,7 he:
799 label_date_from_to: From {{start}} to {{end}}
799 label_date_from_to: From {{start}} to {{end}}
800 label_greater_or_equal: ">="
800 label_greater_or_equal: ">="
801 label_less_or_equal: <=
801 label_less_or_equal: <=
802 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
803 text_wiki_page_reassign_children: Reassign child pages to this parent page
804 text_wiki_page_nullify_children: Keep child pages as root pages
805 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -822,3 +822,7
822 label_date_from_to: "{{start}} -tól {{end}} -ig"
822 label_date_from_to: "{{start}} -tól {{end}} -ig"
823 label_greater_or_equal: ">="
823 label_greater_or_equal: ">="
824 label_less_or_equal: <=
824 label_less_or_equal: <=
825 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
826 text_wiki_page_reassign_children: Reassign child pages to this parent page
827 text_wiki_page_nullify_children: Keep child pages as root pages
828 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -802,3 +802,7 it:
802 label_date_from_to: From {{start}} to {{end}}
802 label_date_from_to: From {{start}} to {{end}}
803 label_greater_or_equal: ">="
803 label_greater_or_equal: ">="
804 label_less_or_equal: <=
804 label_less_or_equal: <=
805 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
806 text_wiki_page_reassign_children: Reassign child pages to this parent page
807 text_wiki_page_nullify_children: Keep child pages as root pages
808 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -815,3 +815,7 ja:
815 label_date_from_to: From {{start}} to {{end}}
815 label_date_from_to: From {{start}} to {{end}}
816 label_greater_or_equal: ">="
816 label_greater_or_equal: ">="
817 label_less_or_equal: <=
817 label_less_or_equal: <=
818 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
819 text_wiki_page_reassign_children: Reassign child pages to this parent page
820 text_wiki_page_nullify_children: Keep child pages as root pages
821 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -846,3 +846,7 ko:
846 label_date_from_to: From {{start}} to {{end}}
846 label_date_from_to: From {{start}} to {{end}}
847 label_greater_or_equal: ">="
847 label_greater_or_equal: ">="
848 label_less_or_equal: <=
848 label_less_or_equal: <=
849 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
850 text_wiki_page_reassign_children: Reassign child pages to this parent page
851 text_wiki_page_nullify_children: Keep child pages as root pages
852 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -827,3 +827,7 lt:
827 label_date_from_to: From {{start}} to {{end}}
827 label_date_from_to: From {{start}} to {{end}}
828 label_greater_or_equal: ">="
828 label_greater_or_equal: ">="
829 label_less_or_equal: <=
829 label_less_or_equal: <=
830 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
831 text_wiki_page_reassign_children: Reassign child pages to this parent page
832 text_wiki_page_nullify_children: Keep child pages as root pages
833 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -772,3 +772,7 nl:
772 label_date_from_to: Van {{start}} tot {{end}}
772 label_date_from_to: Van {{start}} tot {{end}}
773 label_greater_or_equal: ">="
773 label_greater_or_equal: ">="
774 label_less_or_equal: <=
774 label_less_or_equal: <=
775 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
776 text_wiki_page_reassign_children: Reassign child pages to this parent page
777 text_wiki_page_nullify_children: Keep child pages as root pages
778 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -789,3 +789,7
789 label_date_from_to: From {{start}} to {{end}}
789 label_date_from_to: From {{start}} to {{end}}
790 label_greater_or_equal: ">="
790 label_greater_or_equal: ">="
791 label_less_or_equal: <=
791 label_less_or_equal: <=
792 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
793 text_wiki_page_reassign_children: Reassign child pages to this parent page
794 text_wiki_page_nullify_children: Keep child pages as root pages
795 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -820,3 +820,7 pl:
820 label_date_from_to: Od {{start}} do {{end}}
820 label_date_from_to: Od {{start}} do {{end}}
821 label_greater_or_equal: ">="
821 label_greater_or_equal: ">="
822 label_less_or_equal: <=
822 label_less_or_equal: <=
823 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
824 text_wiki_page_reassign_children: Reassign child pages to this parent page
825 text_wiki_page_nullify_children: Keep child pages as root pages
826 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -822,3 +822,7 pt-BR:
822 label_date_from_to: De {{start}} até {{end}}
822 label_date_from_to: De {{start}} até {{end}}
823 label_greater_or_equal: ">="
823 label_greater_or_equal: ">="
824 label_less_or_equal: <=
824 label_less_or_equal: <=
825 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
826 text_wiki_page_reassign_children: Reassign child pages to this parent page
827 text_wiki_page_nullify_children: Keep child pages as root pages
828 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -808,3 +808,7 pt:
808 label_date_from_to: From {{start}} to {{end}}
808 label_date_from_to: From {{start}} to {{end}}
809 label_greater_or_equal: ">="
809 label_greater_or_equal: ">="
810 label_less_or_equal: <=
810 label_less_or_equal: <=
811 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
812 text_wiki_page_reassign_children: Reassign child pages to this parent page
813 text_wiki_page_nullify_children: Keep child pages as root pages
814 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -787,3 +787,7 ro:
787 enumeration_activities: Activitati (timp de lucru)
787 enumeration_activities: Activitati (timp de lucru)
788 label_greater_or_equal: ">="
788 label_greater_or_equal: ">="
789 label_less_or_equal: <=
789 label_less_or_equal: <=
790 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
791 text_wiki_page_reassign_children: Reassign child pages to this parent page
792 text_wiki_page_nullify_children: Keep child pages as root pages
793 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -914,3 +914,7 ru:
914 text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний
914 text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний
915
915
916 warning_attachments_not_saved: "{{count}} файл(ов) невозможно сохранить."
916 warning_attachments_not_saved: "{{count}} файл(ов) невозможно сохранить."
917 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
918 text_wiki_page_reassign_children: Reassign child pages to this parent page
919 text_wiki_page_nullify_children: Keep child pages as root pages
920 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -788,3 +788,7 sk:
788 label_date_from_to: Od {{start}} do {{end}}
788 label_date_from_to: Od {{start}} do {{end}}
789 label_greater_or_equal: ">="
789 label_greater_or_equal: ">="
790 label_less_or_equal: <=
790 label_less_or_equal: <=
791 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
792 text_wiki_page_reassign_children: Reassign child pages to this parent page
793 text_wiki_page_nullify_children: Keep child pages as root pages
794 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -786,3 +786,7 sl:
786 label_date_from_to: From {{start}} to {{end}}
786 label_date_from_to: From {{start}} to {{end}}
787 label_greater_or_equal: ">="
787 label_greater_or_equal: ">="
788 label_less_or_equal: <=
788 label_less_or_equal: <=
789 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
790 text_wiki_page_reassign_children: Reassign child pages to this parent page
791 text_wiki_page_nullify_children: Keep child pages as root pages
792 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -810,3 +810,7
810 label_date_from_to: From {{start}} to {{end}}
810 label_date_from_to: From {{start}} to {{end}}
811 label_greater_or_equal: ">="
811 label_greater_or_equal: ">="
812 label_less_or_equal: <=
812 label_less_or_equal: <=
813 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
814 text_wiki_page_reassign_children: Reassign child pages to this parent page
815 text_wiki_page_nullify_children: Keep child pages as root pages
816 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -844,3 +844,7 sv:
844 enumeration_issue_priorities: Ärendeprioriteter
844 enumeration_issue_priorities: Ärendeprioriteter
845 enumeration_doc_categories: Dokumentkategorier
845 enumeration_doc_categories: Dokumentkategorier
846 enumeration_activities: Aktiviteter (tidsuppföljning)
846 enumeration_activities: Aktiviteter (tidsuppföljning)
847 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
848 text_wiki_page_reassign_children: Reassign child pages to this parent page
849 text_wiki_page_nullify_children: Keep child pages as root pages
850 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -787,3 +787,7 th:
787 label_date_from_to: From {{start}} to {{end}}
787 label_date_from_to: From {{start}} to {{end}}
788 label_greater_or_equal: ">="
788 label_greater_or_equal: ">="
789 label_less_or_equal: <=
789 label_less_or_equal: <=
790 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
791 text_wiki_page_reassign_children: Reassign child pages to this parent page
792 text_wiki_page_nullify_children: Keep child pages as root pages
793 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -823,3 +823,7 tr:
823 label_date_from_to: From {{start}} to {{end}}
823 label_date_from_to: From {{start}} to {{end}}
824 label_greater_or_equal: ">="
824 label_greater_or_equal: ">="
825 label_less_or_equal: <=
825 label_less_or_equal: <=
826 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
827 text_wiki_page_reassign_children: Reassign child pages to this parent page
828 text_wiki_page_nullify_children: Keep child pages as root pages
829 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -786,3 +786,7 uk:
786 label_date_from_to: From {{start}} to {{end}}
786 label_date_from_to: From {{start}} to {{end}}
787 label_greater_or_equal: ">="
787 label_greater_or_equal: ">="
788 label_less_or_equal: <=
788 label_less_or_equal: <=
789 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
790 text_wiki_page_reassign_children: Reassign child pages to this parent page
791 text_wiki_page_nullify_children: Keep child pages as root pages
792 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -856,3 +856,7 vi:
856 label_date_from_to: From {{start}} to {{end}}
856 label_date_from_to: From {{start}} to {{end}}
857 label_greater_or_equal: ">="
857 label_greater_or_equal: ">="
858 label_less_or_equal: <=
858 label_less_or_equal: <=
859 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
860 text_wiki_page_reassign_children: Reassign child pages to this parent page
861 text_wiki_page_nullify_children: Keep child pages as root pages
862 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -894,3 +894,7
894 enumeration_issue_priorities: 項目優先權
894 enumeration_issue_priorities: 項目優先權
895 enumeration_doc_categories: 文件分類
895 enumeration_doc_categories: 文件分類
896 enumeration_activities: 活動 (時間追蹤)
896 enumeration_activities: 活動 (時間追蹤)
897 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
898 text_wiki_page_reassign_children: Reassign child pages to this parent page
899 text_wiki_page_nullify_children: Keep child pages as root pages
900 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -819,3 +819,7 zh:
819 enumeration_issue_priorities: 问题优先级
819 enumeration_issue_priorities: 问题优先级
820 enumeration_doc_categories: 文档类别
820 enumeration_doc_categories: 文档类别
821 enumeration_activities: 活动(时间跟踪)
821 enumeration_activities: 活动(时间跟踪)
822 text_wiki_page_destroy_question: This page has {{descendants}} child page(s) and descendant(s). What do you want to do?
823 text_wiki_page_reassign_children: Reassign child pages to this parent page
824 text_wiki_page_nullify_children: Keep child pages as root pages
825 text_wiki_page_destroy_children: Delete child pages and all their descendants
@@ -240,12 +240,50 class WikiControllerTest < Test::Unit::TestCase
240 )
240 )
241 end
241 end
242
242
243 def test_destroy
243 def test_destroy_child
244 @request.session[:user_id] = 2
244 @request.session[:user_id] = 2
245 post :destroy, :id => 1, :page => 'CookBook_documentation'
245 post :destroy, :id => 1, :page => 'Child_1'
246 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index'
246 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index'
247 end
247 end
248
248
249 def test_destroy_parent
250 @request.session[:user_id] = 2
251 assert_no_difference('WikiPage.count') do
252 post :destroy, :id => 1, :page => 'Another_page'
253 end
254 assert_response :success
255 assert_template 'destroy'
256 end
257
258 def test_destroy_parent_with_nullify
259 @request.session[:user_id] = 2
260 assert_difference('WikiPage.count', -1) do
261 post :destroy, :id => 1, :page => 'Another_page', :todo => 'nullify'
262 end
263 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index'
264 assert_nil WikiPage.find_by_id(2)
265 end
266
267 def test_destroy_parent_with_cascade
268 @request.session[:user_id] = 2
269 assert_difference('WikiPage.count', -3) do
270 post :destroy, :id => 1, :page => 'Another_page', :todo => 'destroy'
271 end
272 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index'
273 assert_nil WikiPage.find_by_id(2)
274 assert_nil WikiPage.find_by_id(5)
275 end
276
277 def test_destroy_parent_with_reassign
278 @request.session[:user_id] = 2
279 assert_difference('WikiPage.count', -1) do
280 post :destroy, :id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
281 end
282 assert_redirected_to :action => 'special', :id => 'ecookbook', :page => 'Page_index'
283 assert_nil WikiPage.find_by_id(2)
284 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
285 end
286
249 def test_special_routing
287 def test_special_routing
250 assert_routing(
288 assert_routing(
251 {:method => :get, :path => '/projects/567/wiki/page_index'},
289 {:method => :get, :path => '/projects/567/wiki/page_index'},
@@ -100,4 +100,18 class WikiPageTest < Test::Unit::TestCase
100 assert WikiContent.find_all_by_page_id(1).empty?
100 assert WikiContent.find_all_by_page_id(1).empty?
101 assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
101 assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
102 end
102 end
103
104 def test_destroy_should_not_nullify_children
105 page = WikiPage.find(2)
106 child_ids = page.child_ids
107 assert child_ids.any?
108 page.destroy
109 assert_nil WikiPage.find_by_id(2)
110
111 children = WikiPage.find_all_by_id(child_ids)
112 assert_equal child_ids.size, children.size
113 children.each do |child|
114 assert_nil child.parent_id
115 end
116 end
103 end
117 end
@@ -40,11 +40,11 module ActiveRecord
40 # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet.
40 # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet.
41 # * <tt>counter_cache</tt> - keeps a count in a +children_count+ column if set to +true+ (default: +false+).
41 # * <tt>counter_cache</tt> - keeps a count in a +children_count+ column if set to +true+ (default: +false+).
42 def acts_as_tree(options = {})
42 def acts_as_tree(options = {})
43 configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil }
43 configuration = { :foreign_key => "parent_id", :dependent => :destroy, :order => nil, :counter_cache => nil }
44 configuration.update(options) if options.is_a?(Hash)
44 configuration.update(options) if options.is_a?(Hash)
45
45
46 belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
46 belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
47 has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy
47 has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent]
48
48
49 class_eval <<-EOV
49 class_eval <<-EOV
50 include ActiveRecord::Acts::Tree::InstanceMethods
50 include ActiveRecord::Acts::Tree::InstanceMethods
@@ -77,6 +77,13 module ActiveRecord
77 children + children.collect(&:children).flatten
77 children + children.collect(&:children).flatten
78 end
78 end
79
79
80 # Returns list of descendants and a reference to the current node.
81 #
82 # root.self_and_descendants # => [root, child1, subchild1, subchild2]
83 def self_and_descendants
84 [self] + descendants
85 end
86
80 # Returns the root node of the tree.
87 # Returns the root node of the tree.
81 def root
88 def root
82 node = self
89 node = self
General Comments 0
You need to be logged in to leave comments. Login now