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 a496574f40..52288ab20c 100644 --- a/app/controllers/administrate/application_controller.rb +++ b/app/controllers/administrate/application_controller.rb @@ -79,6 +79,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 c500e55479..11f75de125 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 %> -