Sha256: 6c3c908e3705f029c17dc03912ac799681c742a9186253a0f69363f24e0ebc53

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

module Admin::ApplicationHelper

  def timestamp(timedate=nil)
    return "Never" if timedate.blank?
    return Time.now() - timedate > 604800 ? timedate.strftime("%B %d") + ' at ' + timedate.strftime("%I:%M %p") : time_ago_in_words(timedate) + ' ago'
  end

  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

  # Build an icon with left padding to indicate nesting below the previous table row
  #
  def table_nesting_indicator(depth)
    if depth > 0
      depth.times do
        concat content_tag(:span, '', :class => 'nesting-spacer')
      end
      content_tag(:span, "", :class => 'glyphicon glyphicon-chevron-right')
    end
  end

  # 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>
  #
  def tb_core_tabbed_navigation(url_helper, tabs)
    key = :tab
    content_tag :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(content_tag(:li, :class => cls){ link_to tab[:title], url })
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tb_core-1.3.3 app/helpers/admin/application_helper.rb
tb_core-1.3.2 app/helpers/admin/application_helper.rb
tb_core-1.3.1 app/helpers/admin/application_helper.rb
tb_core-1.3.0 app/helpers/admin/application_helper.rb