Sha256: cb9fd518822e1fef2a47329cf87d0db44b3f8744903801ac5c71e0b9f873028f

Contents?: true

Size: 975 Bytes

Versions: 25

Compression:

Stored size: 975 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  module Admin
    module UploaderResponses
      extend ActiveSupport::Concern

      def successful_uploader_response(file:, status: :created)
        message = Alchemy.t(:upload_success,
          scope: [:uploader, file.class.model_name.i18n_key],
          name: file.name)

        {
          json: uploader_response(file: file, message: message),
          status: status
        }
      end

      def failed_uploader_response(file:)
        message = Alchemy.t(:upload_failure,
          scope: [:uploader, file.class.model_name.i18n_key],
          error: file.errors[:file].join,
          name: file.name)

        {
          json: uploader_response(file: file, message: message),
          status: :unprocessable_entity
        }
      end

      private

      def uploader_response(file:, message:)
        {
          files: [file.to_jq_upload],
          message: message
        }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
alchemy_cms-7.2.8 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.13 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.7 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.6 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.5 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.12 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.4 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.11 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.3 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.10 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.2 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.9 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.2.1 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.8 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.7 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.6 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.5 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.4 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.3 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-7.1.2 app/controllers/concerns/alchemy/admin/uploader_responses.rb