Module: Helpers

Included in:
Togo::Admin
Defined in:
lib/togo/admin/helpers.rb

Instance Method Summary collapse

Instance Method Details

#admin_url(url) ⇒ Object



45
46
47
# File 'lib/togo/admin/helpers.rb', line 45

def admin_url(url)
  [@path_prefix, url].join
end


25
26
27
28
29
30
31
32
33
34
# File 'lib/togo/admin/helpers.rb', line 25

def column_head_link(property, current_order, qs = {})
  if property.sortable
    qs = hash_to_qs(qs)
    new_order = (current_order[0] == property.name ? (current_order[1] == :asc ? "desc" : "asc") : "asc")
    link_class = current_order[0] == property.name ? new_order : ''
    "<a href=\"?o=#{[(property.name.to_s+'.'+new_order.to_s),qs].compact.join('&')}\" class=\"#{link_class}\">#{property.label}</a>"
  else
    property.label
  end
end

#hash_to_qs(h) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/togo/admin/helpers.rb', line 3

def hash_to_qs(h)
  return nil if h.blank?
  qs = h.keys.collect{|k|
    [k,escape(h[k])].join('=') if not h[k].blank?
  }.compact.join('&')
  qs = nil if qs.blank?
  qs
end

#logged_in?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/togo/admin/helpers.rb', line 40

def logged_in?
  return true if not config[:auth_model] or not config[:sessions]
  config[:auth_model] and session[:user] and session[:user].authenticated?
end


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/togo/admin/helpers.rb', line 12

def paging_links(page, count, qs = {})
  prev_link, next_link = 'Previous', 'Next'
  qs = hash_to_qs(qs)
    
  if not page == 1
    prev_link = "<a href=\"?p=#{[page-1, qs].compact.join('&')}\" rel=\"previous\">#{prev_link}</a>"
  end
  if not page == count and count > 1
    next_link = "<a href=\"?p=#{[page+1, qs].compact.join('&')}\" rel=\"next\">#{next_link}</a>"
  end
  [prev_link, next_link]
end

#partial(template, options = {}) ⇒ Object



36
37
38
# File 'lib/togo/admin/helpers.rb', line 36

def partial(template, options={})
  erb template, options.merge(:layout => false)
end

#return_urlObject



49
50
51
52
53
54
55
# File 'lib/togo/admin/helpers.rb', line 49

def return_url
  if request.referer
    request.referer.gsub(/^http:\/\/.*?\/(.*?)$/,"/\\1").gsub(Regexp.new("^#{@path_prefix}"), '')
  else
    admin_url('/' + @model.name)
  end
end