Class: CamaleonCms::Admin::Settings::CustomFieldsController

Inherits:
CamaleonCms::Admin::SettingsController
  • Object
show all
Includes:
CustomFieldsHelper
Defined in:
app/controllers/camaleon_cms/admin/settings/custom_fields_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

create a new custom field group


53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 53

def create
  @field_group = current_site.custom_field_groups.new(@post_data)
  if @field_group.save
    @field_group.add_fields(params[:fields], params[:field_options])
    @field_group.set_option('caption', @post_data[:caption])
    flash[:notice] = t('camaleon_cms.admin.custom_field.message.custom_created')
    redirect_to action: :edit, id: @field_group.id
  else
    new
  end
end

#destroyObject

destroy a custom field group


66
67
68
69
70
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 66

def destroy
  @field_group.destroy
  flash[:notice] = t('camaleon_cms.admin.custom_field.message.deleted', default: "Custom Field Group Deleted.")
  redirect_to action: :index
end

#editObject


30
31
32
33
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 30

def edit
  add_breadcrumb I18n.t("camaleon_cms.admin.button.edit")
  render 'form'
end

#get_itemsObject


22
23
24
25
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 22

def get_items
  @key = params[:key]
  render partial: "get_items", layout: false
end

#indexObject


15
16
17
18
19
20
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 15

def index
  @field_groups = current_site.custom_field_groups.visible_group.eager_load(:site)
  @field_groups = @field_groups.where(object_class: params[:c]) if params[:c].present?
  @field_groups = @field_groups.where(objectid: params[:id]) if params[:id].present?
  @field_groups = @field_groups.paginate(page: params[:page], per_page: current_site.admin_per_page)
end

#newObject


46
47
48
49
50
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 46

def new
  add_breadcrumb I18n.t("camaleon_cms.admin.button.new")
  @field_group ||= current_site.custom_field_groups.new
  render 'form'
end

#reorderObject

reorder custom fields group


73
74
75
76
77
78
79
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 73

def reorder
  params[:values].to_a.each_with_index do |value, index|
    current_site.custom_field_groups.find(value).update_column('field_order', index)
  end
  json = { size: params[:values].size }
  render json: json
end

#showObject


27
28
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 27

def show
end

#updateObject


35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 35

def update
  if @field_group.update(@post_data)
    @field_group.add_fields(params[:fields], params[:field_options])
    @field_group.set_option('caption', @post_data[:caption])
    flash[:notice] = t('camaleon_cms.admin.custom_field.message.custom_updated')
    redirect_to action: :edit, id: @field_group.id
  else
    render 'form'
  end
end