Module: Spree::Admin::NavigationHelper

Defined in:
app/helpers/spree/admin/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details

#button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object



74
75
76
# File 'app/helpers/spree/admin/navigation_helper.rb', line 74

def button(text, icon_name = nil, button_type = 'submit', options={})
  button_tag(('span', icon(icon_name) + ' ' + text), options.merge(:type => button_type))
end


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/helpers/spree/admin/navigation_helper.rb', line 78

def button_link_to(text, url, html_options = {})
  if (html_options[:method] &&
      html_options[:method].to_s.downcase != 'get' &&
      !html_options[:remote])
    form_tag(url, :method => html_options.delete(:method)) do
      button(text, html_options.delete(:icon), nil, html_options)
    end
  else
    if html_options['data-update'].nil? && html_options[:remote]
      object_name, action = url.split('/')[-2..-1]
      html_options['data-update'] = [action, object_name.singularize].join('_')
    end
    html_options.delete('data-update') unless html_options['data-update']
    link_to(text_for_button_link(text, html_options), url, html_options_for_button_link(html_options))
  end
end

#configurations_menu_item(link_text, url, description = '') ⇒ Object



108
109
110
111
112
113
114
# File 'app/helpers/spree/admin/navigation_helper.rb', line 108

def configurations_menu_item(link_text, url, description = '')
  %(<tr>
    <td>#{link_to(link_text, url)}</td>
    <td>#{description}</td>
  </tr>
  ).html_safe
end

#configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object



116
117
118
119
120
121
# File 'app/helpers/spree/admin/navigation_helper.rb', line 116

def configurations_sidebar_menu_item(link_text, url, options = {})
  options.merge!(:class => url.include?(controller.controller_name) ? 'active' : nil)
  (:li, options) do
    link_to(link_text, url)
  end
end


104
105
106
# File 'app/helpers/spree/admin/navigation_helper.rb', line 104

def html_options_for_button_link(html_options)
  options = { :class => 'button' }.update(html_options)
end

#icon(icon_name) ⇒ Object



70
71
72
# File 'app/helpers/spree/admin/navigation_helper.rb', line 70

def icon(icon_name)
  icon_name ? image_tag("admin/icons/#{icon_name}.png") : ''
end


37
38
39
# File 'app/helpers/spree/admin/navigation_helper.rb', line 37

def link_to_clone(resource, options={})
  link_to_with_icon('exclamation', t(:clone), clone_admin_product_url(resource), options)
end


57
58
59
60
61
62
63
# File 'app/helpers/spree/admin/navigation_helper.rb', line 57

def link_to_delete(resource, options={})
  url = options[:url] || object_url(resource)
  name = options[:name] || icon('delete') + ' ' + t(:delete)
  link_to name, url,
    :class => "delete-resource",
    :data => { :confirm => t(:are_you_sure) }
end


45
46
47
# File 'app/helpers/spree/admin/navigation_helper.rb', line 45

def link_to_edit(resource, options={})
  link_to_with_icon('edit', t(:edit), edit_object_url(resource), options)
end


49
50
51
# File 'app/helpers/spree/admin/navigation_helper.rb', line 49

def link_to_edit_url(url, options={})
  link_to_with_icon('edit', t(:edit), url, options)
end


41
42
43
# File 'app/helpers/spree/admin/navigation_helper.rb', line 41

def link_to_new(resource)
  link_to_with_icon('add', t(:new), edit_object_url(resource))
end


65
66
67
68
# File 'app/helpers/spree/admin/navigation_helper.rb', line 65

def link_to_with_icon(icon_name, text, url, options = {})
  options[:class] = (options[:class].to_s + ' icon_link').strip
  link_to(icon(icon_name) + ' ' + text, url, options)
end

#tab(*args) ⇒ Object

Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow. Valid options are

* :label to override link text, otherwise based on the first resource name (translated)
* :route to override automatically determining the default route
* :match_path as an alternative way to control when the tab is active, /products would match /admin/products, /admin/products/5/variants etc.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/spree/admin/navigation_helper.rb', line 9

def tab(*args)
  options = {:label => args.first.to_s}
  if args.last.is_a?(Hash)
    options = options.merge(args.pop)
  end
  options[:route] ||=  "admin_#{args.first}"

  destination_url = options[:url] || spree.send("#{options[:route]}_path")

  titleized_label = t(options[:label], :default => options[:label]).titleize

  link = link_to(titleized_label, destination_url)

  css_classes = []

  selected = if options[:match_path]
    request.fullpath.starts_with?("#{root_path}admin#{options[:match_path]}")
  else
    args.include?(controller.controller_name.to_sym)
  end
  css_classes << 'selected' if selected

  if options[:css_class]
    css_classes << options[:css_class]
  end
  ('li', link, :class => css_classes.join(' '))
end


95
96
97
98
99
100
101
102
# File 'app/helpers/spree/admin/navigation_helper.rb', line 95

def text_for_button_link(text, html_options)
  s = ''
  if html_options[:icon]
    s << icon(html_options.delete(:icon)) + ' '
  end
  s << text
  ('span', raw(s))
end