Sha256: ac5d96c38e0c41655d89259cf54f37335800ec8fb14d481979fc5d279d1b02c1

Contents?: true

Size: 1.6 KB

Versions: 51

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Admin
    class ClipboardController < Alchemy::Admin::BaseController
      REMARKABLE_TYPES = %w[elements pages]

      authorize_resource class: :alchemy_admin_clipboard
      before_action :set_clipboard

      def index
        @clipboard_items = model_class.all_from_clipboard(@clipboard)
        respond_to do |format|
          format.html
        end
      end

      def insert
        @item = model_class.find(remarkable_params[:remarkable_id])
        unless @clipboard.detect { |item| item["id"] == remarkable_params[:remarkable_id] }
          @clipboard << {
            "id" => remarkable_params[:remarkable_id],
            "action" => params[:remove] ? "cut" : "copy"
          }
        end
        respond_to do |format|
          format.js
        end
      end

      def remove
        @item = model_class.find(remarkable_params[:remarkable_id])
        @clipboard.delete_if { |item| item["id"] == remarkable_params[:remarkable_id] }
        respond_to do |format|
          format.js
        end
      end

      def clear
        @clipboard.clear
      end

      private

      def set_clipboard
        @clipboard = get_clipboard(remarkable_type)
      end

      def model_class
        raise ActionController::BadRequest unless remarkable_type

        "alchemy/#{remarkable_type}".classify.constantize
      end

      def remarkable_params
        params.permit(:remarkable_type, :remarkable_id)
      end

      def remarkable_type
        remarkable_params.keep_if { |_k, type| type.in? REMARKABLE_TYPES }[:remarkable_type]
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
alchemy_cms-7.3.5 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.8 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.1.13 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.0.16 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.3.4 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.3.3 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.3.2 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.7 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.3.1 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.3.0 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.6 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.5 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.1.12 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.0.15 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.4 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.1.11 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.3 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.1.10 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.2.2 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.1.9 app/controllers/alchemy/admin/clipboard_controller.rb