CRM-15003 - Fix ActivityToCase default value
authorColeman Watts <coleman@civicrm.org>
Mon, 11 Aug 2014 14:53:01 +0000 (15:53 +0100)
committerColeman Watts <coleman@civicrm.org>
Mon, 11 Aug 2014 14:55:30 +0000 (15:55 +0100)
CRM/Case/Form/ActivityToCase.php
templates/CRM/Case/Form/ActivityToCase.tpl

index 7cfd525f851b9b52f5e8b34cd86f1ffb806ceb52..39830d00dd3b277356ff5857b3303fea6e9e3eee 100644 (file)
@@ -72,12 +72,16 @@ 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'];
 
+    // If this contact has an open case, supply it as a default
     $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']);
+        $value = array(
+          'label' => $details['sort_name'] . ' - ' . $details['case_type'],
+          'extra' => array('contact_id' => $cid),
+        );
         $this->updateElementAttr('file_on_case_unclosed_case_id', array('data-value' => json_encode($value)));
         break;
       }
index ee8963d638a5048279ec3a302017962cf6ff2e6e..b7723b75e30629b4f49a13d58593674581034054 100644 (file)
             return {results: response};
           }
         }
-      }).change(function() {
-        if ($(this).val()) {
-          selectedCaseId = $(this).val();
-          contactId = $(this).select2('data').extra.contact_id;
-        }
       });
     });
 
           },
           buttons: {
             "{/literal}{ts escape='js'}Save{/ts}{literal}": function() {
+              var selectedCaseId = cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').val();
+              var contactId = cj('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').select2('data').extra.contact_id;
               var subject         = cj("#file_on_case_activity_subject").val( );
               var targetContactId = cj("#file_on_case_target_contact_id").val( );