Class: CamaleonCms::Admin::Settings::CustomFieldsController
- Inherits:
-
CamaleonCms::Admin::SettingsController
- Object
- CamaleonCms::Admin::SettingsController
- CamaleonCms::Admin::Settings::CustomFieldsController
- Defined in:
- app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
create a new custom field group.
-
#destroy ⇒ Object
destroy a custom field group.
- #edit ⇒ Object
- #get_items ⇒ Object
- #index ⇒ Object
- #list ⇒ Object
- #new ⇒ Object
-
#reorder ⇒ Object
reorder custom fields group.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
create a new custom field group
41 42 43 44 45 46 47 48 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 41 def create @field_group = current_site.custom_field_groups.new(@post_data) if @field_group.save && _save_fields(@field_group) redirect_to action: :edit, id: @field_group.id else new end end |
#destroy ⇒ Object
destroy a custom field group
51 52 53 54 55 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 51 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 |
#edit ⇒ Object
21 22 23 24 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 21 def edit I18n.t("camaleon_cms.admin.button.edit") render 'form' end |
#get_items ⇒ Object
13 14 15 16 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 13 def get_items @key = params[:key] render partial: "get_items", layout: false end |
#index ⇒ Object
6 7 8 9 10 11 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 6 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 |
#list ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 66 def list p = params.permit(:post_type, :post_id, :categories => []) args = {} if p[:post_id].present? post = @current_site.the_post(p[:post_id].to_i) post.update_categories(p[:categories]) else post = CamaleonCms::Post.new post.taxonomy_id = p[:post_type].to_i args[:cat_ids] = p[:categories] end render partial: 'camaleon_cms/admin/settings/custom_fields/render', :locals => {record: post, field_groups: post.get_field_groups(args), show_shortcode: true} end |
#new ⇒ Object
34 35 36 37 38 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 34 def new I18n.t("camaleon_cms.admin.button.new") @field_group ||= current_site.custom_field_groups.new render 'form' end |
#reorder ⇒ Object
reorder custom fields group
58 59 60 61 62 63 64 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 58 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 |
#show ⇒ Object
18 19 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 18 def show end |
#update ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/controllers/camaleon_cms/admin/settings/custom_fields_controller.rb', line 26 def update if @field_group.update(@post_data) && _save_fields(@field_group) redirect_to action: :edit, id: @field_group.id else render 'form' end end |