lib/cms/behaviors/connecting.rb in browsercms-3.5.7 vs lib/cms/behaviors/connecting.rb in browsercms-4.0.0.alpha
- old
+ new
@@ -16,11 +16,11 @@
@is_connectable = true
extend ClassMethods
include InstanceMethods
attr_accessor :connect_to_page_id, :connect_to_container,:connected_page
- attr_accessible :connect_to_page_id, :connect_to_container,:connected_page
+ #attr_accessible :connect_to_page_id, :connect_to_container,:connected_page
has_many :connectors, :as => :connectable, :class_name => 'Cms::Connector'
attr_accessor :updated_by_page
@@ -31,21 +31,27 @@
end
end
module ClassMethods
def content_block_type
- ActiveModel::Naming.singular(self)
+ ::ActiveModel::Naming.singular(self)
end
def display_name
Connecting.default_naming_for(self)
end
def display_name_plural
display_name.pluralize
end
end
module InstanceMethods
+ # Returns a machine readable key that identifies the type of content this is.
+ # Should match the key passed to ContentType.find_by_key
+ def content_name
+ self.class.name.demodulize.underscore
+ end
+
def connected_pages
return @connected_pages if @connected_pages
@connected_pages = Page.connected_to(self)
end
@@ -73,10 +79,14 @@
connected_page.create_connector(self, connect_to_container)
end
true
end
+ # By default, all content types will support inline editing. Subclasses can override this.
+ def supports_inline_editing?
+ true
+ end
#
# After blocks are updated, all pages they are connected to should also be updated,
# connecting the page to the new version of the block, as well as putting the pages into
# draft status if necessary.
#
@@ -85,18 +95,18 @@
if self.class.versioned?
#logger.info "..... Updating connected pages for #{self.class} #{id} v#{version}"
#Get all the pages the previous version of this connectable was connected to
draft_version = draft.version
- connected_pages = Page.connected_to(:connectable => self, :version => (draft_version - 1)).all
+ connected_pages = Page.connected_to(:connectable => self, :version => (draft_version - 1)).to_a
# puts "Found #{connected_pages}"
connected_pages.each do |p|
# This is needed in the case of updating page,
# which updates this object, so as not to create a loop
if p != updated_by_page
#This just creates a new version of the page
action = deleted? ? "Deleted" : "Edited"
- p.update_attributes(:version_comment => "#{self.class.name.demodulize} ##{id} was #{action}")
+ p.update_attributes(:version_comment => "#{self.class.name.demodulize} ##{id} was #{action}", :publish_on_save=>false)
#The previous step will copy over a connector pointing to the previous version of this connectable
#We need to change that to point at the new version of this connectable
connectors_for_page = p.connectors
# puts "cfp #{connectors_for_page}"