Module: CrmFormHelper

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

Instance Method Summary collapse

Instance Method Details

#blocking_submit_button(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/crm_form_helper.rb', line 15

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

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



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

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



106
107
108
109
110
111
112
# File 'app/helpers/crm_form_helper.rb', line 106

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

#edit_buttonObject



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

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/crm_form_helper.rb', line 76

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
      if options[:hint]
        output << tag.small(options[:hint], class: 'form-text form-hint text-muted')
      end
      output.html_safe
    end
  end
end

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



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

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



65
66
67
68
69
70
71
# File 'app/helpers/crm_form_helper.rb', line 65

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



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

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

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



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

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



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

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



102
103
104
# File 'app/helpers/crm_form_helper.rb', line 102

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



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

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