Class: Effective::FormBuilderInputs::EffectiveTel

Inherits:
Effective::FormBuilderInput show all
Defined in:
app/models/effective/form_builder_inputs/effective_tel.rb

Constant Summary collapse

DEFAULT_TEL_MASK =
'(999) 999-9999? x99999'
DEFAULT_CELL_MASK =
'(999) 999-9999'

Instance Method Summary collapse

Methods inherited from Effective::FormBuilderInput

#field_name, #html_options, #initialize, #options, #value

Constructor Details

This class inherits a constructor from Effective::FormBuilderInput

Instance Method Details

#cellphone?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 38

def cellphone?
  field_name.include?('cell') || options[:cellphone]
end

#default_input_htmlObject



13
14
15
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 13

def default_input_html
  {class: 'effective_tel tel', placeholder: '(555) 555-5555'}
end

#default_input_jsObject



17
18
19
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 17

def default_input_js
  {mask: DEFAULT_TEL_MASK, placeholder: '_'}
end

#default_optionsObject



9
10
11
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 9

def default_options
  {cellphone: false, fax: false}
end

#fax?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 34

def fax?
  field_name.include?('fax') || options[:fax]
end

#glyphiconObject



42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 42

def glyphicon
  icon = 'earphone' # default

  icon = 'phone' if field_name.include?('cell')
  icon = 'phone-alt' if field_name.include?('fax')

  icon = 'phone' if options[:cellphone]
  icon = 'phone-alt' if options[:fax]

  icon
end

#js_optionsObject



54
55
56
57
58
59
60
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 54

def js_options
  super.tap do |js_options|
    if (fax? || cellphone?) && js_options[:mask] == DEFAULT_TEL_MASK
      js_options[:mask] = DEFAULT_CELL_MASK
    end
  end
end

#to_htmlObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/effective/form_builder_inputs/effective_tel.rb', line 21

def to_html
  if options[:input_group] == false
    return telephone_field_tag(field_name, value, tag_options)
  end

  (:div, class: 'input-group') do
    (:span, class: 'input-group-addon') do
      (:i, '', class: "glyphicon glyphicon-#{glyphicon}").html_safe
    end +
    telephone_field_tag(field_name, value, tag_options)
  end
end