Sha256: 2db2c3d2f04fd11c49822adc5af5e6a30797cf2ee42a5f85fc179d23d44e47d8

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

module Admin::Resources::DataTypes::DragonflyHelper

  def table_dragonfly_field(attribute, item)
    typus_dragonfly_preview(item, attribute)
  end

  def link_to_detach_attribute_for_dragonfly(attribute)
    validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map(&:attributes).flatten.map(&: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, :_nullify => attribute, :_continue => true }, :confirm => Typus::I18n.t("Are you sure?")}</small>
      HTML
      label_text.html_safe
    end
  end

  def typus_dragonfly_preview(item, attachment)
    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_table_thumb_size).url
    else
      params[:_popup] ? data.name : link_to(data.name, data.url)
    end
  end

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

    if data.mime_type =~ /^image\/.+/
      render "admin/templates/dragonfly_form_preview",
             :attachment => data,
             :preview => data.process(:thumb, Typus.image_preview_size).url,
             :thumb => data.process(:thumb, Typus.image_thumb_size).url,
             :options => options
    else
      html = params[:_popup] ? data.name : link_to(data.name, data.url)
      # OPTIMIZE: Generate the tag with Ruby.
      "<p>#{html}</p>".html_safe
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
typus-3.1.10 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.9 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.8 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.7 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.6 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.5 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.4 app/helpers/admin/resources/data_types/dragonfly_helper.rb
typus-3.1.3 app/helpers/admin/resources/data_types/dragonfly_helper.rb