Class: SalesRepPickerTomSelectInput

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

Overview

Tom Select input for sales rep pickers
Use as: :sales_rep_picker_tom_select
Pass role: :primary, :secondary, or :local to filter by rep type

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input, #input_html_classes

Instance Method Details

#collectionObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/inputs/sales_rep_picker_tom_select_input.rb', line 5

def collection
  role = options[:role] || :sales_rep

  reps = case role.to_sym
         when :primary   then Employee.primary_sales_rep_options_for_select
         when :secondary then Employee.secondary_sales_rep_options_for_select
         when :local     then Employee.local_sales_rep_options_for_select
         else Employee.sales_rep_options_for_select
         end

  if (excluded_ids = options[:exclude])
    reps = reps.reject { |_name, id| id.in?(excluded_ids) }
  end

  options[:collection] = reps
  super
end