Skip to content

Commit

Permalink
Support for edit_form in content model, made content_node more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed May 2, 2010
1 parent df9ee49 commit b558d7c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
13 changes: 12 additions & 1 deletion app/models/content_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def field(name)
# Returns a select-friendly list of available relationship classes
def self.relationship_classes
content_models = ContentModel.find(:all,:order => 'name')
clses = [ [ 'User', 'end_user' ] ] + content_models.collect { |mdl| [ mdl.name, mdl.table_name ] }
clses = [ [ 'User', 'end_user' ], ['(Other)', 'other'] ] + content_models.collect { |mdl| [ mdl.name, mdl.table_name ] }
end

def destroy_linked_content #:nodoc:
Expand Down Expand Up @@ -247,6 +247,17 @@ def update_entry(entry,parameters,user=nil)
return entry.update_attributes(entry_attributes(parameters))
end
end

# render an edit form from the fields
def edit_form(f,options = {})
options= options.clone
except=options.delete(:except).to_i
self.content_model_fields.map do |fld|
if fld.id != except
fld.form_field(f)
end
end.compact.join
end

# Checks a list of content_model_fields given a list of ids
def process_fields(fields)
Expand Down
5 changes: 5 additions & 0 deletions app/models/content_model_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class ContentModelField < DomainModel
belongs_to :content_model

has_many :content_relations, :dependent => :delete_all

named_scope :core_fields, lambda { |name|
{ :conditions => { :field_module => 'content/core_field',
:field_type => name } }
}

# acts_as_list

Expand Down
5 changes: 3 additions & 2 deletions app/models/content_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def update_node_content(user,item,opts={}) #:nodoc:
opts = opts.symbolize_keys
if self.content_type_id.blank?
if opts[:container_type] # If there is a container field
container_type = opts.delete(:container_type)
container_id = item.send(opts.delete(:container_field))
container_type = item.resolve_argument(opts.delete(:container_type))
container_id = item.send(item.resolve_argument(opts.delete(:container_field)))

self.content_type = ContentType.find_by_container_type_and_container_id(container_type,container_id)
else
self.content_type = ContentType.find_by_content_type(item.class.to_s)
Expand Down
4 changes: 2 additions & 2 deletions app/models/content_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def add_all_fields!
)
end
end


def assign_entry(entry,values = {},application_state = {})
application_state = application_state.merge({:values => values })
Expand Down Expand Up @@ -104,8 +105,7 @@ def update_entry(entry,values = {},application_state = {})
false
end
end



def form?
self.publication_type_class.respond_to?(:render_form)
end
Expand Down
11 changes: 5 additions & 6 deletions app/models/model_extension/content_node_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ def content_node_type_create #:nodoc:

def content_node_type_update #:nodoc:
opts = self.content_node_type_options

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


# Get the name of the content
content_name = self.resolve_argument(opts[:content_name],:name)

if !self.content_type || content_name != self.content_type.content_name

if !self.content_type
self.content_node_type_create
elsif content_name != self.content_type.content_name
self.content_type.update_attributes(:content_name => content_name)
end

Expand Down

0 comments on commit b558d7c

Please sign in to comment.