Class: StoreItemPickerInput
- Inherits:
-
TomSelectInput
- Object
- SimpleForm::Inputs::CollectionSelectInput
- TomSelectInput
- StoreItemPickerInput
- Defined in:
- app/inputs/store_item_picker_input.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #company_id ⇒ Object
- #default_term ⇒ Object
- #exclude_catalog_id ⇒ Object
- #input(wrapper_options = nil) ⇒ Object
- #lookup_url ⇒ Object
- #return_id ⇒ Object
- #store_id ⇒ Object
Methods inherited from TomSelectInput
Instance Method Details
#collection ⇒ Object
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_id ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/inputs/store_item_picker_input.rb', line 11 def company_id cid = .dig(:query, :company_id) if object.is_a?(CatalogItem) cid ||= object.catalog.company_id end cid ||= 1 end |
#default_term ⇒ Object
36 37 38 |
# File 'app/inputs/store_item_picker_input.rb', line 36 def default_term .dig(:query, :default_term) end |
#exclude_catalog_id ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/inputs/store_item_picker_input.rb', line 19 def exclude_catalog_id ecid = .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( = nil) [:data] ||= {} [:data]['tom-select-suggest-url-value'] = lookup_url min_chars = default_term.present? ? 0 : 2 [:data]['tom-select-min-chars-value'] = min_chars [:include_blank] = true unless [:multiple] super() end |
#lookup_url ⇒ Object
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_id ⇒ Object
27 28 29 30 |
# File 'app/inputs/store_item_picker_input.rb', line 27 def return_id rid = .dig(:query, :return_id) rid ||= 'id' end |
#store_id ⇒ Object
32 33 34 |
# File 'app/inputs/store_item_picker_input.rb', line 32 def store_id .dig(:query, :store_id) end |