Class: Trestle::Resource::Toolbar::Builder

Inherits:
Toolbar::Builder show all
Defined in:
lib/trestle/resource/toolbar.rb

Instance Method Summary collapse

Methods inherited from Toolbar::Builder

builder_method, #button, #dropdown, #initialize, #link

Constructor Details

This class inherits a constructor from Trestle::Toolbar::Builder

Instance Method Details

#delete(label: t("buttons.delete", default: "Delete %{model_name}"), **attrs) ⇒ Object



20
21
22
23
24
25
# File 'lib/trestle/resource/toolbar.rb', line 20

def delete(label: t("buttons.delete", default: "Delete %{model_name}"), **attrs)
  return unless action?(:destroy)

  defaults = Trestle::Options.new(action: :destroy, style: :danger, icon: "fa fa-trash", data: { turbo_method: "delete", turbo_frame: "_top", controller: "confirm-delete", confirm_delete_placement_value: "bottom" })
  link(label, instance, **defaults.merge(attrs))
end

#dismiss(label: t("buttons.ok", default: "OK"), **attrs) ⇒ Object Also known as: ok



27
28
29
30
31
32
# File 'lib/trestle/resource/toolbar.rb', line 27

def dismiss(label: t("buttons.ok", default: "OK"), **attrs)
  return unless @template.modal_request?

  defaults = Trestle::Options.new(type: :button, style: :light, data: { bs_dismiss: "modal" })
  button(label, **defaults.merge(attrs))
end

#new(label: t("buttons.new", default: "New %{model_name}"), **attrs) ⇒ Object



8
9
10
11
12
13
# File 'lib/trestle/resource/toolbar.rb', line 8

def new(label: t("buttons.new", default: "New %{model_name}"), **attrs)
  return unless action?(:new)

  defaults = { action: :new, style: :light, icon: "fa fa-plus", class: "btn-new-resource" }
  link(label, **defaults.merge(attrs))
end

#save(label: t("buttons.save", default: "Save %{model_name}"), **attrs) ⇒ Object



15
16
17
18
# File 'lib/trestle/resource/toolbar.rb', line 15

def save(label: t("buttons.save", default: "Save %{model_name}"), **attrs)
  defaults = { style: :success }
  button(label, **defaults.merge(attrs))
end

#save_or_dismiss(action = :update) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/trestle/resource/toolbar.rb', line 35

def save_or_dismiss(action=:update)
  if action?(action)
    save
  else
    dismiss
  end
end