Skip to content

Commit

Permalink
Can add a content model to a blog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Youch committed Jun 24, 2010
1 parent 703ec73 commit b35466e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions vendor/modules/blog/app/controllers/blog/page_feature.rb
Expand Up @@ -128,6 +128,9 @@ def blog_entry_tags(c,data)
nil
end
end

c.expansion_tag('entry:content') { |tag| tag.locals.form = tag.locals.entry.data_model }
c.publication_field_tags('entry:content', data[:blog].content_publication)
end

feature :blog_categories, :default_feature => <<-FEATURE
Expand Down
7 changes: 7 additions & 0 deletions vendor/modules/blog/app/models/blog/blog_blog.rb
Expand Up @@ -10,6 +10,9 @@ class Blog::BlogBlog < DomainModel

belongs_to :blog_target

belongs_to :content_model
belongs_to :content_publication

has_many :blog_posts, :dependent => :destroy, :include => :active_revision
has_many :blog_categories, :class_name => 'Blog::BlogCategory', :dependent => :destroy, :order => 'blog_categories.name'

Expand Down Expand Up @@ -97,6 +100,10 @@ def self.filter_options
ContentFilter.filter_options
end

def before_save
self.content_publication_id = nil if self.content_model.nil? || self.content_publication.nil? || self.content_model.id != self.content_publication.content_model_id
end

def before_validation_on_create
if self.is_user_blog?
self.content_filter = 'safe_html' if self.is_user_blog?
Expand Down
18 changes: 18 additions & 0 deletions vendor/modules/blog/app/models/blog/blog_post.rb
Expand Up @@ -30,11 +30,24 @@ class Blog::BlogPost < DomainModel

has_content_tags

def data_model
return @data_model if @data_model
return nil unless self.blog_blog.content_model
@data_model = self.blog_blog.content_model.content_model.find_by_id self.data_model_id if self.data_model_id
@data_model = self.blog_blog.content_model.content_model.new unless @data_model
@data_model
end

def data_model=(opts)
self.data_model.attributes = opts
end

def validate
if self.status == 'published' && !self.published_at.is_a?(Time)
self.errors.add(:published_at,'is invalid')
end

self.errors.add_to_base('%s is invalid' / self.blog_blog.content_model.name) if self.data_model && ! self.data_model.valid?
end

content_node :container_type => :content_node_container_type, :container_field => Proc.new { |post| post.content_node_container_id },
Expand Down Expand Up @@ -172,6 +185,11 @@ def self.comment_posted(blog_id)


def before_save
if self.data_model
self.data_model.save
self.data_model_id = self.data_model.id
end

self.active_revision.update_attribute(:status,'old') if self.active_revision
@revision = @revision.clone

Expand Down
4 changes: 3 additions & 1 deletion vendor/modules/blog/app/views/blog/manage/configure.rhtml
Expand Up @@ -8,8 +8,10 @@
<%= f.text_field :html_class, :description => 'HTML Class to wrap blog posts in WYSIWYG Editor (optional)' %>
<%= f.access_control :edit_permission, 'Limit which admins can edit this blog', :description => 'User must also have Blog Writer permission' %>
<%= f.check_boxes :trackback, [['Send pingbacks when a post is published.', true]], :label => 'Pingbacks', :single => true %>
<%= f.select :content_model_id, ContentModel.select_options_with_nil %>
<%= f.select :content_publication_id, @blog.content_model ? @blog.content_model.content_publications.select_options_with_nil : [["--Select %s--" / 'Content publication', nil]] %>
<%= f.spacer %>
<%= f.submit_tag 'Update' %>
<% end -%>


</div>
16 changes: 16 additions & 0 deletions vendor/modules/blog/app/views/blog/manage/post.rhtml
Expand Up @@ -125,6 +125,22 @@
<% end -%>
<%= f.datetime_field :published_at, :label => '',:unstyled => true, :blank => true, :disabled => !(@entry.status == 'published' && ( !@entry.published_at || @entry.published_at > Time.now ) ) %>
</div>

<% if @blog.content_model -%>
<div class='sidebar_header'>
<%= @blog.content_model.name %>
</div>
<div class='sidebar_group'>
<table>
<% cms_subfields_for 'entry[data_model]', @entry.data_model do |cf| -%>
<% @blog.content_model.content_model_fields.each do |field| -%>
<%= field.form_field(cf, :vertical => true) %>
<% end -%>
</table>
<% end -%>
</div>
<% end -%>

<div align='center'>
<table>
<%= f.submit_tag @entry.id ? 'Update Entry' : 'Create Entry',:unstyled => true %>
Expand Down
13 changes: 13 additions & 0 deletions vendor/modules/blog/db/20100624134614_add_content_model_to_blog.rb
@@ -0,0 +1,13 @@
class AddContentModelToBlog < ActiveRecord::Migration
def self.up
add_column :blog_blogs, :content_model_id, :integer
add_column :blog_blogs, :content_publication_id, :integer
add_column :blog_posts, :data_model_id, :integer
end

def self.down
remove_column :blog_blogs, :content_model_id
remove_column :blog_blogs, :content_publication_id
remove_column :blog_posts, :data_model_id
end
end

0 comments on commit b35466e

Please sign in to comment.