Sha256: 53c623a2f1ab4c1f399bd6ef455b1f1e1aae4ff5d3215a42857797641b71b057

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

#require 'rails_admin/config/fields/types/string'
module RailsAdmin::Config::Fields::Types
  class ImageManagerPicker < RailsAdmin::Config::Fields::Base
    RailsAdmin::Config::Fields::Types::register(:image_manager_picker, self)

    register_instance_option(:config) do
      {}
    end

    register_instance_option(:partial) do
      :form_image_manager_picker
    end

    register_instance_option(:delete_method) do
      "#{name}_deselect"
    end

    register_instance_option :allowed_methods do
      [method_name, delete_method].compact
    end

    def editor_options
      RailsAdminImageManager.options(config)
    end

    def preview_image_path
      if value.to_s.html_safe != ""
        if (true if Float(value) rescue false)
          # if the value is numeric we assume its an object id
          # Check if the id exist otherwise show placeholder image
          if RailsAdminImageManager::File.exists?(value)
            image_manager_file = RailsAdminImageManager::File.find(value)
            image_manager_file.image.url(:rails_admin)
          else
            editor_options[:placeholder_image]
          end
        else
          # if not, we assume its a url
          value.to_s
        end
      else
        # no value, show placeholder image
        editor_options[:placeholder_image]
      end

    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rails_admin_image_manager-0.1.34 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.33 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.31 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.30 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.3 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.29 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.28 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.27 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.26 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.25 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.24 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.23 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.22 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.21 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.20 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb
rails_admin_image_manager-0.1.15 lib/rails_admin_image_manager/rails_admin/config/fields/types/image_manager_picker.rb