Module: CrmFormHelper

Included in:
AddressesController, OrdersController, QuotesController
Defined in:
app/helpers/crm_form_helper.rb

Overview

View helper: crm form.

Instance Method Summary collapse

Instance Method Details

#blocking_submit_button(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/crm_form_helper.rb', line 16

def blocking_submit_button(options = {})
  data_hash = { controller: 'ui-blocker', turbo_submits_with: 'Please wait…' }
  data_hash[:turbo_confirm] = options[:confirm] if options[:confirm].present?
  data_hash.merge!(options[:data]) if options[:data].present?
  extra_class = options.delete(:extra_class) || 'mx-2 px-4'
  css_class = "btn btn-#{options[:button_class] || 'success'} #{extra_class}"
  button_tag(type: 'submit',
             name: options[:name] || 'commit',
             value: options[:value] || '1',
             data: data_hash,
             id: options[:id],
             class: css_class) do
    (options[:label] || 'Continue').html_safe
  end
end

#boolean_select(form, field, value, prompt = false, disabled = false) ⇒ Object



4
5
6
# File 'app/helpers/crm_form_helper.rb', line 4

def boolean_select(form, field, value, prompt = false, disabled = false)
  form.select field, options_for_select([["Yes", true], ["No", false]], selected: value), { prompt: prompt }, { disabled: disabled, class: "form-control", style: "max-width:200px" }
end

#datalist(id, values) ⇒ Object



95
96
97
98
99
100
101
# File 'app/helpers/crm_form_helper.rb', line 95

def datalist(id, values)
  (:datalist, id: id) do
    values.each do |n|
      concat tag.option(value: n)
    end
  end
end

#edit_buttonObject



8
9
10
# File 'app/helpers/crm_form_helper.rb', line 8

def edit_button
  fa_icon('pen-to-square', text: 'Edit')
end

#form_style_attribute_display(label, display = nil, options = {}) ⇒ Object

Displays a form line with the label and display value using the same style
as the form builder simple form uses, pass the value as display parameter
of use a block



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/crm_form_helper.rb', line 67

def form_style_attribute_display(label, display = nil, options = {})
   :div, class: 'form-group row' do
    (:label, label, class: 'optional col-sm-3 col-form-label') +
      (:div, class: 'col') do
        display_value = display || (yield if block_given?)
        output = if options[:raw]
                   tag.span display_value
                 elsif options[:multi_line]
                   text_area_tag 'label', display_value, class: 'form-control', disabled: true
                 else
                   text_field_tag 'label', display_value, class: 'form-control', disabled: true
                 end
        output << tag.small(options[:hint], class: 'form-text form-hint text-muted') if options[:hint]
        output.html_safe
      end
  end
end

#opportunity_local_sales_rep_input(form, options = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/crm_form_helper.rb', line 32

def opportunity_local_sales_rep_input(form, options = {})
  form.input :local_sales_rep_id, label: 'Local Sales Rep',
          as: :tom_select,
          collection: Employee.local_sales_rep_options_for_select,
          include_blank: true,
          placeholder: options[:placeholder]
end

#sales_support_rep_input(form, options = {}) ⇒ Object



56
57
58
59
60
61
62
# File 'app/helpers/crm_form_helper.rb', line 56

def sales_support_rep_input(form, options = {})
  form.input :sales_support_rep_id, label: 'Sales Support Rep',
          as: :tom_select,
          collection: Employee.primary_sales_rep_options_for_select,
          include_blank: true,
          placeholder: options[:placeholder]
end

#submit_cancel(options = {}) ⇒ Object



12
13
14
# File 'app/helpers/crm_form_helper.rb', line 12

def submit_cancel(options = {})
  render partial: "/submit_cancel", locals: options
end

#technical_rep_input(form, options = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'app/helpers/crm_form_helper.rb', line 40

def technical_rep_input(form, options = {})
  form.input :technical_support_rep_id, label: 'Technical Rep 1',
          as: :tom_select,
          collection: Employee.technical_support_rep_options_for_select,
          include_blank: true,
          placeholder: options[:placeholder]
end

#technical_rep_sec_input(form, options = {}) ⇒ Object



48
49
50
51
52
53
54
# File 'app/helpers/crm_form_helper.rb', line 48

def technical_rep_sec_input(form, options = {})
  form.input :technical_support_rep_sec_id, label: 'Technical Rep 2',
          as: :tom_select,
          collection: Employee.technical_support_rep_options_for_select,
          include_blank: true,
          placeholder: options[:placeholder]
end

#yes_no_blank_boolean_collection_for_select(blank_name = 'n/a') ⇒ Object



91
92
93
# File 'app/helpers/crm_form_helper.rb', line 91

def yes_no_blank_boolean_collection_for_select(blank_name = 'n/a')
  yes_no_boolean_collection_for_select(blank: blank_name)
end

#yes_no_boolean_collection_for_select(blank: nil) ⇒ Object



85
86
87
88
89
# File 'app/helpers/crm_form_helper.rb', line 85

def yes_no_boolean_collection_for_select(blank: nil)
  r = [['Yes', true], ['No', false]]
  r.insert(0, [blank, '']) if blank
  r
end