Module: Presenters::StandardOperationsForRecord

Extended by:
ActiveSupport::Concern
Included in:
CatalogItemPresenter, CatalogPresenter, DeliveryPresenter, ExportedCatalogItemPacketPresenter, OrderPresenter
Defined in:
app/concerns/presenters/standard_operations_for_record.rb

Instance Method Summary collapse

Instance Method Details

#audit_buttonObject



50
51
52
53
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 50

def audit_button
  return unless r.present?
  h.audit_button(r)
end

#created_atObject



40
41
42
43
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 40

def created_at
  return unless r.created_at rescue false
  h.render_date(r.created_at)
end

#destroy_record_button(record, options = {}) ⇒ Object

Renders a destroy button for a record assuming standard rails routing
practices and bootstrap styles



8
9
10
11
12
13
14
15
16
17
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 8

def destroy_record_button(record,options={})
  return unless h.can?(:destroy, record)
  options.reverse_merge!({
    class: 'btn btn-danger',
    data: {
      turbo_confirm: "This will delete the #{record.class.name.humanize}, are you sure?"
    }
  })
  destroy_record_link record, options
end


19
20
21
22
23
24
25
26
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 19

def destroy_record_link(record, options={})
  options = options.dup
  data = (options[:data] || {}).dup
  data[:turbo_method] ||= :delete
  data[:turbo_confirm] ||= data.delete(:confirm) if data[:confirm]
  options[:data] = data
  h.link_to 'Delete', h.polymorphic_path(record), **options
end

#edit_record_button(record, options = {}) ⇒ Object

Renders an edit button for a record assuming standard rails routing
practices and bootstrap styles



30
31
32
33
34
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 30

def edit_record_button(record, options={})
  return unless h.can?(:update, record)
  options[:class] ||= 'btn btn-outline-primary'
  edit_record_link record, options
end


36
37
38
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 36

def edit_record_link(record, options={})
  h.link_to 'Edit', h.polymorphic_path(record, action: :edit), **options
end

#updated_atObject



45
46
47
48
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 45

def updated_at
  return unless r.updated_at rescue false
  h.render_date(r.updated_at)
end