Module: Admin::ApplicationHelper

Defined in:
app/helpers/admin/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#table_nesting_indicator(depth) ⇒ Object

Build an icon with left padding to indicate nesting below the previous table row



25
26
27
28
29
30
31
32
# File 'app/helpers/admin/application_helper.rb', line 25

def table_nesting_indicator(depth)
  if depth > 0
    depth.times do
      concat (:span, '', :class => 'nesting-spacer')
    end
    (:span, "", :class => 'glyphicon glyphicon-chevron-right')
  end
end

#tb_core_tabbed_navigation(url_helper, tabs) ⇒ Object

Build a Bootstrap nav-tabs element

  • url_helper: A symbol representing the url helper method. ie: admin_widgets_path

  • tabs: An array of tab hashes with :title and :value keys

Example:

<%= tb_core_tabbed_navigation(:admin_vehicles_path, [
  {:title => 'All'},
  {:title => 'New', :value => 'new'},
  {:title => 'Used', :value => 'used'}
]) %>

This would generate:

<ul class=“nav nav-tabs”>

<li class="active"><a href="/admin/vehicles">All</a></li>
<li class=""><a href="/admin/vehicles?tab=new">New</a></li>
<li class=""><a href="/admin/vehicles?tab=used">Used</a></li>

</ul>



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/admin/application_helper.rb', line 55

def tb_core_tabbed_navigation(url_helper, tabs)
  key = :tab
   :ul, :class => 'nav nav-tabs' do
    tabs.each do |tab|
      cls = params[key] == tab[:value] ? 'active' : ''
      url = tab.delete(:url)
      if url.blank?
        id_params = params.select{ |k,v| k == :id || k.to_s =~ /_id$/ }
        link_args = id_params.merge(key => tab[:value])
        url = self.send(url_helper, link_args)
      end
      concat((:li, :class => cls){ link_to tab[:title], url })
    end
  end
end

#timestamp(timedate = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/admin/application_helper.rb', line 3

def timestamp(timedate=nil)
  return "Never" if timedate.blank?

  if Time.now() > timedate # in the past
    return Time.now() - timedate > 604800 ? timedate.strftime("%B %d, %Y") + ' at ' + timedate.strftime("%I:%M %p") : time_ago_in_words(timedate) + ' ago'
  elsif Time.now() < timedate # in the future
    return timedate.strftime("%B %d, %Y") + ' at ' + timedate.strftime("%I:%M %p")
  else
    return "Right now"
  end
end

#url_for_admin_dashboard_application(url) ⇒ Object



15
16
17
18
19
20
21
# File 'app/helpers/admin/application_helper.rb', line 15

def url_for_admin_dashboard_application(url)
  if Rails.configuration.relative_url_root.blank?
    return url
  else
    return [Rails.configuration.relative_url_root, url].join('/').gsub(/(\/+)/, '/') 
  end
end