Module: CoreFloatingActionButtonHelper

Defined in:
app/helpers/core_floating_action_button_helper.rb

Overview

Draw floating action buttons for the page

Instance Method Summary collapse

Instance Method Details

#add_fab_button(clazz, path) ⇒ Object

This method is abstract.

Render a creation FAB

Single action buttons



9
10
11
12
13
# File 'app/helpers/core_floating_action_button_helper.rb', line 9

def add_fab_button(clazz, path)
  return unless can?(:create, clazz)

  floating_action_button(path, title: "Add #{clazz.to_s.humanize}", icon_name: 'add-circle')
end
This method is abstract.

add floating action



53
54
55
56
57
# File 'app/helpers/core_floating_action_button_helper.rb', line 53

def add_floating_action_link(clazz, path)
  return unless can?(:create, clazz)

  floating_action_link(path, "New #{clazz.to_s.humanize}", 'add-circle')
end

#delete_floating_action_button(clazz, path, title: 'Delete', icon_name: 'delete-bin', confirm: 'Are you sure you want to delete this item?') ⇒ Object



46
47
48
49
50
# File 'app/helpers/core_floating_action_button_helper.rb', line 46

def delete_floating_action_button(clazz, path, title: 'Delete', icon_name: 'delete-bin', confirm: 'Are you sure you want to delete this item?')
  return unless can?(:destroy, clazz)

  floating_action_link(path, title, icon_name, confirm: confirm, method: :delete)
end

#edit_fab_button(obj, path) ⇒ Object

This method is abstract.

Render a creation FAB



16
17
18
19
20
# File 'app/helpers/core_floating_action_button_helper.rb', line 16

def edit_fab_button(obj, path)
  return unless can?(:edit, obj)

  floating_action_button(path, title: 'Edit', icon_name: 'edit')
end
This method is abstract.

Edit floating action, if the user is allowed to edit the object



60
61
62
63
64
# File 'app/helpers/core_floating_action_button_helper.rb', line 60

def edit_floating_action_link(clazz, path)
  return unless can?(:edit, clazz)

  floating_action_link(path, 'Edit', 'edit')
end

#floating_action_button(path, title: 'Add', icon_name: 'add-circle') ⇒ Object

This method is abstract.

Render a floating action button



23
24
25
26
27
28
29
# File 'app/helpers/core_floating_action_button_helper.rb', line 23

def floating_action_button(path, title: 'Add', icon_name: 'add-circle')
  (:div, class: 'btn-fab') do
    concat((:a, class: 'btn btn-primary btn-large rounded-circle', href: path, title: title) do
      concat((:i, class: "ri-#{icon_name}-line ri-36px") {})
    end)
  end
end


73
74
75
76
77
78
79
80
81
# File 'app/helpers/core_floating_action_button_helper.rb', line 73

def floating_action_link(path, title, icon_name, confirm: nil, method: :get)
  data = { confirm: confirm, title: title, method: method }
  (:li) do
    concat((:a, class: 'dropdown-item', href: path, data: data) do
      concat(menu_remix_icon(icon_name))
      concat((:span) { title })
    end)
  end
end

#multiple_floating_action_button(&block) ⇒ Object

This method is abstract.

Build the FAB that has a “more” icon and yields the buttons

Multiple action buttons



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/core_floating_action_button_helper.rb', line 33

def multiple_floating_action_button(&block)
  (:div, class: 'btn-fab') do
    concat((:button, class: 'btn btn-primary btn-lg rounded-circle',
                       type: :button,
                       'data-bs-toggle': :dropdown,
                       haspopup: true,
                       'aria-expanded': false) do
      remix_icon('more-2', classes: %w[ri-24px])
    end)
    concat((:ul, class: 'dropdown-menu') { yield block })
  end
end
This method is abstract.

Edit floating action, if the user is allowed to edit the object



67
68
69
70
71
# File 'app/helpers/core_floating_action_button_helper.rb', line 67

def refresh_floating_action_link(clazz, path, title: 'Refresh', icon_name: 'refresh', confirm: 'Are you sure you want to refresh this item?')
  return unless can?(:edit, clazz)

  floating_action_link(path, title, icon_name, confirm: confirm)
end