Class: Plugins::CamaContactForm::CamaContactForm
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Plugins::CamaContactForm::CamaContactForm
- Includes:
- MainHelper
- Defined in:
- app/models/plugins/cama_contact_form/cama_contact_form.rb
Overview
A contact form and, through parent_id, its stored response rows, scoped to a site.
Class Method Summary collapse
Instance Method Summary collapse
-
#fields ⇒ Object
Example of the stored
valueJSON, kept on one line for copy-paste: rubocop:disable Layout/LineLength ["label":"Untitled","field_type":"text","required":true,"field_options":{"size":"large","field_class":"Default","cid":"c2"},"label":"Untitled","field_type":"paragraph","required":true,"field_options":{"size":"large","field_class":"Default","cid":"c6"},"label":"Untitled","field_type":"captcha","required":true,"field_options":{"field_class":"Default","cid":"c10"},"label":"Untitled","field_type":"checkboxes","required":true,"field_options":{"options":[{"label":"Default","checked":false,"label":"Default","checked":false],"field_class":"Default","description":"description\n"},"cid":"c12"}] rubocop:enable Layout/LineLength. - #form_button_settings ⇒ Object
-
#mail_settings ⇒ Object
The three settings containers, always readable.
- #message_settings ⇒ Object
-
#recaptcha_enabled? ⇒ Boolean
verify if recaptcha was enabled for this form this method can be overwritten if recaptcha was already defined on initializers to return true as default.
-
#set_captcha_settings! ⇒ Object
define recaptcha settings.
- #the_message(key, default) ⇒ Object
- #the_settings ⇒ Object
Class Method Details
.field_template ⇒ Object
60 61 62 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 60 def self.field_template "<div class='form-group'>\n\t <label>[label ci]</label>\n\t<p>[descr ci]</p>\n\t<div>[ci]</div> \n</div>" end |
Instance Method Details
#fields ⇒ Object
Example of the stored value JSON, kept on one line for copy-paste:
rubocop:disable Layout/LineLength
["label":"Untitled","field_type":"text","required":true,"field_options":{"size":"large","field_class":"Default","cid":"c2"},"label":"Untitled","field_type":"paragraph","required":true,"field_options":{"size":"large","field_class":"Default","cid":"c6"},"label":"Untitled","field_type":"captcha","required":true,"field_options":{"field_class":"Default","cid":"c10"},"label":"Untitled","field_type":"checkboxes","required":true,"field_options":{"options":[{"label":"Default","checked":false,"label":"Default","checked":false],"field_class":"Default","description":"description\n"},"cid":"c12"}]
rubocop:enable Layout/LineLength
30 31 32 33 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 30 def fields @_the_fields ||= JSON.parse(value || '{"fields": []}').with_indifferent_access Array(@_the_fields[:fields]) end |
#form_button_settings ⇒ Object
47 48 49 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 47 def settings_hash(:railscf_form_button) end |
#mail_settings ⇒ Object
The three settings containers, always readable. A form that has never been saved carries
settings of {}, and a partial update can leave any of them unset -- so every caller in the
admin views guards its read with rescue '', while the ones that do not (the public shortcode,
the mailer) raised NoMethodError on every request until someone edited the database by hand.
43 44 45 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 43 def mail_settings settings_hash(:railscf_mail) end |
#message_settings ⇒ Object
51 52 53 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 51 def settings_hash(:railscf_message) end |
#recaptcha_enabled? ⇒ Boolean
verify if recaptcha was enabled for this form this method can be overwritten if recaptcha was already defined on initializers to return true as default
76 77 78 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 76 def recaptcha_enabled? the_settings[:recaptcha_site_key].present? end |
#set_captcha_settings! ⇒ Object
define recaptcha settings
65 66 67 68 69 70 71 72 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 65 def set_captcha_settings! return unless recaptcha_enabled? Recaptcha.configure do |config| config.site_key = the_settings[:recaptcha_site_key] config.secret_key = the_settings[:recaptcha_secret_key] end end |
#the_message(key, default) ⇒ Object
55 56 57 58 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 55 def (key, default) r = [key].to_s.translate r.presence || default end |
#the_settings ⇒ Object
35 36 37 |
# File 'app/models/plugins/cama_contact_form/cama_contact_form.rb', line 35 def the_settings @the_settings ||= JSON.parse(settings || '{}').with_indifferent_access end |