? pi_assigned_update.patch
Index: /Applications/MAMP/htdocs/oct/drupal/sites/all/modules/project_issue/issue.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v
retrieving revision 1.315
diff -u -p -r1.315 issue.inc
--- issue.inc	23 Oct 2008 00:35:06 -0000	1.315
+++ issue.inc	25 Oct 2008 18:08:48 -0000
@@ -76,14 +76,25 @@ function project_issue_page() {
 }
 
 /**
- * JS callback method to return updated elements on the issue form
- * when someone changes the "Project" selector. See project_issue.js.
+ * JS callback method to return updated elements on the issue form.
+ * This function is called when someone changes the "Project" selector.
+ * See project_issue.js.
+ *
+ * @param $pid
+ *   The nid of the project we're updating to.
+ * @param $issue_nid
+ *   The issue nid.
+ * @param $cid
+ *   The component from the previously selected project.
+ * @param $rid
+ *   The version from the previously selected project.
+ * @param $assigned_uid
+ *   The uid of the assigned user from the previously selected project.
  */
-function project_issue_update_project($pid, $cid = NULL, $rid = NULL) {
-
+function project_issue_update_project($pid, $issue_nid, $cid = NULL, $rid = NULL, $assigned_uid = NULL) {
   // Prevent a malicious user from snooping this callback directly.
   $error = array('error' => t('An error was detected. Please try again.'));
-  $node = node_load($pid);
+  $node = node_load(array('nid' => $pid, 'type' => 'project_project'));
   if ($node) {
     if (!node_access('view', $node)) {
       print drupal_to_js($error);
@@ -128,6 +139,29 @@ function project_issue_update_project($p
     }
   }
 
+  // Assigned.
+  if (is_numeric($issue_nid)) {
+    $issue = node_load(array('nid' => $issue_nid, 'type' => 'project_issue'));
+  }
+  else {
+    $issue = new stdClass;
+  }
+  $issue->pid = $pid;
+  $return['assigned'] = '';
+  $assigned_choices = project_issue_assigned_choices($issue);
+
+  $form = array();
+  $form['issue_info']['assigned'] = array(
+    '#type' => 'select',
+    '#title' => t('Assigned'),
+    '#default_value' => $assigned_uid,
+    '#options' => $assigned_choices,
+  );
+
+  // Build the HTML output for the assigned select.
+  $form = form_builder('assigned', $form);
+  $return['assigned'] .= drupal_render($form);
+
   // Components.
   $return['component'] = '';
   $project = db_fetch_object(db_query('SELECT * FROM {project_issue_projects} WHERE nid = %d', $pid));
@@ -687,7 +721,11 @@ function project_issue_form($node, $incl
   // Load Javascript (unless the issue is being edited).
   if ($allow_metadata_changes) {
     drupal_add_js(drupal_get_path('module', 'project_issue') .'/project_issue.js');
-    drupal_add_js(array('projectUrl' => url('project/issues/update_project')), 'setting');
+    drupal_add_js(
+      array(
+        'projectUrl' => url('project/issues/update_project'),
+        'issueNid' => $node->nid,
+      ), 'setting');
   }
 
   // Load the project and initialize some support arrays.
@@ -713,15 +751,7 @@ function project_issue_form($node, $incl
     $categories = array_merge(array(t('<none>')), project_issue_category(0, 0));
     $priorities = project_issue_priority();
     $states = project_issue_state(0, true, $node->nid && ($node->uid == $user->uid), $node->sid);
-
-    // Setup the array of choices for who the issue is assigned to.
-    $assigned = array();
-    foreach (module_implements('project_issue_assignees') as $module) {
-      $function = "{$module}_project_issue_assignees";
-      $function($assigned, $node);
-    }
-    natcasesort($assigned);
-    $assigned = array(0 => empty($node->assigned) ? t('Unassigned') : t('Unassign')) + $assigned;
+    $assigned = project_issue_assigned_choices($node);
   }
 
   // Display the site-wide and/or per-project help text.
@@ -859,6 +889,27 @@ function project_issue_form($node, $incl
 }
 
 /**
+ * Build an array of users to whom an issue may be assigned.
+ *
+ * @param $issue
+ *   The issue object.
+ * @return
+ *   A keyed array in the form uid => name containing users
+ *   to whom an issue may be assigned.
+ */
+function project_issue_assigned_choices($issue) {
+  // Setup the array of choices for who the issue is assigned to.
+  $assigned = array();
+  foreach (module_implements('project_issue_assignees') as $module) {
+    $function = "{$module}_project_issue_assignees";
+    $function($assigned, $issue);
+  }
+  natcasesort($assigned);
+  $assigned = array(0 => empty($issue->assigned) ? t('Unassigned') : t('Unassign')) + $assigned;
+  return $assigned;
+}
+
+/**
  * Implmentation of hook_validate().
  *
  * Ensures that the issue node form has valid values for all required fields.
Index: /Applications/MAMP/htdocs/oct/drupal/sites/all/modules/project_issue/project_issue.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.js,v
retrieving revision 1.4
diff -u -p -r1.4 project_issue.js
--- project_issue.js	25 Oct 2007 04:44:04 -0000	1.4
+++ project_issue.js	25 Oct 2008 18:08:48 -0000
@@ -6,7 +6,7 @@ Drupal.projectSwitchAutoAttach = functio
 
     // Temporarily disable the dynamic selects while we retrieve the new info.
     // The newly loaded selects will be enabled by default.
-    $('#edit-project-info-rid, #edit-project-info-component').attr('disabled', 'disabled');
+    $('#edit-project-info-rid, #edit-project-info-component, #edit-assigned').attr('disabled', 'disabled');
 
     // Get existing component setting.
     var cid = $('#edit-project-info-component').val();
@@ -17,8 +17,15 @@ Drupal.projectSwitchAutoAttach = functio
     var rid = $('#edit-project-info-rid option[@value=' + nid + ']').text();
     rid = Drupal.encodeURIComponent(rid);
 
+    // Get existing assigned uid.
+    var assigned_uid = $('#edit-assigned').val();
+    assigned_uid = Drupal.encodeURIComponent(assigned_uid);
+
+    // Get the issue node's nid.
+    var issue_nid = Drupal.encodeURIComponent(Drupal.settings.issueNid);
+
     // Pass new project ID, existing version, existing component.
-    var url = Drupal.settings.projectUrl + '/' + pid + '/' + cid + '/' + rid;
+    var url = Drupal.settings.projectUrl + '/' + pid + '/' + issue_nid + '/' + cid + '/' + rid + '/' + assigned_uid;
 
     // Ajax GET request.
     $.ajax({
@@ -33,6 +40,8 @@ Drupal.projectSwitchAutoAttach = functio
         else {
           $('#edit-project-info-rid, #edit-project-info-component').parent().remove();
           $('#edit-project-info-pid').parent().after(result.component).after(result.rid);
+          $('#edit-assigned').parent().remove();
+          $('#edit-priority').parent().after(result.assigned);
         }
       },
       error: function (xmlhttp) {
