Class: Cms::SectionNode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::SectionNode
- Defined in:
- app/models/cms/section_node.rb
Instance Method Summary collapse
- #ancestry_path ⇒ Object
- #move_after(section_node) ⇒ Object
- #move_before(section_node) ⇒ Object
- #move_to(section, position) ⇒ Object
- #move_to_beginning(sec) ⇒ Object
- #move_to_end(sec) ⇒ Object
- #orphaned? ⇒ Boolean
-
#page? ⇒ Boolean
Is this node a page.
-
#parent_section ⇒ Object
(also: #section)
This is the parent section for this node For backwards compatiblity.
-
#scope_condition ⇒ Object
For acts_as_list.
-
#section=(new_section) ⇒ Object
For backwards compatiblity.
-
#section? ⇒ Boolean
Is this node a section.
- #visible? ⇒ Boolean
Instance Method Details
#ancestry_path ⇒ Object
105 106 107 |
# File 'app/models/cms/section_node.rb', line 105 def ancestry_path path_ids.join "/" end |
#move_after(section_node) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'app/models/cms/section_node.rb', line 87 def move_after(section_node) if section == section_node.section && position < section_node.position pos = section_node.position else pos = section_node.position + 1 end move_to(section_node.section, pos) end |
#move_before(section_node) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/models/cms/section_node.rb', line 78 def move_before(section_node) if section == section_node.section && position < section_node.position pos = section_node.position - 1 else pos = section_node.position end move_to(section_node.section, pos) end |
#move_to(section, position) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/cms/section_node.rb', line 56 def move_to(section, position) #logger.info "Moving Section Node ##{id} to Section ##{sec.id} Position #{pos}" transaction do if self.parent != section.node remove_from_list self.parent = section.node save end if position < 0 position = 0 else #This helps prevent the position from getting out of whack #If you pass in a really high number for position, #this just corrects it to the right number node_count =Cms::SectionNode.count(:conditions => {:ancestry => ancestry}) position = node_count if position > node_count end insert_at_position(position) end end |
#move_to_beginning(sec) ⇒ Object
96 97 98 |
# File 'app/models/cms/section_node.rb', line 96 def move_to_beginning(sec) move_to(sec, 0) end |
#move_to_end(sec) ⇒ Object
100 101 102 103 |
# File 'app/models/cms/section_node.rb', line 100 def move_to_end(sec) #1.0/0 == Infinity move_to(sec, 1.0/0) end |
#orphaned? ⇒ Boolean
40 41 42 |
# File 'app/models/cms/section_node.rb', line 40 def orphaned? !node || (node.class.uses_soft_delete? && node.deleted?) end |
#page? ⇒ Boolean
Is this node a page
50 51 52 |
# File 'app/models/cms/section_node.rb', line 50 def page? node_type == 'Cms::Page' end |
#parent_section ⇒ Object Also known as: section
This is the parent section for this node For backwards compatiblity
8 9 10 |
# File 'app/models/cms/section_node.rb', line 8 def parent_section self.parent ? self.parent.node : nil end |
#scope_condition ⇒ Object
For acts_as_list. Specifies that position should be unique within a section.
24 25 26 |
# File 'app/models/cms/section_node.rb', line 24 def scope_condition ancestry ? "ancestry = '#{ancestry}'" : 'ancestry IS NULL' end |
#section=(new_section) ⇒ Object
For backwards compatiblity
15 16 17 |
# File 'app/models/cms/section_node.rb', line 15 def section=(new_section) self.parent = new_section.node end |
#section? ⇒ Boolean
Is this node a section
45 46 47 |
# File 'app/models/cms/section_node.rb', line 45 def section? node_type == 'Cms::Section' end |
#visible? ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'app/models/cms/section_node.rb', line 32 def visible? return false unless node return false if (node.respond_to?(:hidden?) && node.hidden?) return false if (node.respond_to?(:archived?) && node.archived?) return false if (node.respond_to?(:published?) && !node.published?) true end |