summaryrefslogtreecommitdiff
path: root/app/models/node.rb
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-22 17:14:08 +0100
committerhukl <contact@smyck.org>2009-03-22 17:14:08 +0100
commit06ec666fa8fad0aafe7d8e505f6e92b729fccbce (patch)
tree8ae948c50ffd9ebcf264f1b02dcea150c6eb96e1 /app/models/node.rb
parentc2f581ac675a869c2f0600c738332c0674a3606c (diff)
Finally! The cloning of pages for creating new drafts is now a lot cleaner. I had to search for a while to figure out a better way. Thank you svenfuchs and joshmh for the support!
Diffstat (limited to 'app/models/node.rb')
-rw-r--r--app/models/node.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 0f34b73..04d98b5 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -11,7 +11,8 @@ class Node < ActiveRecord::Base
11 belongs_to :user, :foreign_key => :locking_user_id 11 belongs_to :user, :foreign_key => :locking_user_id
12 12
13 # Callbacks 13 # Callbacks
14 after_create :initialize_empty_page 14 after_create :initialize_empty_page
15 before_save :check_for_changed_slug
15 16
16 # Validations 17 # Validations
17 # validates_length_of :slug, :within => 3..40 18 # validates_length_of :slug, :within => 3..40
@@ -59,7 +60,7 @@ class Node < ActiveRecord::Base
59 end 60 end
60 61
61 def create_new_draft user 62 def create_new_draft user
62 empty_page = self.pages.new 63 empty_page = self.pages.create
63 empty_page.user = user 64 empty_page.user = user
64 empty_page.clone_attributes_from self.head 65 empty_page.clone_attributes_from self.head
65 66
@@ -96,17 +97,17 @@ class Node < ActiveRecord::Base
96 self.save 97 self.save
97 end 98 end
98 99
100 def unlock!
101 self.user = nil
102 self.save
103 end
104
99 protected 105 protected
100 def lock_for! current_user 106 def lock_for! current_user
101 self.user = current_user 107 self.user = current_user
102 self.save 108 self.save
103 end 109 end
104 110
105 def unlock!
106 self.user = nil
107 self.save
108 end
109
110 # Creates an empty page and associates it to the given node. This means 111 # Creates an empty page and associates it to the given node. This means
111 # freshly created node has an empty draft. A user can create nodes as he 112 # freshly created node has an empty draft. A user can create nodes as he
112 # wants to which will not appear on the public page until the author edits 113 # wants to which will not appear on the public page until the author edits
@@ -117,6 +118,16 @@ class Node < ActiveRecord::Base
117 self.save 118 self.save
118 end 119 end
119 end 120 end
121
122 def check_for_changed_slug
123 if parent and changed.include? "slug"
124 self.update_unique_name
125
126 if tmp_descendants = descendants
127 tmp_descendants.each { |descendant| descendant.update_unique_name }
128 end
129 end
130 end
120end 131end
121 132
122 133