Module: Cms::Behaviors::Connecting::InstanceMethods
- Defined in:
- lib/cms/behaviors/connecting.rb
Instance Method Summary collapse
- #connect_to_page ⇒ Object
- #connected_page_count ⇒ Object
- #connected_pages ⇒ Object
- #content_block_type ⇒ Object
- #display_name ⇒ Object
- #display_name_plural ⇒ Object
-
#update_connected_pages ⇒ Object
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.
Instance Method Details
#connect_to_page ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/cms/behaviors/connecting.rb', line 68 def connect_to_page unless connect_to_page_id.blank? || connect_to_container.blank? #Note that we are setting connected_page so that page can look at that #to determine if the page should be published self.connected_page = Page.find(connect_to_page_id) connected_page.create_connector(self, connect_to_container) end true end |
#connected_page_count ⇒ Object
52 53 54 |
# File 'lib/cms/behaviors/connecting.rb', line 52 def connected_page_count Page.currently_connected_to(self).count end |
#connected_pages ⇒ Object
47 48 49 50 |
# File 'lib/cms/behaviors/connecting.rb', line 47 def connected_pages return @connected_pages if @connected_pages @connected_pages = Page.connected_to(self) end |
#content_block_type ⇒ Object
56 57 58 |
# File 'lib/cms/behaviors/connecting.rb', line 56 def content_block_type self.class.content_block_type end |
#display_name ⇒ Object
60 61 62 |
# File 'lib/cms/behaviors/connecting.rb', line 60 def display_name self.class.display_name end |
#display_name_plural ⇒ Object
64 65 66 |
# File 'lib/cms/behaviors/connecting.rb', line 64 def display_name_plural self.class.display_name_plural end |
#update_connected_pages ⇒ Object
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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cms/behaviors/connecting.rb', line 83 def update_connected_pages # If this is versioned, then we need make new versions of all the pages this is connected to 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 # 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}") #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}" page_draft_version = p.draft.version cnn = connectors_for_page.for_page_version(page_draft_version) # puts "Connectors for page version #{page_draft_version} are #{cnn.all}" connectors = cnn.for_connectable(self) # puts "Found connectors #{connectors.all}" connectors.each do |con| con.update_attribute(:connectable_version, draft_version) end end end end true end |