CRM-15003 - Supply contacts' open case as a default
authorColeman Watts <coleman@civicrm.org>
Thu, 17 Jul 2014 12:47:19 +0000 (13:47 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 17 Jul 2014 12:47:19 +0000 (13:47 +0100)
CRM/Case/BAO/Case.php
CRM/Case/Form/ActivityToCase.php
templates/CRM/Case/Form/ActivityToCase.tpl

index 0ca273ae2fec9439be96cc5d1961f9c326f005dd..b251ffa58d902e8c893f18a6689bb2b8e2c3e14a 100644 (file)
@@ -2049,6 +2049,9 @@ SELECT civicrm_contact.id as casemanager_id,
       $search = ($config->includeWildCardInName) ? "%$sortName%" : "$sortName%";
       $where[] = "( sort_name LIKE '$search' )";
     }
+    if ($cid = CRM_Utils_Array::value('contact_id', $params)) {
+      $where[] = " c.id = $cid ";
+    }
     if (is_array($excludeCaseIds) &&
       !CRM_Utils_System::isNull($excludeCaseIds)
     ) {
index 85f56d91558b3404ef953481a1f422ad3fb0aeb1..7cfd525f851b9b52f5e8b34cd86f1ffb806ceb52 100644 (file)
@@ -72,6 +72,17 @@ class CRM_Case_Form_ActivityToCase extends CRM_Core_Form {
     $defaults['file_on_case_activity_subject'] = $defaults['subject'];
     $defaults['file_on_case_target_contact_id'] = $defaults['target_contact'];
 
+    $cid = CRM_Utils_Request::retrieve('cid', 'Integer');
+    if ($cid) {
+      $cases = CRM_Case_BAO_Case::getUnclosedCases(array('contact_id' => $cid), $this->_currentCaseId);
+      foreach ($cases as $id => $details) {
+        $defaults['file_on_case_unclosed_case_id'] = $id;
+        $value = array('label' => $details['sort_name'] . ' - ' . $details['case_type']);
+        $this->updateElementAttr('file_on_case_unclosed_case_id', array('data-value' => json_encode($value)));
+        break;
+      }
+    }
+
     return $defaults;
   }
 
index 1f5a9da24bff5d63da4788ef34cfa471f64e1e5a..ee8963d638a5048279ec3a302017962cf6ff2e6e 100644 (file)
@@ -53,6 +53,9 @@
         formatSelection: function(row) {
           return row.label;
         },
+        initSelection: function($el, callback) {
+          callback($el.data('value'));
+        },
         ajax: {
           url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal},
           data: function(term) {