Sha256: db94c9ca9c1563980b58e2a4d6775b08eff2e4827aadb7472e1421dcde5e8df0

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Admin
    class ContentsController < Alchemy::Admin::BaseController
      helper 'alchemy/admin/essences'

      authorize_resource class: Alchemy::Content

      def create
        @element = Element.find(params[:content][:element_id])
        @content = Content.create_from_scratch(@element, content_params)
        @html_options = params[:html_options] || {}
        if picture_gallery_editor?
          @content.update_essence(picture_id: params[:picture_id])
          @gallery_pictures = @element.contents.gallery_pictures
          options_from_params[:sortable] = @gallery_pictures.size > 1
          @content_dom_id = "#add_picture_#{@element.id}"
        else
          @content_dom_id = "#add_content_for_element_#{@element.id}"
        end
      end

      def order
        Content.transaction do
          params[:content_ids].each_with_index do |id, idx|
            Content.where(id: id).update_all(position: idx + 1)
          end
        end
        @notice = Alchemy.t("Successfully saved content position")
      end

      private

      def content_params
        params.require(:content).permit(:element_id, :name, :ingredient, :essence_type)
      end

      def picture_gallery_editor?
        params[:content][:essence_type] == 'Alchemy::EssencePicture' && options_from_params[:grouped] == 'true'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-4.1.2 app/controllers/alchemy/admin/contents_controller.rb
alchemy_cms-4.1.1 app/controllers/alchemy/admin/contents_controller.rb
alchemy_cms-4.1.0 app/controllers/alchemy/admin/contents_controller.rb
alchemy_cms-4.1.0.rc1 app/controllers/alchemy/admin/contents_controller.rb
alchemy_cms-4.1.0.beta app/controllers/alchemy/admin/contents_controller.rb