Module: Gluttonberg::AssetLibrary

Included in:
ApplicationHelper
Defined in:
app/helpers/gluttonberg/asset_library.rb

Instance Method Summary collapse

Instance Method Details

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/gluttonberg/asset_library.rb', line 63

def _asset_browser_tag( field_id , opts = {} )
     asset_id = nil
     asset_id = opts[:asset_id]
     filter = opts[:filter].blank? ? "all" : opts[:filter]

     if opts[:id].blank?
       rel = field_id.to_s + "_" + id.to_s
       opts[:id] = rel
     end
     html_id = opts[:id]


    asset_info = ""
    asset_name = "Nothing selected"
    unless asset_id.blank?
      asset = Gluttonberg::Asset.find(:first , :conditions => {:id => asset_id})
      asset_name =  asset.name if asset
      if asset
        if asset.category && asset.category.to_s.downcase == "image"
          asset_info = asset_tag(asset , :small_thumb).html_safe
        end
      else
        asset_name = "Asset missing!"
      end
    end

    asset_name = (:h5, asset_name) if asset_name



     # Output it all
     thumbnail_contents = ""
     thumbnail_contents << asset_info

     thumbnail_caption = ""
     thumbnail_caption << asset_name unless asset_name.blank?
    thumbnail_caption << hidden_field_tag("filter_" + field_id.to_s , value=filter , :id => "filter_#{opts[:id]}" )
    thumbnail_caption << hidden_field_tag(field_id , asset_id , { :id => opts[:id] , :class => "choose_asset_hidden_field" } )

    thumbnail_p = ""
    thumbnail_p << link_to("Select", admin_asset_browser_url + "?filter=#{filter}" , { :class =>"btn button choose_button #{opts[:button_class]}" , :rel => html_id, :style => "margin-right:5px;" , :data_url => opts[:data_url] })
    if opts[:remove_button] != false
      thumbnail_p << clear_asset_tag( field_id , opts )
    end

    thumbnail_caption << (:p, thumbnail_p.html_safe)

    thumbnail_contents << (:div, thumbnail_caption.html_safe, :class => "caption")
    thumbnail = (:div, thumbnail_contents.html_safe, :class => "thumbnail asset_selector_wrapper")
    li_content = (:li, thumbnail, :class => "span4")
    (:ul , li_content , :id => "title_thumb_#{opts[:id]}", :class => "thumbnails")
end


116
117
118
119
120
121
# File 'app/helpers/gluttonberg/asset_library.rb', line 116

def add_image_to_gallery_tag( button_text , add_url, gallery_id , opts = {})
    opts[:class] = "" if opts[:class].blank?
    opts[:class] << " add_image_to_gallery choose_button btn button  #{opts[:button_class]}"
    link_contents = link_to(button_text, admin_asset_browser_url + "?filter=image" , opts.merge( :data_url => add_url ))
    (:span , link_contents , { :class => "assetBrowserLink" } )
end

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

Generates a link which launches the asset browser This method operates in bound or unbound mode.

In unbound mode this method accepts name of the tag and an options hash.

The options hash accepts the following parameters:

The following are required in unbound mode, not used in bound mode:
  :id = This is the id to use for the generated hidden field to store the selected assets id.
  :asset_id = The id of the currently selected asset.
  :filter = Its optional. If valid filter is provided then it only brings assets of belonging to select filter type. (image,audio video)
  :button_class => Html class for button
  :button_text => Its a label for button. If its not provided then "Browse"
The following are optional in either mode:
  < any option accepted by hidden_field() method >

For Finding image assets

asset_browser_tag( name_of_tag ,  opts = { :button_class => "" , :button_text => "Select" ,  :filter => "" ,  :id => "html_id", :asset_id => content.asset_id } )


59
60
61
# File 'app/helpers/gluttonberg/asset_library.rb', line 59

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

#asset_panel(assets, name_or_id, type) ⇒ Object



136
137
138
# File 'app/helpers/gluttonberg/asset_library.rb', line 136

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

#asset_tag(asset, thumbnail_type = nil, options = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'app/helpers/gluttonberg/asset_library.rb', line 141

def asset_tag(asset , thumbnail_type = nil, options = {} )
   unless asset.blank?
     path = thumbnail_type.blank? ? asset.url : asset.url_for(thumbnail_type)

     unless options.has_key?(:alt)
       options[:alt] = asset.alt.blank? ? asset.name : asset.alt
     end
     options[:src] = path
     tag(:img , ""  , options)
   end
end

#asset_tag_v2(asset, options = {}, thumbnail_type = nil) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'app/helpers/gluttonberg/asset_library.rb', line 153

def asset_tag_v2(asset , options = {} , thumbnail_type = nil)
    unless asset.blank?
      options[:class] = "" if options[:class].blank?
      options[:class] << " #{asset.name}"
      options[:alt] = asset.name
      options[:title] = asset.name
      options[:src] = thumbnail_type.blank? ? asset.url : asset.url_for(thumbnail_type)
      tag(:img , "" , options)
    end
end

#asset_url(asset, opts = {}) ⇒ Object

nice and clean public url of assets



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/gluttonberg/asset_library.rb', line 5

def asset_url(asset , opts = {})
  url = ""
  if Rails.env=="development"
    url = "http://#{request.host}:#{request.port}/user_asset/#{asset.asset_hash[0..3]}/#{asset.id}"
  else
    url = "http://#{request.host}/user_asset/#{asset.asset_hash[0..3]}/#{asset.id}"
  end

  if opts[:thumb_name]
    url << "/#{opts[:thumb_name]}"
  end

  url
end

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



123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/helpers/gluttonberg/asset_library.rb', line 123

def clear_asset_tag( field_id , opts = {} )
  asset_id = nil
  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]}"  , :onclick => "$('##{html_id}').val('');$('#title_thumb_#{opts[:id]} h5').html('');$('#title_thumb_#{opts[:id]} img').remove();" })


end


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/helpers/gluttonberg/asset_library.rb', line 164

def gallery_images_ul(id , gallery_thumb_image , gallery_large_image ,html_opts_for_ul = {})
  gallery = Gluttonberg::Gallery.find(id)
  unless gallery.blank? || gallery.gallery_images.blank?
    options = ""
    gallery.gallery_images.each do |g_image|
      li_html = link_to(asset_tag(g_image.image , gallery_thumb_image).html_safe , asset_url(g_image.image , :thumb_name => gallery_large_image) , :class => "thumb")
      unless g_image.image.alt.blank?
        image_desc_html = (:div , g_image.image.alt  , :class => "image-desc")
        li_html << (:div , image_desc_html , :class => "caption")
      end
      options << (:li , li_html , :id => "image_#{g_image.id}").html_safe
    end
    (:ul  , options.html_safe , html_opts_for_ul)
  end
end

Returns a link for sorting assets in the library



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

def sorter_link(name, param, url)
  opts = {}
  route_opts = { :order => param , :order_type => "asc" }
  if param == params[:order] || (!params[:order] && param == 'date-added')
    opts[:class] = "current"
    unless params[:order_type].blank?
      route_opts[:order_type] = (params[:order_type] == "asc" ? "desc" : "asc" )
    else
      route_opts[:order_type] = "desc"
    end
    opts[:class] << (route_opts[:order_type] == "asc" ? " desc" : " asc" )
  end

  link_to(name, url + "?" + route_opts.to_param , opts)
end