? devel_node_access.js
? devel_node_access_ajax.patch
Index: devel_node_access.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/devel/devel_node_access.module,v
retrieving revision 1.15.2.38
diff -u -p -r1.15.2.38 devel_node_access.module
--- devel_node_access.module	24 Feb 2011 09:11:34 -0000	1.15.2.38
+++ devel_node_access.module	28 Feb 2011 07:08:20 -0000
@@ -60,6 +60,14 @@ function devel_node_access_menu() {
     );
   }
 
+  $items['devel/node_access/user_ajax/%/%'] = array(
+    'title' => 'Devel node access user ajax',
+    'page callback' => 'devel_node_access_user_ajax',
+    'page arguments' => array(3, 4),
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
@@ -81,6 +89,12 @@ function devel_node_access_form_alter(&$
         '@link' => url('admin/build/block/list'),
       )),
     );
+    $form['devel_node_access_user_ajax'] = array(
+      '#type'          => 'checkbox',
+      '#title'         => t('Devel Node Access by User Ajax'),
+      '#default_value' => variable_get('devel_node_access_user_ajax', TRUE),
+      '#description'   => t('Use Ajax to populate the <em>Devel Node Access by User</em> block.  This loads the initial page faster, and uses dynamic calls to build the data in the table, one request at a time.'),
+    );
     // push these down:
     $form['devel_error_handler']['#weight'] = 1;
     $form['smtp_library']['#weight'] = 1;
@@ -510,6 +524,10 @@ function devel_node_access_block($op = '
           if (arg(0) == 'node' && is_numeric($nid = arg(1)) && arg(2) == null && $node = node_load($nid)) {
             $headers = array(t('username'), '<span title="'. t("Create nodes of the '@Node_type' type.", array('@Node_type' => node_get_types('name', $node))) .'">'. t('create') .'</span>', t('view'), t('update'), t('delete'));
             $rows = array();
+            // Determine whether to use Ajax or prepopulate the tables.
+            if ($ajax = variable_get('devel_node_access_user_ajax', TRUE)) {
+              drupal_add_js(drupal_get_path('module', 'devel_node_access') .'/devel_node_access.js');
+            }
             // Find all users. The following operations are very inefficient, so we
             // limit the number of users returned.  It would be better to make a
             // pager query, or at least make the number of users configurable.  If
@@ -521,11 +539,28 @@ function devel_node_access_block($op = '
               if ($account->uid == $user->uid) {
                 $username = '<strong>'. $username .'</strong>';
               }
-              $rows[] = array($username,
-                              theme('dna_permission', _devel_node_access_explain_access('create', $nid, $account)),
-                              theme('dna_permission', _devel_node_access_explain_access('view', $nid, $account)),
-                              theme('dna_permission', _devel_node_access_explain_access('update', $nid, $account)),
-                              theme('dna_permission', _devel_node_access_explain_access('delete', $nid, $account)),
+              $rows[] = array(
+                $username,
+                array(
+                  'id' => 'create-' . $nid . '-' . $account->uid,
+                  'class' => 'dna-permission',
+                  'data' => $ajax ? NULL : theme('dna_permission', _devel_node_access_explain_access('create', $nid, $account)),
+                ),
+                array(
+                  'id' => 'view-' . $nid . '-' . $account->uid,
+                  'class' => 'dna-permission',
+                  'data' => $ajax ? NULL : theme('dna_permission', _devel_node_access_explain_access('view', $nid, $account)),
+                ),
+                array(
+                  'id' => 'update-' . $nid . '-' . $account->uid,
+                  'class' => 'dna-permission',
+                  'data' => $ajax ? NULL : theme('dna_permission', _devel_node_access_explain_access('update', $nid, $account)),
+                ),
+                array(
+                  'id' => 'delete-' . $nid . '-' . $account->uid,
+                  'class' => 'dna-permission',
+                  'data' => $ajax ? NULL : theme('dna_permission', _devel_node_access_explain_access('delete', $nid, $account)),
+                ),
               );
             }
             if (count($rows)) {
@@ -542,6 +577,38 @@ function devel_node_access_block($op = '
 }
 
 /**
+ * Callback function for node access by user block ajax.
+ */
+function devel_node_access_user_ajax($data_type, $cell) {
+  list($op, $nid, $uid) = explode('-', $cell);
+  $account = user_load($uid);
+  $output = theme('dna_permission', _devel_node_access_explain_access($op, $nid, $account));
+  // JSON output for Ajax callbacks.
+  if ($data_type == 'json') {
+    drupal_json($output);
+    exit;
+  }
+  // HTML output for error message click-throughs.
+  if ($node = node_load($nid)) {
+    $node_title = l($node->title, 'node/'. $node->nid);
+  }
+  else {
+    $node_title = t('unknown node %nid', array('%nid' => $nid));
+  }
+  drupal_set_title(
+    t(
+      'Devel node access: %op permission for !user on !node',
+      array(
+        '%op'   => $op,
+        '!user' => theme('username', $account),
+        '!node' => $node_title,
+      )
+    )
+  );
+  return $output;
+}
+
+/**
  * Helper function that mimicks node.module's node_access() function.
  *
  * Unfortunately, this needs to be updated manually whenever node.module changes!
