Module: Admin::ApplicationHelper
- Defined in:
- app/helpers/admin/application_helper.rb
Instance Method Summary collapse
- #current_admin_site_name ⇒ Object
- #error_messages_for(object) ⇒ Object
- #header_style ⇒ Object
-
#tb_core_tabbed_navigation(url_helper, tabs) ⇒ Object
Build a Bootstrap nav-tabs element.
- #timestamp(timedate = nil) ⇒ Object
- #url_for_admin_dashboard_application(url) ⇒ Object
Instance Method Details
#current_admin_site_name ⇒ Object
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 (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..each do |msg| content+="<li>#{msg}</li>" end content +="</ul></div>" end return content.html_safe end |
#header_style ⇒ Object
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 (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 |
#timestamp(timedate = nil) ⇒ Object
3 4 5 6 |
# File 'app/helpers/admin/application_helper.rb', line 3 def (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 |