Class: Plugins::CamaContactForm::AdminFormsController
- Inherits:
-
CamaleonCms::Apps::PluginsAdminController
- Object
- CamaleonCms::Apps::PluginsAdminController
- Plugins::CamaContactForm::AdminFormsController
- Includes:
- ContactFormControllerConcern, MainHelper
- Defined in:
- app/controllers/plugins/cama_contact_form/admin_forms_controller.rb
Defined Under Namespace
Classes: MarkupScrubber
Instance Method Summary collapse
- #create ⇒ Object
- #del_response ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #item_field ⇒ Object
- #manual ⇒ Object
- #responses ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 57 def create @form = current_site.contact_forms.new(params.require(:plugins_cama_contact_form_cama_contact_form).permit(:name, :slug)) if @form.save flash[:notice] = "#{t('.created', default: 'Created successfully')}" redirect_to action: :edit, id: @form.id else flash[:error] = @form.errors..join(', ') redirect_to action: :index end end |
#del_response ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 82 def del_response response = current_site.contact_forms.find_by_id(params[:response_id]) if response.present? && response.destroy flash[:notice] = "#{t('.actions.msg_deleted', default: 'The response has been deleted')}" end redirect_to action: :responses end |
#destroy ⇒ Object
68 69 70 71 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 68 def destroy flash[:notice] = "#{t('.deleted', default: 'Destroyed successfully')}" if @form.destroy redirect_to action: :index end |
#edit ⇒ Object
16 17 18 19 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 16 def edit I18n.t("plugins.cama_contact_form.edit_view", default: 'Edit contact form') render "edit" end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 7 def index @forms = current_site.contact_forms.where("parent_id is null").all @forms = @forms.paginate(:page => params[:page], :per_page => current_site.admin_per_page) end |
#item_field ⇒ Object
94 95 96 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 94 def item_field render partial: 'item_field', locals:{ field_type: params[:kind], cid: params[:cid] } end |
#manual ⇒ Object
90 91 92 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 90 def manual end |
#responses ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 73 def responses I18n.t("plugins.cama_contact_form.list_responses", default: 'Contact form records') @form = current_site.contact_forms.where({id: params[:admin_form_id]}).first values = JSON.parse(@form.value).to_sym @op_fields = values[:fields].select{ |field| relevant_field? field } @forms = current_site.contact_forms.where({parent_id: @form.id}) @forms = @forms.paginate(:page => params[:page], :per_page => current_site.admin_per_page) end |
#show ⇒ Object
12 13 14 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 12 def show end |
#update ⇒ Object
21 22 23 24 25 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 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 21 def update form_params = params.require(:plugins_cama_contact_form_cama_contact_form).permit(:name, :slug) settings = {"railscf_mail" => params[:railscf_mail], "railscf_message" => , "railscf_form_button" => params[:railscf_form_button], recaptcha_site_key: params[:recaptcha_site_key], recaptcha_secret_key: params[:recaptcha_secret_key]} # The shape of `params` is chosen by the client, not by the form editor, and every check below # indexes into it. Verified first, for everyone, so that nothing downstream -- here or in the # renderer -- has to cope with a String where it expected a Hash. if (malformed = first_malformed_shape_key(settings)) return reject_save(t('.malformed_structure', field: malformed, default: 'A field has a malformed %{field}. Nothing was saved.')) end fields = submitted_fields # Checked before the record is touched, so a rejected save leaves the form exactly as it was # rather than persisting the name and slug and dropping everything else. if (malformed = first_malformed_structural_key(fields)) return reject_save(t('.malformed_structure', field: malformed, default: 'A field has a malformed %{field}. Nothing was saved.')) end unless trusted_for_unfiltered_html? if (rejected = first_unpermitted_html_key(settings, fields)) return reject_save((*rejected)) end end if @form.update(form_params) @form.update({settings: settings.to_json, value: {fields: fields}.to_json}) flash[:notice] = t('.updated_success', default: 'Updated successfully') redirect_to action: :edit, id: @form.id else edit end end |