Class: Qbrick::Brick
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Qbrick::Brick
show all
- Includes:
- BrickList, RailsSettings::Extend
- Defined in:
- app/models/qbrick/brick.rb
Instance Method Summary
collapse
Methods included from BrickList
#allowed_brick_types, #brick_types, #collect_fulltext, included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #uploader?, #user_can_add_childs?, #user_can_delete?, #user_can_save?
Instance Method Details
#available_display_styles ⇒ Object
return a list of css classnames that can be applied to the brick
114
115
116
|
# File 'app/models/qbrick/brick.rb', line 114
def available_display_styles
[]
end
|
#backend_label(options = {}) ⇒ Object
124
125
126
127
128
129
130
131
|
# File 'app/models/qbrick/brick.rb', line 124
def backend_label(options = {})
label = self.class.model_name.human
if options[:parenthesis] == true
"(#{label})"
else
label
end
end
|
#brick_list_type ⇒ Object
99
100
101
|
# File 'app/models/qbrick/brick.rb', line 99
def brick_list_type
'Qbrick::Brick'
end
|
#cache_key ⇒ Object
137
138
139
|
# File 'app/models/qbrick/brick.rb', line 137
def cache_key
super + partial_digest(to_partial_path)
end
|
#has_siblings? ⇒ Boolean
63
64
65
|
# File 'app/models/qbrick/brick.rb', line 63
def has_siblings?
brick_list.present? && brick_list.bricks.any?
end
|
#parents ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'app/models/qbrick/brick.rb', line 78
def parents
p = []
parent = brick_list.presence
while parent
p << parent
parent = parent.respond_to?(:brick_list) ? parent.brick_list : nil
end
p.reverse
end
|
#partial_digest(name) ⇒ Object
133
134
135
|
# File 'app/models/qbrick/brick.rb', line 133
def partial_digest(name)
ActionView::Digestor.digest(name: name, finder: ApplicationController.new.lookup_context, partial: true)
end
|
#set_position ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'app/models/qbrick/brick.rb', line 89
def set_position
self.position = if self.position.present?
self.position
elsif self.respond_to?(:brick_list) && brick_list.respond_to?(:bricks)
brick_list.bricks.maximum(:position).to_i + 1
else
1
end
end
|
#to_edit_childs_partial_path ⇒ Object
The child partial can contain your own implementation of how the brick renders it’s child in the edit form. Returns the path to this partial.
72
73
74
75
76
|
# File 'app/models/qbrick/brick.rb', line 72
def to_edit_childs_partial_path
path = to_partial_path.split '/'
path << 'childs'
path.join '/'
end
|
#to_edit_partial_path ⇒ Object
57
58
59
60
61
|
# File 'app/models/qbrick/brick.rb', line 57
def to_edit_partial_path
path = to_partial_path.split '/'
path << 'edit'
path.join '/'
end
|
#to_style_class ⇒ Object
Returns a css classname suitable for use in the frontend
104
105
106
|
# File 'app/models/qbrick/brick.rb', line 104
def to_style_class
([self.class.to_s.underscore.dasherize.gsub('/', '-')] + display_styles).join(' ')
end
|
#to_style_id ⇒ Object
Returns a unique DOM id suitable for use in the frontend
109
110
111
|
# File 'app/models/qbrick/brick.rb', line 109
def to_style_id
"#{self.class.to_s.underscore.dasherize.gsub('/', '-')}-#{id}"
end
|
#translated_available_display_styles ⇒ Object
118
119
120
121
122
|
# File 'app/models/qbrick/brick.rb', line 118
def translated_available_display_styles
available_display_styles.map do |style|
[I18n.t("#{self.class.to_s.demodulize.underscore}.display_styles.#{style}"), style]
end
end
|
#update_fulltext ⇒ Object
TODO: yes. temporary workaround. see above
49
50
51
52
53
54
55
|
# File 'app/models/qbrick/brick.rb', line 49
def update_fulltext
if brick_list.is_a? Page
brick_list.update_fulltext
else
brick_list.brick_list.update_fulltext
end
end
|