Module: CrmFormHelper
- Included in:
- AddressesController, OrdersController, QuotesController
- Defined in:
- app/helpers/crm_form_helper.rb
Overview
View helper for CRM forms.
Instance Method Summary collapse
-
#blocking_submit_button(options = {}) ⇒ String
Renders a submit button that blocks the UI while the form submits.
-
#boolean_select(form, field, value, prompt = false, disabled = false) ⇒ String
Renders a Yes/No dropdown for a boolean attribute.
-
#datalist(id, values) ⇒ String
Renders an HTML datalist element.
-
#edit_button ⇒ String
Renders the standard edit icon button.
-
#form_style_attribute_display(label, display = nil, options = {}) { ... } ⇒ String
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.
-
#opportunity_local_sales_rep_input(form, options = {}) ⇒ String
Renders the local sales rep select input for an opportunity form.
-
#sales_support_rep_input(form, options = {}) ⇒ String
Renders the sales support rep select input.
-
#submit_cancel(options = {}) ⇒ String
Renders the shared submit/cancel button bar partial.
-
#technical_rep_input(form, options = {}) ⇒ String
Renders the primary technical rep select input.
-
#technical_rep_sec_input(form, options = {}) ⇒ String
Renders the secondary technical rep select input.
-
#yes_no_blank_boolean_collection_for_select(blank_name = 'n/a') ⇒ Array<Array(String, Boolean)>
Builds a Yes/No collection with a configurable blank label.
-
#yes_no_boolean_collection_for_select(blank: nil) ⇒ Array<Array(String, Boolean)>
Builds a Yes/No collection for select inputs.
Instance Method Details
#blocking_submit_button(options = {}) ⇒ String
Renders a submit button that blocks the UI while the form submits.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/crm_form_helper.rb', line 49 def ( = {}) data_hash = { controller: 'ui-blocker', turbo_submits_with: 'Please wait…' } data_hash[:turbo_confirm] = [:confirm] if [:confirm].present? data_hash.merge!([:data]) if [:data].present? extra_class = .delete(:extra_class) || 'mx-2 px-4' css_class = "btn btn-#{[:button_class] || 'success'} #{extra_class}" (type: 'submit', name: [:name] || 'commit', value: [:value] || '1', data: data_hash, id: [:id], class: css_class) do ([:label] || 'Continue').html_safe end end |
#boolean_select(form, field, value, prompt = false, disabled = false) ⇒ String
Renders a Yes/No dropdown for a boolean attribute.
12 13 14 |
# File 'app/helpers/crm_form_helper.rb', line 12 def boolean_select(form, field, value, prompt = false, disabled = false) form.select field, ([["Yes", true], ["No", false]], selected: value), { prompt: prompt }, { disabled: disabled, class: "form-control", style: "max-width:200px" } end |
#datalist(id, values) ⇒ String
Renders an HTML datalist element.
166 167 168 169 170 171 172 |
# File 'app/helpers/crm_form_helper.rb', line 166 def datalist(id, values) content_tag(:datalist, id: id) do values.each do |n| concat tag.option(value: n) end end end |
#edit_button ⇒ String
Renders the standard edit icon button.
18 19 20 |
# File 'app/helpers/crm_form_helper.rb', line 18 def fa_icon('pen-to-square', text: 'Edit') end |
#form_style_attribute_display(label, display = nil, options = {}) { ... } ⇒ String
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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/helpers/crm_form_helper.rb', line 128 def form_style_attribute_display(label, display = nil, = {}) content_tag :div, class: 'form-group row' do content_tag(:label, label, class: 'optional col-sm-3 col-form-label') + content_tag(:div, class: 'col') do display_value = display || (yield if block_given?) output = if [:raw] tag.span display_value elsif [: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([:hint], class: 'form-text form-hint text-body-secondary') if [:hint] output.html_safe end end end |
#opportunity_local_sales_rep_input(form, options = {}) ⇒ String
Renders the local sales rep select input for an opportunity form.
70 71 72 73 74 75 76 |
# File 'app/helpers/crm_form_helper.rb', line 70 def opportunity_local_sales_rep_input(form, = {}) form.input :local_sales_rep_id, label: 'Local Sales Rep', as: :tom_select, collection: Employee., include_blank: true, placeholder: [:placeholder] end |
#sales_support_rep_input(form, options = {}) ⇒ String
Renders the sales support rep select input.
109 110 111 112 113 114 115 |
# File 'app/helpers/crm_form_helper.rb', line 109 def sales_support_rep_input(form, = {}) form.input :sales_support_rep_id, label: 'Sales Support Rep', as: :tom_select, collection: Employee., include_blank: true, placeholder: [:placeholder] end |
#submit_cancel(options = {}) ⇒ String
Renders the shared submit/cancel button bar partial.
34 35 36 |
# File 'app/helpers/crm_form_helper.rb', line 34 def submit_cancel( = {}) render partial: "/submit_cancel", locals: end |
#technical_rep_input(form, options = {}) ⇒ String
Renders the primary technical rep select input.
83 84 85 86 87 88 89 |
# File 'app/helpers/crm_form_helper.rb', line 83 def technical_rep_input(form, = {}) form.input :technical_support_rep_id, label: 'Technical Rep 1', as: :tom_select, collection: Employee., include_blank: true, placeholder: [:placeholder] end |
#technical_rep_sec_input(form, options = {}) ⇒ String
Renders the secondary technical rep select input.
96 97 98 99 100 101 102 |
# File 'app/helpers/crm_form_helper.rb', line 96 def technical_rep_sec_input(form, = {}) form.input :technical_support_rep_sec_id, label: 'Technical Rep 2', as: :tom_select, collection: Employee., include_blank: true, placeholder: [:placeholder] end |
#yes_no_blank_boolean_collection_for_select(blank_name = 'n/a') ⇒ Array<Array(String, Boolean)>
Builds a Yes/No collection with a configurable blank label.
158 159 160 |
# File 'app/helpers/crm_form_helper.rb', line 158 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) ⇒ Array<Array(String, Boolean)>
Builds a Yes/No collection for select inputs.
149 150 151 152 153 |
# File 'app/helpers/crm_form_helper.rb', line 149 def yes_no_boolean_collection_for_select(blank: nil) r = [['Yes', true], ['No', false]] r.insert(0, [blank, '']) if blank r end |