Sha256: 4f2252bb5d8f9564a7e62d10aaf2e400638cb3bdfc0c6657a21ef821d67669ee

Contents?: true

Size: 999 Bytes

Versions: 39

Compression:

Stored size: 999 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],
          growl_message: message
        }
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.6 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.5 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.5.1 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.5 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.4 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.0.6 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.3 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.2 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.1 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.6.0 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.5.0 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.4 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.3 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.2 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.1 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.4.0 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.3.2 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.2.4 app/controllers/concerns/alchemy/admin/uploader_responses.rb
alchemy_cms-4.3.1 app/controllers/concerns/alchemy/admin/uploader_responses.rb