Module: Spree::Admin::NavigationHelper
- Defined in:
- app/helpers/spree/admin/navigation_helper.rb
Instance Method Summary collapse
- #button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
- #button_link_to(text, url, html_options = {}) ⇒ Object
- #configurations_menu_item(link_text, url, description = '') ⇒ Object
- #configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
- #icon(icon_name) ⇒ Object
-
#klass_for(name) ⇒ Object
finds class for a given symbol / string.
- #link_to_clone(resource, options = {}) ⇒ Object
- #link_to_delete(resource, options = {}) ⇒ Object
- #link_to_edit(resource, options = {}) ⇒ Object
- #link_to_edit_url(url, options = {}) ⇒ Object
- #link_to_new(resource) ⇒ Object
- #link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
-
#tab(*args) ⇒ Object
Make an admin tab that coveres one or more resources supplied by symbols Option hash may follow.
- #text_for_button_link(text, html_options) ⇒ Object
Instance Method Details
#button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
103 104 105 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 103 def (text, icon_name = nil, = 'submit', ={}) (text, .merge(:type => , :class => "#{icon_name} button")) end |
#button_link_to(text, url, html_options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 107 def (text, url, = {}) if ([:method] && [:method].to_s.downcase != 'get' && ![:remote]) form_tag(url, :method => .delete(:method)) do (text, .delete(:icon), nil, ) end else if ['data-update'].nil? && [:remote] object_name, action = url.split('/')[-2..-1] ['data-update'] = [action, object_name.singularize].join('_') end .delete('data-update') unless ['data-update'] [:class] = 'button' if [:icon] [:class] += " #{[:icon]}" end link_to((text, ), url, ) end end |
#configurations_menu_item(link_text, url, description = '') ⇒ Object
137 138 139 140 141 142 143 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 137 def (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
145 146 147 148 149 150 151 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 145 def (link_text, url, = {}) is_active = url.ends_with?(controller.controller_name) || url.ends_with?( "#{controller.controller_name}/edit") .merge!(:class => is_active ? 'active' : nil) content_tag(:li, ) do link_to(link_text, url) end end |
#icon(icon_name) ⇒ Object
99 100 101 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 99 def icon(icon_name) icon_name ? content_tag(:i, '', :class => icon_name) : '' end |
#klass_for(name) ⇒ Object
finds class for a given symbol / string
Example : :products returns Spree::Product :my_products returns MyProduct if MyProduct is defined :my_products returns My::Product if My::Product is defined if cannot constantize it returns nil This will allow us to use cancan abilities on tab
54 55 56 57 58 59 60 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 54 def klass_for(name) model_name = name.to_s ["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t| t.safe_constantize end.try(:safe_constantize) end |
#link_to_clone(resource, options = {}) ⇒ Object
62 63 64 65 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 62 def link_to_clone(resource, ={}) [:data] = {:action => 'clone'} link_to_with_icon('icon-copy', Spree.t(:clone), clone_admin_product_url(resource), ) end |
#link_to_delete(resource, options = {}) ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 82 def link_to_delete(resource, ={}) url = [:url] || object_url(resource) name = [:name] || Spree.t(:delete) [:class] = "delete-resource" [:data] = { :confirm => Spree.t(:are_you_sure), :action => 'remove' } link_to_with_icon 'icon-trash', name, url, end |
#link_to_edit(resource, options = {}) ⇒ Object
72 73 74 75 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 72 def link_to_edit(resource, ={}) [:data] = {:action => 'edit'} link_to_with_icon('icon-edit', Spree.t(:edit), edit_object_url(resource), ) end |
#link_to_edit_url(url, options = {}) ⇒ Object
77 78 79 80 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 77 def link_to_edit_url(url, ={}) [:data] = {:action => 'edit'} link_to_with_icon('icon-edit', Spree.t(:edit), url, ) end |
#link_to_new(resource) ⇒ Object
67 68 69 70 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 67 def link_to_new(resource) [:data] = {:action => 'new'} link_to_with_icon('icon-plus', Spree.t(:new), edit_object_url(resource)) end |
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 90 def link_to_with_icon(icon_name, text, url, = {}) [:class] = ([:class].to_s + " icon_link with-tip #{icon_name}").strip [:class] += ' no-text' if [:no_text] [:title] = text if [:no_text] text = [:no_text] ? '' : raw("<span class='text'>#{text}</span>") .delete(:no_text) link_to(text, url, ) 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 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 9 def tab(*args) = {:label => args.first.to_s} # Return if resource is found and user is not allowed to :admin return '' if klass = klass_for([:label]) and cannot?(:admin, klass) if args.last.is_a?(Hash) = .merge(args.pop) end [:route] ||= "admin_#{args.first}" destination_url = [:url] || spree.send("#{[:route]}_path") titleized_label = Spree.t([:label], :default => [:label]).titleize css_classes = [] if [:icon] link = link_to_with_icon([:icon], titleized_label, destination_url) css_classes << 'tab-with-icon' else link = link_to(titleized_label, destination_url) end selected = if [:match_path] request.fullpath.starts_with?("#{spree.root_path}admin#{[:match_path]}") else args.include?(controller.controller_name.to_sym) end css_classes << 'selected' if selected if [:css_class] css_classes << [:css_class] end content_tag('li', link, :class => css_classes.join(' ')) end |
#text_for_button_link(text, html_options) ⇒ Object
131 132 133 134 135 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 131 def (text, ) s = '' s << text raw(s) end |