Sha256: 488e13f6a3c3adda729aefeda43dfb1d65d032144a209e1218ca76aa3195be0d

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

module Admin::Resources::DataTypes::DragonflyHelper

  def table_dragonfly_field(attribute, item)
    options = { :height => 25, :width => 25 }
    typus_dragonfly_preview(item, attribute, options)
  end

  def link_to_detach_attribute_for_dragonfly(attribute)
    validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map { |i| i.attributes }.flatten.map { |i| i.to_s }
    attachment = @item.send(attribute)

    if attachment.present? && !validators.include?(attribute) && attachment
      attribute_i18n = @item.class.human_attribute_name(attribute)
      label_text = <<-HTML
#{attribute_i18n}
<small>#{link_to Typus::I18n.t("Remove"), { :action => 'update', :id => @item.id, :attribute => attribute, :_continue => true }, :confirm => Typus::I18n.t("Are you sure?")}</small>
      HTML
      label_text.html_safe
    end
  end

  def typus_dragonfly_preview(item, attachment, options = {})
    data = item.send(attachment)
    return unless data

    if data.mime_type =~ /^image\/.+/
      render "admin/templates/dragonfly_preview",
             :preview => data.process(:thumb, Typus.image_preview_size).url,
             :thumb => data.process(:thumb, Typus.image_thumb_size).url,
             :options => options
    else
      link_to data.name, data.url
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
typus-3.1.0.rc18 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc17 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc16 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc15 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc14 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc13 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc12 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc11 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc10 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.0.rc9 app/helpers/admin/resources/data_types/dragonfly_helper.rb