Class: Kuhsaft::Brick

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
BrickList
Defined in:
app/models/kuhsaft/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_stylesObject

return a list of css classnames that can be applied to the brick



107
108
109
# File 'app/models/kuhsaft/brick.rb', line 107

def available_display_styles
  []
end

#backend_label(options = {}) ⇒ Object



111
112
113
114
115
116
117
118
# File 'app/models/kuhsaft/brick.rb', line 111

def backend_label(options = {})
  label = self.class.model_name.human
  if options[:parenthesis] == true
    "(#{label})"
  else
    label
  end
end

#brick_list_typeObject



92
93
94
# File 'app/models/kuhsaft/brick.rb', line 92

def brick_list_type
  'Kuhsaft::Brick'
end

#has_siblings?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'app/models/kuhsaft/brick.rb', line 54

def has_siblings?
  if brick_list
    brick_list.bricks.any?
  end
end

#parentsObject



71
72
73
74
75
76
77
78
79
80
# File 'app/models/kuhsaft/brick.rb', line 71

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

#set_positionObject



82
83
84
85
86
87
88
89
90
# File 'app/models/kuhsaft/brick.rb', line 82

def set_position
  self.position = if self.position.present?
    self.position
  elsif self.respond_to?(:brick_list) && self.brick_list.respond_to?(:bricks)
    brick_list.bricks.maximum(:position).to_i + 1
  else
    1
  end
end

#to_edit_childs_partial_pathObject

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.



65
66
67
68
69
# File 'app/models/kuhsaft/brick.rb', line 65

def to_edit_childs_partial_path
  path = self.to_partial_path.split '/'
  path << 'childs'
  path.join '/'
end

#to_edit_partial_pathObject



48
49
50
51
52
# File 'app/models/kuhsaft/brick.rb', line 48

def to_edit_partial_path
  path = self.to_partial_path.split '/'
  path << 'edit'
  path.join '/'
end

#to_style_classObject

Returns a css classname suitable for use in the frontend



97
98
99
# File 'app/models/kuhsaft/brick.rb', line 97

def to_style_class
  ([self.class.to_s.underscore.dasherize.gsub('/', '-')] + self.display_styles).join(' ')
end

#to_style_idObject

Returns a unique DOM id suitable for use in the frontend



102
103
104
# File 'app/models/kuhsaft/brick.rb', line 102

def to_style_id
  "#{self.class.to_s.underscore.dasherize.gsub('/', '-')}-#{id}"
end

#update_fulltextObject

TODO: yes. temporary workaround. see above



40
41
42
43
44
45
46
# File 'app/models/kuhsaft/brick.rb', line 40

def update_fulltext
  if brick_list.is_a? Page
    brick_list.update_fulltext
  else
    brick_list.brick_list.update_fulltext
  end
end