Sha256: 782bd644ed462992b5a2440a1d56b72af31394a36d7e27488cc35caad1478e50

Contents?: true

Size: 1.6 KB

Versions: 88

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

88 entries across 88 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.9 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.8 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.7 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.6 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.5 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.14 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.4 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-7.0.0.pre.a app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.13 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.3 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.2 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.1 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.1.0 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.12 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.11 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.10 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-5.3.8 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-6.0.9 app/controllers/alchemy/admin/clipboard_controller.rb
alchemy_cms-5.3.7 app/controllers/alchemy/admin/clipboard_controller.rb