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
Instance Method Summary collapse
- #create ⇒ Object
- #del_response ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #item_field ⇒ Object
- #manual ⇒ Object
- #responses ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 33 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
58 59 60 61 62 63 64 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 58 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
44 45 46 47 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 44 def destroy flash[:notice] = "#{t('.deleted', default: 'Destroyed successfully')}" if @form.destroy redirect_to action: :index end |
#edit ⇒ Object
12 13 14 15 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 12 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
70 71 72 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 70 def item_field render partial: 'item_field', locals:{ field_type: params[:kind], cid: params[:cid] } end |
#manual ⇒ Object
66 67 68 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 66 def manual end |
#responses ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 49 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 |
#update ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/plugins/cama_contact_form/admin_forms_controller.rb', line 17 def update if @form.update(params.require(:plugins_cama_contact_form_cama_contact_form).permit(:name, :slug)) settings = {"railscf_mail" => params[:railscf_mail], "railscf_message" => params[:railscf_message], "railscf_form_button" => params[:railscf_form_button], recaptcha_site_key: params[:recaptcha_site_key], recaptcha_secret_key: params[:recaptcha_secret_key]} fields = [] (params[:fields] || {}).each{|k, v| v[:field_options][:options] = v[:field_options][:options].values if v[:field_options][:options].present? fields << v } @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 |