diff options
| author | hukl <contact@smyck.org> | 2009-03-08 22:31:00 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-03-08 22:31:00 +0100 |
| commit | 00fe407be045a5b6cf8269965c0fd35a44094741 (patch) | |
| tree | cf1d0599a6a4614e85021286260cac754d750b22 /app | |
| parent | 3d62eef0723e39c8454035dc1e5ed6a214b20e8b (diff) | |
added date selector for published_at. Also removed the part that reset the published_at attribute to Time.now. Some cleanups
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/node.rb | 5 | ||||
| -rw-r--r-- | app/models/page.rb | 25 | ||||
| -rw-r--r-- | app/views/nodes/edit.html.erb | 5 |
3 files changed, 12 insertions, 23 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 7f2bca6..d2db4ba 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -59,7 +59,6 @@ class Node < ActiveRecord::Base | |||
| 59 | def create_new_draft user | 59 | def create_new_draft user |
| 60 | empty_page = self.pages.new | 60 | empty_page = self.pages.new |
| 61 | empty_page.user = user | 61 | empty_page.user = user |
| 62 | |||
| 63 | empty_page.clone_attributes_from self.head | 62 | empty_page.clone_attributes_from self.head |
| 64 | 63 | ||
| 65 | self.draft = empty_page | 64 | self.draft = empty_page |
| @@ -70,11 +69,9 @@ class Node < ActiveRecord::Base | |||
| 70 | def publish_draft! | 69 | def publish_draft! |
| 71 | if self.draft | 70 | if self.draft |
| 72 | self.head = self.draft | 71 | self.head = self.draft |
| 72 | self.head.save! | ||
| 73 | self.draft = nil | 73 | self.draft = nil |
| 74 | self.save! | 74 | self.save! |
| 75 | |||
| 76 | self.head.published_at = Time.now | ||
| 77 | self.head.save! | ||
| 78 | else | 75 | else |
| 79 | nil | 76 | nil |
| 80 | end | 77 | end |
diff --git a/app/models/page.rb b/app/models/page.rb index a27ccfc..ae2f998 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -19,7 +19,7 @@ class Page < ActiveRecord::Base | |||
| 19 | before_save :rewrite_links_in_body | 19 | before_save :rewrite_links_in_body |
| 20 | 20 | ||
| 21 | # Security | 21 | # Security |
| 22 | attr_accessible :title, :abstract, :body, :template_name | 22 | attr_accessible :title, :abstract, :body, :template_name, :published_at |
| 23 | 23 | ||
| 24 | # Class Methods | 24 | # Class Methods |
| 25 | 25 | ||
| @@ -59,24 +59,6 @@ class Page < ActiveRecord::Base | |||
| 59 | end | 59 | end |
| 60 | 60 | ||
| 61 | # Instance Methods | 61 | # Instance Methods |
| 62 | |||
| 63 | def clone_attributes_from page | ||
| 64 | return nil unless page | ||
| 65 | |||
| 66 | self.tag_list = page.tag_list.join(", ") | ||
| 67 | |||
| 68 | locale_before = I18n.locale | ||
| 69 | |||
| 70 | I18n.available_locales.each do |l| | ||
| 71 | next if l == :root | ||
| 72 | I18n.locale = l | ||
| 73 | self.title = page.title | ||
| 74 | self.abstract = page.abstract | ||
| 75 | self.body = page.body | ||
| 76 | end | ||
| 77 | |||
| 78 | I18n.locale = locale_before | ||
| 79 | end | ||
| 80 | 62 | ||
| 81 | def public_template_path | 63 | def public_template_path |
| 82 | File.join(PUBLIC_TEMPLATE_PATH, template_name) | 64 | File.join(PUBLIC_TEMPLATE_PATH, template_name) |
| @@ -106,8 +88,13 @@ class Page < ActiveRecord::Base | |||
| 106 | def clone_attributes_from page | 88 | def clone_attributes_from page |
| 107 | return nil unless page | 89 | return nil unless page |
| 108 | 90 | ||
| 91 | # Clone untranslated attributes | ||
| 92 | |||
| 109 | self.tag_list = page.tag_list.join(", ") | 93 | self.tag_list = page.tag_list.join(", ") |
| 110 | self.template_name = page.template_name | 94 | self.template_name = page.template_name |
| 95 | self.published_at = page.published_at | ||
| 96 | |||
| 97 | # Clone translated attributes | ||
| 111 | 98 | ||
| 112 | locale_before = I18n.locale | 99 | locale_before = I18n.locale |
| 113 | 100 | ||
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 929bbf6..d230f5c 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb | |||
| @@ -13,6 +13,11 @@ | |||
| 13 | <%= f.error_messages %> | 13 | <%= f.error_messages %> |
| 14 | 14 | ||
| 15 | <% fields_for @draft do |d| %> | 15 | <% fields_for @draft do |d| %> |
| 16 | |||
| 17 | <p> | ||
| 18 | <%= d.label :published_at %><br /> | ||
| 19 | <%= d.datetime_select :published_at %> | ||
| 20 | </p> | ||
| 16 | <p> | 21 | <p> |
| 17 | <%= d.label :template_name %> | 22 | <%= d.label :template_name %> |
| 18 | <%= d.select :template_name, custom_page_templates %> | 23 | <%= d.select :template_name, custom_page_templates %> |
