devel_node_access.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @file devel_node_access.js.
  3. */
  4. (function ($) {
  5. /**
  6. * Perform the access by user ajax request.
  7. */
  8. function devel_node_access_user_ajax(context) {
  9. // Get the cell ID for the first .dna-permission that isn't processed.
  10. var cell = $('td.dna-permission', context)
  11. .not('.ajax-processed', context)
  12. .attr('id');
  13. if (cell !== undefined) {
  14. // Generate the URI from the basePath, path, data type, cell ID, and a
  15. // random token to bypass caching.
  16. var url = Drupal.settings.basePath
  17. + "?q="
  18. + 'devel/node_access/by_user/json/'
  19. + cell
  20. + '/'
  21. + Math.floor((1000000000 * Math.random())).toString(16);
  22. // Execute Ajax callback and handle the response.
  23. $.getJSON(url, function(data) {
  24. $('#' + cell, context).html(data).addClass('ajax-processed');
  25. // Call this function again.
  26. devel_node_access_user_ajax(context);
  27. });
  28. // Ajax fails silently on error, mark bad requests with an error message.
  29. // If the request is just slow this will update when the request succeeds.
  30. setTimeout(
  31. function() {
  32. if ($('#' + cell, context).hasClass('ajax-processed') == false) {
  33. $('#' + cell, context)
  34. .html(
  35. '<span class="error">'
  36. + '<a href="' + url.replace('/json/', '/html/') + '">'
  37. + Drupal.t('Error: could not explain access')
  38. + '</a>'
  39. + '</span>'
  40. )
  41. .addClass('ajax-processed');
  42. // Call this function again.
  43. devel_node_access_user_ajax(context);
  44. }
  45. },
  46. 3000
  47. );
  48. }
  49. }
  50. /**
  51. * Attach the access by user behavior which initiates ajax.
  52. */
  53. Drupal.behaviors.develNodeAccessUserAjax = {
  54. attach: function(context) {
  55. // Start the ajax.
  56. devel_node_access_user_ajax(context);
  57. }
  58. };
  59. })(jQuery);