Class: StoreItemPickerInput

Inherits:
TomSelectInput
  • Object
show all
Defined in:
app/inputs/store_item_picker_input.rb

Overview

SimpleForm input wrapper: store item picker.

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input_html_classes

Instance Method Details

#collectionObject



48
49
50
# File 'app/inputs/store_item_picker_input.rb', line 48

def collection
  StoreItem.where(id: selected_value).map { |si| [si.selection_name, si.id] }
end

#company_idObject



13
14
15
16
17
# File 'app/inputs/store_item_picker_input.rb', line 13

def company_id
  cid = input_html_options.dig(:query, :company_id)
  cid ||= object.catalog.company_id if object.is_a?(CatalogItem)
  cid || 1
end

#default_termObject



34
35
36
# File 'app/inputs/store_item_picker_input.rb', line 34

def default_term
  input_html_options.dig(:query, :default_term)
end

#exclude_catalog_idObject



19
20
21
22
23
# File 'app/inputs/store_item_picker_input.rb', line 19

def exclude_catalog_id
  ecid = input_html_options.dig(:query, :exclude_catalog_id)
  ecid ||= object.catalog_id if object.respond_to?(:catalog_id)
  ecid
end

#input(wrapper_options = nil) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/inputs/store_item_picker_input.rb', line 4

def input(wrapper_options = nil)
  input_html_options[:data] ||= {}
  input_html_options[:data]['tom-select-suggest-url-value'] = lookup_url
  min_chars = default_term.present? ? 0 : 2
  input_html_options[:data]['tom-select-min-chars-value'] = min_chars
  input_html_options[:include_blank] = true unless input_html_options[:multiple]
  super
end

#lookup_urlObject



38
39
40
41
42
43
44
45
46
# File 'app/inputs/store_item_picker_input.rb', line 38

def lookup_url
  template.lookup_store_items_path(
    company_id: company_id,
    exclude_catalog_id: exclude_catalog_id,
    return_id: return_id,
    store_id: store_id,
    default_term: default_term
  )
end

#return_idObject



25
26
27
28
# File 'app/inputs/store_item_picker_input.rb', line 25

def return_id
  rid = input_html_options.dig(:query, :return_id)
  rid || 'id'
end

#store_idObject



30
31
32
# File 'app/inputs/store_item_picker_input.rb', line 30

def store_id
  input_html_options.dig(:query, :store_id)
end