Module: ProductSpecificationsHelper

Defined in:
app/helpers/product_specifications_helper.rb

Instance Method Summary collapse

Instance Method Details

#product_specification_command_options(product_specification = nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/product_specifications_helper.rb', line 2

def product_specification_command_options(product_specification = nil)
  product_specification ||= @product_specification
  return unless product_specification

  opts = []

  if can?(:update, @product_specification)
    opts << link_to(fa_icon('pencil', text: 'Edit'), edit_product_specification_path(@product_specification))
    opts << link_to(fa_icon('clone', text: 'Clone spec'),
                    clone_product_specification_path(@product_specification.id,
                                                     product_specification: {}),
                    data: { turbo_method: :post })
    opts << link_to(fa_icon('arrow-rotate-right', text: 'Refresh Specs'), refresh_specs_product_specification_path(@product_specification, return_path: product_specification_path(@product_specification)), data: { turbo_method: :post })
    opts << link_to('Auto Translate', auto_translate_product_specification_path(@product_specification, return_path: product_specification_path(@product_specification)), data: { turbo_method: :post })
    opts << link_to('Auto Translate with Reset', auto_translate_product_specification_path(@product_specification, reset_previous_values: true, return_path: product_specification_path(@product_specification)), data: { turbo_method: :post })
  end
  if can?(:destroy, @product_specification)
    opts << link_to(fa_icon('trash', text: 'Delete'), product_specification_path(@product_specification),
                    data: { turbo_confirm: 'Are you sure you wish to delete this Product Specification?', turbo_method: :delete })
  end
  opts
end

#product_specification_item_group_command_options(label, item, url_defaults, grouping = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/product_specifications_helper.rb', line 25

def product_specification_item_group_command_options(label, item, url_defaults, grouping = nil)
  opts = [label.html_safe]
  opts << link_to("For #{item.sku} Only", url_defaults.new_product_specification_path(product_specification: { grouping:, item_ids: [item.id] }))
  if item.primary_product_line
    opts << link_to("For #{item.primary_product_line.name} / #{item.product_category.name}",
                    url_defaults.new_product_specification_path(product_specification: { grouping:, product_line_id: item.primary_product_line.id, product_category_id: item.product_category_id }))
  end
  if (pppl = item.primary_product_line&.parent)
    opts << link_to("For #{pppl.name} / #{item.product_category.name}",
                    url_defaults.new_product_specification_path(product_specification: { grouping:, product_line_id: pppl.id, product_category_id: item.product_category_id }))
  end
  if item.primary_product_line
    opts << link_to("For #{item.primary_product_line.name} / #{item.product_category.name} as Template",
                    url_defaults.new_product_specification_path(product_specification: { grouping:, product_line_id: item.primary_product_line.id, product_category_id: item.product_category_id, template: true }))
  end
  opts.compact
end