Module: CoreFloatingActionButtonHelper
- Defined in:
- app/helpers/core_floating_action_button_helper.rb
Overview
Draw floating action buttons for the page
Instance Method Summary collapse
-
#add_fab_button(clazz, path) ⇒ Object
abstract
Single action buttons.
- #add_floating_action_link(clazz, path) ⇒ Object abstract
- #delete_floating_action_button(clazz, path, title: 'Delete', icon_name: 'delete-bin', confirm: 'Are you sure you want to delete this item?') ⇒ Object
- #edit_fab_button(obj, path) ⇒ Object abstract
- #edit_floating_action_link(clazz, path) ⇒ Object abstract
- #floating_action_button(path, title: 'Add', icon_name: 'add-circle') ⇒ Object abstract
- #floating_action_link(path, title, icon_name, confirm: nil, method: :get) ⇒ Object
-
#multiple_floating_action_button(&block) ⇒ Object
abstract
Multiple action buttons.
- #refresh_floating_action_link(clazz, path, title: 'Refresh', icon_name: 'refresh', confirm: 'Are you sure you want to refresh this item?') ⇒ Object abstract
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 (clazz, path) return unless can?(:create, clazz) (path, title: "Add #{clazz.to_s.humanize}", icon_name: 'add-circle') end |
#add_floating_action_link(clazz, path) ⇒ Object
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 (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 (obj, path) return unless can?(:edit, obj) (path, title: 'Edit', icon_name: 'edit') end |
#edit_floating_action_link(clazz, path) ⇒ Object
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 (path, title: 'Add', icon_name: 'add-circle') content_tag(:div, class: 'btn-fab') do concat(content_tag(:a, class: 'btn btn-primary btn-large rounded-circle', href: path, title: title) do concat(content_tag(:i, class: "ri-#{icon_name}-line ri-36px") {}) end) end end |
#floating_action_link(path, title, icon_name, confirm: nil, method: :get) ⇒ Object
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 } content_tag(:li) do concat(content_tag(:a, class: 'dropdown-item', href: path, data: data) do concat((icon_name)) concat(content_tag(: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 (&block) content_tag(:div, class: 'btn-fab') do concat(content_tag(: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(content_tag(:ul, class: 'dropdown-menu') { yield block }) end end |
#refresh_floating_action_link(clazz, path, title: 'Refresh', icon_name: 'refresh', confirm: 'Are you sure you want to refresh this item?') ⇒ Object
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 |