Module: AdminHelper

Defined in:
app/helpers/admin_helper.rb

Constant Summary collapse

ROUTE_MAP =
{
    admin_products_path:        'admin/products',
    admin_custom_fields_path:   'admin/custom_fields',
    admin_product_groups_path:  'admin/product_groups',
    admin_link_groups_path:     [ 'admin/link_groups', 'admin/navigations' ],
    admin_payment_methods_path: 'admin/payment_methods',
    admin_shipping_zones_path:  [ 'admin/shipping_zones', 'admin/shipping_methods' ],
    edit_admin_shop_path:       'admin/shops',
    admin_orders_path:          'admin/orders'
}

Instance Method Summary collapse

Instance Method Details

#admin_topbar(label, path, identifier) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/admin_helper.rb', line 18

def admin_topbar(label, path, identifier)

  html_options = {}

  if admin_topbar_active?(identifier, params[:controller])
    html_options['class'] = 'active'
  end

  (:li, link_to(label, path), html_options)
end

#admin_topbar_active?(path, current_controller) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/helpers/admin_helper.rb', line 14

def admin_topbar_active?(path, current_controller)
  Array.wrap(ROUTE_MAP[path.to_sym]).include?(current_controller)
end

#creditcard_logo_for(creditcard) ⇒ Object



46
47
48
# File 'app/helpers/admin_helper.rb', line 46

def creditcard_logo_for(creditcard)
  image_tag "#{creditcard.cardtype}.png"
end

#delete_iconObject



78
79
80
81
82
# File 'app/helpers/admin_helper.rb', line 78

def delete_icon
  %Q{
    <i class='icon-remove icon-black'></i>
  }.html_safe
end

#display_payment_status(order) ⇒ Object



29
30
31
32
# File 'app/helpers/admin_helper.rb', line 29

def display_payment_status(order)
  css_klass = order.payment_status == 'purchased' ? 'label-success' : 'label-info'
  %Q{<span class="label #{css_klass}"> #{order.payment_status.titleize.upcase} </span>}.html_safe
end

#display_shipping_status(order) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/admin_helper.rb', line 34

def display_shipping_status(order)
  css_klass = case order.shipping_status
              when 'shipped'
                'label-success'
              when 'nothing_to_ship'
                'label-info'
              when 'shipping_pending'
                'label-important'
              end
  %Q{<span class="label #{css_klass}"> #{order.shipping_status.titleize.upcase} </span>}.html_safe
end

#gravatar_for(email, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'app/helpers/admin_helper.rb', line 60

def gravatar_for(email, options = {})
  email ||= '[email protected]'
  options = { alt: 'avatar', class: 'avatar', size: 50 }.merge! options
  id = Digest::MD5::hexdigest(email.strip.downcase)
  default_gravatar_url = Rack::Utils.escape(image_path('default_gravatar.jpg'))
  url = 'http://www.gravatar.com/avatar/' + id + '.jpg?d='+default_gravatar_url+'&s=' + options[:size].to_s
  options.delete :size
  image_tag url, options
end

#shipment_info(shipment) ⇒ Object



70
71
72
73
74
75
76
# File 'app/helpers/admin_helper.rb', line 70

def shipment_info(shipment)
  if shipment.tracking_number.present?
    link_to shipment.name + ' #' + shipment.tracking_number, shipment.tracking_url
  else
    shipment.name
  end
end

#shipping_method_condition_in_english(shipping_method) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/helpers/admin_helper.rb', line 50

def shipping_method_condition_in_english(shipping_method)
  if shipping_method.maximum_order_amount
    s = number_to_currency(shipping_method.minimum_order_amount)
    s << " - "
    s << number_to_currency(shipping_method.maximum_order_amount)
  else
    number_to_currency(shipping_method.minimum_order_amount) + ' minimum'
  end
end