Class: Cms::SectionNode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::SectionNode
- Defined in:
- app/models/cms/section_node.rb
Class Method Summary collapse
- .fetch_nodes ⇒ Object
- .in_order ⇒ Object
-
.not_of_type(klass) ⇒ Object
Return all section nodes which are not of the given type (i.e. class name).
- .of_type(types) ⇒ Object
Instance Method Summary collapse
- #ancestry_path ⇒ Object
- #deletable? ⇒ Boolean
-
#home? ⇒ Boolean
Determines if this node is the homepage of the site.
- #link? ⇒ Boolean
- #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
Class Method Details
.fetch_nodes ⇒ Object
40 41 42 |
# File 'app/models/cms/section_node.rb', line 40 def fetch_nodes includes(:node) end |
.in_order ⇒ Object
36 37 38 |
# File 'app/models/cms/section_node.rb', line 36 def in_order order("position asc") end |
.not_of_type(klass) ⇒ Object
Return all section nodes which are not of the given type (i.e. class name)
47 48 49 |
# File 'app/models/cms/section_node.rb', line 47 def self.not_of_type(klass) where("#{table_name}.node_type NOT IN (?)", klass) end |
.of_type(types) ⇒ Object
32 33 34 |
# File 'app/models/cms/section_node.rb', line 32 def of_type(types) where(["#{table_name}.node_type IN (?)", types]) end |
Instance Method Details
#ancestry_path ⇒ Object
141 142 143 |
# File 'app/models/cms/section_node.rb', line 141 def ancestry_path path_ids.join "/" end |
#deletable? ⇒ Boolean
82 83 84 85 86 87 88 |
# File 'app/models/cms/section_node.rb', line 82 def deletable? return false if self.root? if node.respond_to?(:deletable?) return node.deletable? end true end |
#home? ⇒ Boolean
Determines if this node is the homepage of the site.
52 53 54 |
# File 'app/models/cms/section_node.rb', line 52 def home? page? && node.home? end |
#link? ⇒ Boolean
78 79 80 |
# File 'app/models/cms/section_node.rb', line 78 def link? node_type == 'Cms::Link' end |
#move_after(section_node) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'app/models/cms/section_node.rb', line 123 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
114 115 116 117 118 119 120 121 |
# File 'app/models/cms/section_node.rb', line 114 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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/cms/section_node.rb', line 92 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.where({:ancestry => ancestry}).count position = node_count if position > node_count end insert_at_position(position) end end |
#move_to_beginning(sec) ⇒ Object
132 133 134 |
# File 'app/models/cms/section_node.rb', line 132 def move_to_beginning(sec) move_to(sec, 0) end |
#move_to_end(sec) ⇒ Object
136 137 138 139 |
# File 'app/models/cms/section_node.rb', line 136 def move_to_end(sec) #1.0/0 == Infinity move_to(sec, 1.0/0) end |
#orphaned? ⇒ Boolean
64 65 66 |
# File 'app/models/cms/section_node.rb', line 64 def orphaned? !node || (node.class.uses_soft_delete? && node.deleted?) end |
#page? ⇒ Boolean
Is this node a page
74 75 76 |
# File 'app/models/cms/section_node.rb', line 74 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
10 11 12 |
# File 'app/models/cms/section_node.rb', line 10 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.
26 27 28 |
# File 'app/models/cms/section_node.rb', line 26 def scope_condition ancestry ? "ancestry = '#{ancestry}'" : 'ancestry IS NULL' end |
#section=(new_section) ⇒ Object
For backwards compatiblity
17 18 19 |
# File 'app/models/cms/section_node.rb', line 17 def section=(new_section) self.parent = new_section.node end |
#section? ⇒ Boolean
Is this node a section
69 70 71 |
# File 'app/models/cms/section_node.rb', line 69 def section? node_type == 'Cms::Section' end |
#visible? ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'app/models/cms/section_node.rb', line 56 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 |