Class: StoreItemPickerInput

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

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input_html_classes

Instance Method Details

#collectionObject



50
51
52
# File 'app/inputs/store_item_picker_input.rb', line 50

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

#company_idObject



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

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

#default_termObject



36
37
38
# File 'app/inputs/store_item_picker_input.rb', line 36

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

#exclude_catalog_idObject



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

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

#input(wrapper_options = nil) ⇒ Object



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

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(wrapper_options)
end

#lookup_urlObject



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

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



27
28
29
30
# File 'app/inputs/store_item_picker_input.rb', line 27

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

#store_idObject



32
33
34
# File 'app/inputs/store_item_picker_input.rb', line 32

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