class Para::Markup::ResourcesButtons

Attributes

component[R]

Public Class Methods

new(component, view) click to toggle source
Calls superclass method Para::Markup::Component::new
# File lib/para/markup/resources_buttons.rb, line 6
def initialize(component, view)
  @component = component
  super(view)
end

Public Instance Methods

clone_button(resource) click to toggle source
# File lib/para/markup/resources_buttons.rb, line 11
def clone_button(resource)
  return unless resource.class.cloneable? && view.can?(:clone, resource)

  path = component.relation_path(
    resource, action: :clone, return_to: view.request.fullpath
  )

  options = {
    class: 'btn btn-sm btn-icon-info btn-shadow hint--left',
    data: { 'turbo-method': :post, 'turbo-frame': '_top' },
    aria: { label: ::I18n.t('para.shared.copy') }
  }

  view.link_to(path, **options) do
    content_tag(:i, '', class: 'fa fa-copy')
  end
end
delete_button(resource) click to toggle source
# File lib/para/markup/resources_buttons.rb, line 47
def delete_button(resource)
  return unless view.can?(:delete, resource)

  path = component.relation_path(resource, return_to: view.request.fullpath)

  options = {
    class: 'btn btn-sm btn-icon-danger btn-shadow hint--left',
    data: {
      'turbo-method': :delete,
      'turbo-confirm': ::I18n.t('para.list.delete_confirmation')
    },
    aria: {
      label: ::I18n.t('para.shared.destroy')
    }
  }

  view.link_to(path, **options) do
    content_tag(:i, '', class: 'fa fa-times')
  end
end
edit_button(resource) click to toggle source
# File lib/para/markup/resources_buttons.rb, line 29
def edit_button(resource)
  return unless view.can?(:edit, resource)

  path = component.relation_path(
    resource, action: :edit, return_to: view.request.fullpath
  )

  options = {
    class: 'btn btn-sm btn-icon-primary btn-shadow hint--left',
    data: { 'turbo-frame': '_top' },
    aria: { label: ::I18n.t('para.shared.edit') }
  }

  view.link_to(path, **options) do
    content_tag(:i, '', class: 'fa fa-pencil')
  end
end