Class: Para::Markup::ResourcesButtons

Inherits:
Component
  • Object
show all
Defined in:
lib/para/markup/resources_buttons.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#view

Instance Method Summary collapse

Constructor Details

#initialize(component, view) ⇒ ResourcesButtons

Returns a new instance of ResourcesButtons.



6
7
8
9
# File 'lib/para/markup/resources_buttons.rb', line 6

def initialize(component, view)
  @component = component
  super(view)
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



4
5
6
# File 'lib/para/markup/resources_buttons.rb', line 4

def component
  @component
end

Instance Method Details

#clone_button(resource) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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
    (:i, '', class: 'fa fa-copy')
  end
end

#delete_button(resource) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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
    (:i, '', class: 'fa fa-times')
  end
end

#edit_button(resource) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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
    (:i, '', class: 'fa fa-pencil')
  end
end