Module: CMS::FormHelper

Defined in:
app/helpers/cms/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#cms_form_for(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/cms/form_helper.rb', line 3

def cms_form_for(options = {})
  simple_form_for(cms_form_instance, cms_form_options(options)) do |f|
    concat f.invisible_captcha(:_subtitle)
    yield f
    if @cms_view
      concat f.input(:structure_id, as: :hidden, input_html: { value: cms_form_instance.structure_id })
    end
  end
end

#cms_form_options(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/cms/form_helper.rb', line 13

def cms_form_options(options = {})
  if @cms_view
    url = @cms_view.url
  else
    url = main_app.__send__("#{cms_form_instance.form_name}_path")
  end
  options.reverse_merge! url: url
  if cms_form_instance.has_attachments?
    options[:multipart] = true
  else
    options[:remote] = true
  end
  options
end

#cms_form_partialObject



28
29
30
# File 'app/helpers/cms/form_helper.rb', line 28

def cms_form_partial
  "cms/forms/#{params[:cms_view_type]}/form"
end

#cms_form_sendObject



62
63
64
# File 'app/helpers/cms/form_helper.rb', line 62

def cms_form_send
  t('cms.form.submit.send')
end

#cms_form_sending(options = {}) ⇒ Object



66
67
68
# File 'app/helpers/cms/form_helper.rb', line 66

def cms_form_sending(options = {})
  { 'data-disable-with' => t('cms.form.submit.sending') }.merge(options)
end

#cms_validate_check_boxes(options = {}) ⇒ Object



58
59
60
# File 'app/helpers/cms/form_helper.rb', line 58

def cms_validate_check_boxes(options = {})
  { 'data-validation' => 'checkbox_group', 'data-validation-qty' => 'min1', 'data-validation-error-msg' => t('errors.messages.blank') }.merge(options)
end

#cms_validate_email(options = {}) ⇒ Object



54
55
56
# File 'app/helpers/cms/form_helper.rb', line 54

def cms_validate_email(options = {})
  { 'data-validation' => 'email', 'data-validation-error-msg' => t('errors.messages.invalid') }.merge(options)
end

#cms_validate_presence(options = {}) ⇒ Object



50
51
52
# File 'app/helpers/cms/form_helper.rb', line 50

def cms_validate_presence(options = {})
  { 'data-validation' => 'required', 'data-validation-error-msg' => t('errors.messages.blank') }.merge(options)
end

#cms_validates(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/cms/form_helper.rb', line 32

def cms_validates(options = {})
  type, required = options.extract!(*Form::Field::TYPES.map(&:to_sym)).first
  unless type
    return cms_validate_presence(options)
  end
  unless required
    return options
  end
  case type
  when :check_boxes
    cms_validate_check_boxes(options)
  when :email
    cms_validate_email(options)
  else
    cms_validate_presence(options)
  end
end