Module: Hancock::Feedback::Controllers::Contacts

Extended by:
ActiveSupport::Concern
Included in:
Hancock::Feedback::ContactsController
Defined in:
lib/hancock/feedback/controllers/contacts.rb

Instance Method Summary collapse

Instance Method Details

#cache_fields?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/hancock/feedback/controllers/contacts.rb', line 75

def cache_fields?
  ['new', 'index'].include? action_name
end

#cache_keyObject



78
79
80
# File 'lib/hancock/feedback/controllers/contacts.rb', line 78

def cache_key
  'hancock_feedback_contacts_fields'.freeze
end

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hancock/feedback/controllers/contacts.rb', line 26

def create
  @contact_message = model.new(message_params)
  after_initialize

  if Hancock::Feedback.config.captcha
    if Hancock::Feedback.config.recaptcha_support
      if verify_recaptcha
        meth = :save
      else
        meth = :valid?
        @recaptcha_error = I18n.t('hancock.errors.feedback.recaptcha')
      end

    elsif Hancock::Feedback.config.simple_captcha_support
      meth = :save_with_captcha

    else
      meth = :save
    end
  else
    meth = :save
  end

  if @contact_message.send(meth) and @recaptcha_error.blank?
    after_create
    if request.xhr? && process_ajax
      ajax_success
    else
      redirect_after_done
    end
  else
    render_contacts_error
  end
end

#fields_partialObject



81
82
83
# File 'lib/hancock/feedback/controllers/contacts.rb', line 81

def fields_partial
  "hancock/feedback/contacts/#{(Hancock::Feedback.config.model_settings_support ? 'fields_with_settings' : 'fields')}".freeze
end

#hancock_feedback_update_captcha_pathObject



69
70
71
# File 'lib/hancock/feedback/controllers/contacts.rb', line 69

def hancock_feedback_update_captcha_path
  url_for(action: :update_captcha, time: Time.new.to_i, only_path: true)
end

#indexObject



14
15
16
17
18
# File 'lib/hancock/feedback/controllers/contacts.rb', line 14

def index
  @contact_message = model.new
  after_initialize
  render locals: locals unless xhr_checker
end

#is_cache_fieldsObject



72
73
74
# File 'lib/hancock/feedback/controllers/contacts.rb', line 72

def is_cache_fields
  cache_fields?
end

#localsObject



96
97
98
99
100
101
102
103
104
# File 'lib/hancock/feedback/controllers/contacts.rb', line 96

def locals
  {
    is_cache_fields:    is_cache_fields,
    cache_key:          cache_key,
    fields_partial:     fields_partial,
    settings_scope:     settings_scope,
    recaptcha_options:  recaptcha_options
  }
end

#newObject



20
21
22
23
24
# File 'lib/hancock/feedback/controllers/contacts.rb', line 20

def new
  @contact_message = model.new
  after_initialize
  render locals: locals unless xhr_checker
end

#recaptcha_optionsObject



93
94
95
# File 'lib/hancock/feedback/controllers/contacts.rb', line 93

def recaptcha_options
  {}
end

#sentObject



61
62
# File 'lib/hancock/feedback/controllers/contacts.rb', line 61

def sent
end

#settings_scopeObject



84
85
86
87
88
89
90
91
92
# File 'lib/hancock/feedback/controllers/contacts.rb', line 84

def settings_scope
  if Hancock::Feedback.config.model_settings_support
    model.settings
  elsif defined?(Settings)
    Settings.ns('feedback')
  else
    nil
  end
end

#update_captchaObject



64
65
66
# File 'lib/hancock/feedback/controllers/contacts.rb', line 64

def update_captcha
  render layout: false
end