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
- #button_link_to_function(text, function, html_options = {}) ⇒ Object
- #configurations_menu_item(link_text, url, description = '') ⇒ Object
- #configurations_sidebar_menu_item(link_text, url, options = {}) ⇒ Object
- #html_options_for_button_link(html_options) ⇒ Object
- #icon(icon_name) ⇒ Object
- #link_to_clone(resource, options = {}) ⇒ Object
- #link_to_delete(resource, options = {}, html_options = {}) ⇒ Object
- #link_to_edit(resource, options = {}) ⇒ Object
- #link_to_edit_url(url, options = {}) ⇒ Object
- #link_to_function_delete(options, html_options) ⇒ Object
- #link_to_function_delete_ajax(options) ⇒ Object
-
#link_to_function_delete_native(options, html_options) ⇒ Object
this function does not use jConfirm.
- #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
RAILS 3 TODO - no longer needed def button_link_to_remote(text, url, html_options = {}) html_options.reverse_merge! :remote => true link_to(text_for_button_link(text, html_options), url, html_options_for_button_link(html_options)) end.
Instance Method Details
#button(text, icon_name = nil, button_type = 'submit', options = {}) ⇒ Object
111 112 113 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 111 def (text, icon_name = nil, = 'submit', ={}) content_tag('button', content_tag('span', icon(icon_name) + ' ' + text), .merge(:type => )) end |
#button_link_to(text, url, html_options = {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 115 def (text, url, = {}) if ([:method] && [:method].to_s.downcase != 'get' && ![:remote]) form_tag(url, :method => [:method]) do (text, [:icon]) 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'] link_to((text, ), url, ()) end end |
#button_link_to_function(text, function, html_options = {}) ⇒ Object
132 133 134 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 132 def (text, function, = {}) link_to_function((text, ), function, ()) end |
#configurations_menu_item(link_text, url, description = '') ⇒ Object
161 162 163 164 165 166 167 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 161 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
169 170 171 172 173 174 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 169 def (link_text, url, = {}) .merge!(:class => url.include?(controller.controller_name) ? 'active' : nil) content_tag(:li, ) do link_to(link_text, url) end end |
#html_options_for_button_link(html_options) ⇒ Object
157 158 159 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 157 def () = { :class => 'button' }.update() end |
#icon(icon_name) ⇒ Object
107 108 109 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 107 def icon(icon_name) icon_name ? image_tag("admin/icons/#{icon_name}.png") : '' end |
#link_to_clone(resource, options = {}) ⇒ Object
39 40 41 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 39 def link_to_clone(resource, ={}) link_to_with_icon('exclamation', t(:clone), clone_admin_product_url(resource), ) end |
#link_to_delete(resource, options = {}, html_options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 59 def link_to_delete(resource, = {}, ={}) .assert_valid_keys(:url, :caption, :title, :dataType, :success, :name) .reverse_merge! :url => object_url(resource) unless .key? :url .reverse_merge! :caption => t(:are_you_sure) .reverse_merge! :title => t(:confirm_delete) .reverse_merge! :dataType => 'script' .reverse_merge! :success => "function(r){ $('##{dom_id resource}').fadeOut('hide'); }" .reverse_merge! :error => "function(jqXHR, textStatus, errorThrown){ show_flash_error(jqXHR.responseText); }" .reverse_merge! :name => icon('delete') + ' ' + t(:delete) link_to_function_delete(, ) #link_to_function_delete_native(options, html_options) end |
#link_to_edit(resource, options = {}) ⇒ Object
47 48 49 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 47 def link_to_edit(resource, ={}) link_to_with_icon('edit', t(:edit), edit_object_url(resource), ) end |
#link_to_edit_url(url, options = {}) ⇒ Object
51 52 53 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 51 def link_to_edit_url(url, ={}) link_to_with_icon('edit', t(:edit), url, ) end |
#link_to_function_delete(options, html_options) ⇒ Object
83 84 85 86 87 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 83 def link_to_function_delete(, ) link_to_function [:name], "jConfirm('#{[:caption]}', '#{[:title]}', function(r) { if(r){ #{link_to_function_delete_ajax()} } });", end |
#link_to_function_delete_ajax(options) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 89 def link_to_function_delete_ajax() %Q{ $.ajax({ type: 'POST', url: '#{[:url]}', data: ({_method: 'delete', authenticity_token: AUTH_TOKEN}), dataType:'#{[:dataType]}', success: #{[:success]}, error: #{[:error]} }); } end |
#link_to_function_delete_native(options, html_options) ⇒ Object
this function does not use jConfirm
75 76 77 78 79 80 81 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 75 def link_to_function_delete_native(, ) fn = %Q{ var answer = confirm("#{t(:are_you_sure)}"); if (!!answer) { #{link_to_function_delete_ajax()} }; } link_to_function [:name], fn, end |
#link_to_new(resource) ⇒ Object
43 44 45 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 43 def link_to_new(resource) link_to_with_icon('add', t(:new), edit_object_url(resource)) end |
#link_to_with_icon(icon_name, text, url, options = {}) ⇒ Object
102 103 104 105 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 102 def link_to_with_icon(icon_name, text, url, = {}) [:class] = ([:class].to_s + ' icon_link').strip link_to(icon(icon_name) + ' ' + 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 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 9 def tab(*args) = {:label => args.first.to_s} if args.last.is_a?(Hash) = .merge(args.pop) end [:route] ||= "admin_#{args.first}" destination_url = [:url] || spree.send("#{[:route]}_path") titleized_label = t([:label], :default => [:label]).titleize link = link_to(titleized_label, destination_url) css_classes = [] selected = if [:match_path] # TODO: `request.fullpath` for engines mounted at '/' returns '//' # which seems an issue with Rails routing.- revisit issue #910 request.fullpath.gsub('//', '/').starts_with?("#{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
RAILS 3 TODO - no longer needed def button_link_to_remote(text, url, html_options = {})
.reverse_merge! :remote => true
link_to((text, ), url, ())
end
def link_to_remote(name, options = {}, html_options = {})
[:before] ||= "jQuery(this).parent().hide(); jQuery('#busy_indicator').show();"
[:complete] ||= "jQuery('#busy_indicator').hide()"
link_to_function(name, remote_function(), || .delete(:html))
end
148 149 150 151 152 153 154 155 |
# File 'app/helpers/spree/admin/navigation_helper.rb', line 148 def (text, ) s = '' if [:icon] s << icon(.delete(:icon)) + ' ' end s << text content_tag('span', raw(s)) end |