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

#collect_fulltext, included, #renders_own_childs?, #to_brick_item_id, #to_brick_list_id, #user_can_add_childs?, #user_can_delete?, #user_can_save?

Instance Method Details

#backend_label(options = {}) ⇒ Object



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

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

#brick_list_typeObject



68
69
70
# File 'app/models/kuhsaft/brick.rb', line 68

def brick_list_type
  'Kuhsaft::Brick'
end

#parentsObject



43
44
45
46
47
48
49
50
51
52
# File 'app/models/kuhsaft/brick.rb', line 43

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_localeObject



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

def set_locale
  self.locale = self.locale.presence || I18n.locale
end

#set_positionObject



58
59
60
61
62
63
64
65
66
# File 'app/models/kuhsaft/brick.rb', line 58

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.



37
38
39
40
41
# File 'app/models/kuhsaft/brick.rb', line 37

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

#to_edit_partial_pathObject



26
27
28
29
30
# File 'app/models/kuhsaft/brick.rb', line 26

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



73
74
75
# File 'app/models/kuhsaft/brick.rb', line 73

def to_style_class
  self.class.to_s.underscore.dasherize.gsub('/', '-')
end

#to_style_idObject

Returns a unique DOM id suitable for use in the frontend



78
79
80
# File 'app/models/kuhsaft/brick.rb', line 78

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