Class: StoreItemPickerInput
- Inherits:
-
TomSelectInput
- Object
- SimpleForm::Inputs::CollectionSelectInput
- TomSelectInput
- StoreItemPickerInput
- Defined in:
- app/inputs/store_item_picker_input.rb
Overview
SimpleForm input wrapper: store item picker.
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
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_id ⇒ Object
13 14 15 16 17 |
# File 'app/inputs/store_item_picker_input.rb', line 13 def company_id cid = .dig(:query, :company_id) cid ||= object.catalog.company_id if object.is_a?(CatalogItem) cid || 1 end |
#default_term ⇒ Object
34 35 36 |
# File 'app/inputs/store_item_picker_input.rb', line 34 def default_term .dig(:query, :default_term) end |
#exclude_catalog_id ⇒ Object
19 20 21 22 23 |
# File 'app/inputs/store_item_picker_input.rb', line 19 def exclude_catalog_id ecid = .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( = 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
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_id ⇒ Object
25 26 27 28 |
# File 'app/inputs/store_item_picker_input.rb', line 25 def return_id rid = .dig(:query, :return_id) rid || 'id' end |
#store_id ⇒ Object
30 31 32 |
# File 'app/inputs/store_item_picker_input.rb', line 30 def store_id .dig(:query, :store_id) end |