Class: Plugins::ContactForm::AdminFormsController

Inherits:
CamaleonCms::Apps::PluginsAdminController
  • Object
show all
Defined in:
app/apps/plugins/contact_form/admin_forms_controller.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 39

def create

  params[:plugins_contact_form_models_contact_form][:value] = {"fields" => []}.to_json
  params[:plugins_contact_form_models_contact_form][:settings] = {}.to_json

  data_form = params[:plugins_contact_form_models_contact_form]
  @form = current_site.contact_forms.new(data_form)

  if @form.save
    flash[:notice] = "#{t('plugin.contact_form.message.save')}"
    redirect_to action: :edit, id: @form.id
  else
    flash[:error] = @form.errors.full_messages.join(', ')
    redirect_to action: :index
  end
end

#destroyObject



56
57
58
59
60
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 56

def destroy
  flash[:notice] = "#{t('plugin.contact_form.message.delete')}" if @form.destroy

  redirect_to action: :index
end

#editObject



19
20
21
22
23
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 19

def edit
  add_breadcrumb I18n.t("camaleon_cms.admin.button.edit")
  append_asset_libraries({"plugin_contact_form"=> { js: [plugin_asset_path("js/contact_form.js")], css: [plugin_asset_path("css/contact-form.css")] }})
  render "edit"
end

#indexObject



13
14
15
16
17
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 13

def index
  # here your actions for admin panel
  @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

#manualObject



71
72
73
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 71

def manual

end

#responsesObject



62
63
64
65
66
67
68
69
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 62

def responses
  @form = current_site.contact_forms.where({id: params[:admin_form_id]}).first
  values = JSON.parse(@form.value).to_sym

  @op_fields = values[:fields]
  @forms = current_site.contact_forms.where({parent_id: @form.id})
  @forms = @forms.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/apps/plugins/contact_form/admin_forms_controller.rb', line 25

def update
  if @form.update(params[:plugins_contact_form_models_contact_form])

    settings = {"railscf_mail" => params[:railscf_mail], "railscf_message" => params[:railscf_message], "railscf_form_button" => params[:railscf_form_button]}.to_json
    current_site.contact_forms.where(id: @form.id).update_or_create({settings: fix_meta_value(settings)})
    current_site.contact_forms.where(id: @form.id).update_or_create({value: params[:meta]})

    flash[:notice] = t('camaleon_cms.admin.message.updated_success')
    redirect_to action: :edit, id: @form.id
  else
    edit
  end
end