From: Coleman Watts Date: Mon, 11 Aug 2014 14:53:01 +0000 (+0100) Subject: CRM-15003 - Fix ActivityToCase default value X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7359cdbc2be53f31631ce210a969ca380737fbe1;p=civicrm-core.git CRM-15003 - Fix ActivityToCase default value --- diff --git a/CRM/Case/Form/ActivityToCase.php b/CRM/Case/Form/ActivityToCase.php index 7cfd525f85..39830d00dd 100644 --- a/CRM/Case/Form/ActivityToCase.php +++ b/CRM/Case/Form/ActivityToCase.php @@ -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; } diff --git a/templates/CRM/Case/Form/ActivityToCase.tpl b/templates/CRM/Case/Form/ActivityToCase.tpl index ee8963d638..b7723b75e3 100644 --- a/templates/CRM/Case/Form/ActivityToCase.tpl +++ b/templates/CRM/Case/Form/ActivityToCase.tpl @@ -65,11 +65,6 @@ return {results: response}; } } - }).change(function() { - if ($(this).val()) { - selectedCaseId = $(this).val(); - contactId = $(this).select2('data').extra.contact_id; - } }); }); @@ -110,6 +105,8 @@ }, 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( );