Skip to content

Commit

Permalink
Added push_value and proc support for content_type field values
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Mar 27, 2010
1 parent c15b35a commit acfc3d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
16 changes: 14 additions & 2 deletions app/models/content_node.rb
Expand Up @@ -114,6 +114,10 @@ def update_node_content(user,item,opts={}) #:nodoc:
self.last_editor_id = user_id if user_id
end
self.save

if opts[:push_value]
generate_content_values!
end
end


Expand All @@ -122,10 +126,18 @@ def update_node_content(user,item,opts={}) #:nodoc:
def admin_url
if self.content_type
if self.content_type.container
self.content_type.container.content_admin_url(self.node_id)
if self.content_type.container.respond_to?(:content_admin_url)
self.content_type.container.content_admin_url(self.node_id)
else
raise "#{self.content_type.container_type} needs to define content admin url"
end
else
cls =self.content_type.content_type.constantize
cls.content_admin_url(self.node_id)
if cls.respond_to?(:content_admin_url)
cls.content_admin_url(self.node_id)
else
raise "#{cls.to_s} needs to define content admin url"
end
end
else
nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/content_type.rb
Expand Up @@ -59,7 +59,7 @@ def before_create #:nodoc:
end

def after_update #:nodoc:
self.content_node_values.delete
self.content_node_values.clear
end

# Full name of this content type
Expand Down
13 changes: 9 additions & 4 deletions app/models/model_extension/content_node_extension.rb
Expand Up @@ -19,6 +19,8 @@ module ClassMethods
# string representing the class that is the ContentType container for this class
# [:container_field]
# symbol with the name of the attribute that is the belong_to foreign key for the container
# [:push_value]
# set to true to immediately push the content node value - should only be done for admin only content models
def content_node(options = {})
attr_accessor :content_node_skip
after_save :content_node_save
Expand Down Expand Up @@ -107,8 +109,11 @@ def content_node_type_create #:nodoc:

opts = self.content_node_type_options

title_field = (opts[:title_field] || 'name').to_s
url_field = (opts[:url_field] || 'id').to_s
title_field = (opts[:title_field] || 'name')
url_field = (opts[:url_field] || 'id')

title_field = title_field.call(self) if title_field.is_a?(Proc)
url_field = url_field.call(self) if url_field.is_a?(Proc)

# Get the name of the content
content_name = self.resolve_argument(opts[:content_name],:name)
Expand All @@ -118,8 +123,8 @@ def content_node_type_create #:nodoc:
:container => self,
:content_name => content_name,
:content_type => content_type,
:title_field => title_field,
:url_field => url_field,
:title_field => title_field.to_s,
:url_field => url_field.to_s,
:search_results => opts[:search] )
end
end
Expand Down

0 comments on commit acfc3d7

Please sign in to comment.