Module: Admin::ApplicationHelper

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

Instance Method Summary collapse

Instance Method Details

#current_admin_site_nameObject



8
9
10
11
12
13
14
15
# File 'app/helpers/admin/application_helper.rb', line 8

def current_admin_site_name
  site_name = Spud::Core.site_name
  if Spud::Core.multisite_mode_enabled && !session[:admin_site].blank?
    config = Spud::Core.multisite_config.select{|p| p[:site_id].to_i == session[:admin_site].to_i}
    site_name = config[0][:site_name] if !config.blank?
  end
  return site_name
end

#error_messages_for(object) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/admin/application_helper.rb', line 26

def error_messages_for(object)
  content = ""
  if object.errors.any?
    content += "<div class='spud_admin_form_error_list'>"
    content += "<h4>#{pluralize(object.errors.count, "error")} prohibited you from saving:</h4>"
    content +="<ul>"
    object.errors.full_messages.each do |msg|
      content+="<li>#{msg}</li>"
    end
    content +="</ul></div>"
  end
  return content.html_safe

end

#header_styleObject



17
18
19
20
21
22
23
24
# File 'app/helpers/admin/application_helper.rb', line 17

def header_style
  style_str = ''
  if Spud::Core.multisite_mode_enabled
    config = Spud::Core.multisite_config.select{|p| p[:site_id].to_i == session[:admin_site].to_i}
    style_str = config[0][:header_style] if !config.blank? && config[0].has_key?(:header_style)
  end
  return style_str
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>



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/admin/application_helper.rb', line 70

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
# File 'app/helpers/admin/application_helper.rb', line 3

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

#url_for_admin_dashboard_application(url) ⇒ Object



41
42
43
44
45
46
47
# File 'app/helpers/admin/application_helper.rb', line 41

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