Class: SalesRepPickerInput

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

Overview

SimpleForm input: sales rep picker. Use as: :sales_rep_picker.
Pass role: :primary, :secondary, or :local to scope to a rep type;
omit role: for the union of all sales reps.

Instance Method Summary collapse

Methods inherited from TomSelectInput

#input, #input_html_classes

Instance Method Details

#collectionObject



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

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