diff --git a/app/assets/javascripts/administrate/components/table.js b/app/assets/javascripts/administrate/components/table.js index c283eb410d..bb9b36919a 100644 --- a/app/assets/javascripts/administrate/components/table.js +++ b/app/assets/javascripts/administrate/components/table.js @@ -2,12 +2,14 @@ $(function() { var keycodes = { space: 32, enter: 13 }; var visitDataUrl = function(event) { - if (event.type=="click" || + if (event.type == "click" || event.keyCode == keycodes.space || event.keyCode == keycodes.enter) { - if(!event.target.href) { - window.location = $(event.target).closest("tr").data("url"); + if (!event.target.href) { + var url = $(event.target).closest("tr").data("url"); + + if (url) { window.location = url; } } } }; diff --git a/app/controllers/administrate/application_controller.rb b/app/controllers/administrate/application_controller.rb index 20c3e3a242..f1992704cd 100644 --- a/app/controllers/administrate/application_controller.rb +++ b/app/controllers/administrate/application_controller.rb @@ -80,6 +80,17 @@ def nav_link_state(resource) end end + helper_method :valid_action? + def valid_action?(name, resource = resource_name) + !!routes.detect do |controller, action| + controller == resource.to_s.pluralize && action == name.to_s + end + end + + def routes + @routes ||= Namespace.new(namespace).routes + end + def records_per_page params[:per_page] || 20 end diff --git a/app/views/administrate/application/_collection.html.erb b/app/views/administrate/application/_collection.html.erb index 8a4d0932a1..1aeffe3735 100644 --- a/app/views/administrate/application/_collection.html.erb +++ b/app/views/administrate/application/_collection.html.erb @@ -47,16 +47,17 @@ to display a collection of resources in an HTML table. <% end %> <% end %> -