Module: Gluttonberg::Admin::Assets

Included in:
Gluttonberg::Admin
Defined in:
app/helpers/gluttonberg/admin/assets.rb

Instance Method Summary collapse

Instance Method Details

#_asset_browser_tag(field_name, opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/gluttonberg/admin/assets.rb', line 23

def _asset_browser_tag( field_name , opts = {} )
  asset_id = opts[:asset_id]
  opts[:filter] = opts[:filter] || "all"
  asset = if asset_id.blank?
    nil
  else
    Gluttonberg::Asset.where(:id => asset_id).first
  end

  opts[:id] = "#{field_name}_#{asset_id}" if opts[:id].blank?
  render :partial => "/gluttonberg/admin/asset_library/shared/asset_browser", :locals => {
    :opts => opts,
    :asset => asset,
    :field_name => field_name
  }
end

#asset_browser_tag(field_name, opts = {}) ⇒ Object

Generates a link which launches the asset browser

For Finding image assets

asset_browser_tag( field_name ,  opts = { :id => "" , :asset_id => "" ,  :filter => "" ,  :id => "html_id", :data_url => "", :button_class =>  "" } )

Parameters:

  • field_name (String or Symbol)
  • opts (Hash) (defaults to: {})

    :id (optional) This is the id to use for the generated hidden field to store the selected assets id. If its not provided then this helper will auto generate :asset_id (nil allowed) The id of the currently selected asset. :filter (optional) If valid filter is provided then it only brings assets of belonging to select filter type. (image,audio video). Now comma seperated list of filters is also allowed. :button_class (optional) Css class for asset selector link/button :data_url (optional) If this url is provided then it will auto save selection



19
20
21
# File 'app/helpers/gluttonberg/admin/assets.rb', line 19

def asset_browser_tag( field_name , opts = {} )
  _asset_browser_tag( field_name , opts  )
end

#asset_panel(assets, name_or_id, type) ⇒ Object



64
65
66
# File 'app/helpers/gluttonberg/admin/assets.rb', line 64

def asset_panel(assets, name_or_id , type )
  render :partial => "/gluttonberg/admin/shared/asset_panel" , :locals => {:assets => assets , :name_or_id => name_or_id , :type => type} , :formats => [:html]
end

#backend_logo(default_logo_image_path, html_opts = {}, thumbnail_type = :backend_logo) ⇒ Object

Button to select Backend logo on settings page



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/gluttonberg/admin/assets.rb', line 69

def (default_logo_image_path , html_opts={}, thumbnail_type = :backend_logo)
   = Gluttonberg::Setting.get_setting("backend_logo")
  if !.blank? && .to_i > 0
    asset = Asset.where(:id => ).first
    unless asset.blank?
      path = thumbnail_type.blank? ? asset.url : asset.url_for(thumbnail_type)
      (:img , "" , html_opts.merge( :alt => asset.name , :src => path ) )
    else
      image_tag(default_logo_image_path)
    end
  end
end

#clear_asset_tag(field_id, opts = {}) ⇒ Object

Generates a link which clears asset browser input

For clearing image asset

clear_asset_tag( field_name ,  opts = { :id => "", :asset_id => "", :id => "html_id", :data_url => "", :button_class =>  "" } )

Parameters:

  • field_name (String or Symbol)
  • opts (Hash) (defaults to: {})

    :id (optional) This is the id to use for the generated hidden field to store the selected assets id. If its not provided then this helper will auto generate :asset_id (nil allowed) The id of the currently selected asset. :button_class (optional) Css class for asset selector link/button :data_url (optional) If this url is provided then it will auto save selection



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/gluttonberg/admin/assets.rb', line 51

def clear_asset_tag( field_id , opts = {} )
  asset_id = opts[:asset_id]
  if opts[:id].blank?
    rel = field_id.to_s + "_" + id.to_s
    opts[:id] = rel
  end
  html_id = opts[:id]
  link_to("Remove", "Javascript:;" , {
    :class => "btn btn-danger button remove #{opts[:button_class]}",
    :data_url => opts[:data_url]
  })
end