diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-26 11:46:24 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-26 11:46:24 +0000 |
commit | 60d066f943c68a348fee3a8350dc5ba88878b69c (patch) | |
tree | 00d123b7b25e7306688842a7fed0733412118f41 /app/models/wiki_page.rb | |
parent | b68fd4c04bed4d8c9f7d0ad9d65125c36635c819 (diff) | |
download | redmine-60d066f943c68a348fee3a8350dc5ba88878b69c.tar.gz redmine-60d066f943c68a348fee3a8350dc5ba88878b69c.zip |
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1698 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/wiki_page.rb')
-rw-r--r-- | app/models/wiki_page.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 65fc1f68c..2416fab74 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -22,7 +22,8 @@ class WikiPage < ActiveRecord::Base belongs_to :wiki has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy has_many :attachments, :as => :container, :dependent => :destroy - + acts_as_tree :order => 'title' + acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"}, :description => :text, :datetime => :created_on, @@ -110,6 +111,24 @@ class WikiPage < ActiveRecord::Base def editable_by?(usr) !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project) end + + def parent_title + @parent_title || (self.parent && self.parent.pretty_title) + end + + def parent_title=(t) + @parent_title = t + parent_page = t.blank? ? nil : self.wiki.find_page(t) + self.parent = parent_page + end + + protected + + def validate + errors.add(:parent_title, :activerecord_error_invalid) if !@parent_title.blank? && parent.nil? + errors.add(:parent_title, :activerecord_error_circular_dependency) if parent && (parent == self || parent.ancestors.include?(self)) + errors.add(:parent_title, :activerecord_error_not_same_project) if parent && (parent.wiki_id != wiki_id) + end end class WikiDiff |