From 5ffd5a35504fb8ac641e4d488c9707f0b04c1070 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 17 Mar 2014 23:18:53 -0400 Subject: [PATCH] CRM-10693 HR-310 - Use ajax framework for edit case activities, relationships, etc --- CRM/Case/Form/CaseView.php | 59 ++++++++++------ templates/CRM/Case/Form/CaseView.js | 22 ++++++ templates/CRM/Case/Form/CaseView.tpl | 102 ++++----------------------- 3 files changed, 73 insertions(+), 110 deletions(-) create mode 100644 templates/CRM/Case/Form/CaseView.js diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index 903fa6abb3..9e2dd86768 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -68,6 +68,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { } $this->assign('relatedCases', $relatedCases); $this->assign('showRelatedCases', TRUE); + CRM_Utils_System::setTitle(ts('Related Cases')); return; } @@ -132,19 +133,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $this->_caseType = $caseTypeName; $this->assign('caseDetails', $this->_caseDetails); - $newActivityUrl = CRM_Utils_System::url('civicrm/case/activity', - "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=", - FALSE, NULL, FALSE - ); - $this->assign('newActivityUrl', $newActivityUrl); - - // Send Email activity requires a different URL format from all other activities - $newActivityEmailUrl = CRM_Utils_System::url('civicrm/activity/email/add', - "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=", - FALSE, NULL, FALSE - ); - $this->assign('newActivityEmailUrl', $newActivityEmailUrl); - $reportUrl = CRM_Utils_System::url('civicrm/case/report', "reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=", FALSE, NULL, FALSE @@ -187,7 +175,16 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $relatedCases = empty($relatedCases) ? FALSE : $relatedCases; $this->set('relatedCases', $relatedCases); } - $this->assign('hasRelatedCases', $relatedCases); + $this->assign('hasRelatedCases', (bool) $relatedCases); + if ($relatedCases) { + $this->assign('relatedCaseLabel', ts('%1 Related Case', array('count' => count($relatedCases), 'plural' => '%1 Related Cases'))); + $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array( + 'id' => $this->_caseID, + 'cid' => $this->_contactID, + 'relatedCases' => 1, + 'action' => 'view', + ))); + } $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'][0] : NULL; $this->assign('caseTypeID', $entitySubType); @@ -227,6 +224,10 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { return; } + CRM_Core_Resources::singleton() + ->addScriptFile('civicrm', 'js/crm.livePage.js') + ->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js'); + $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); @@ -241,19 +242,16 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'); + $emailActivityType = array_search('Email', $allActTypes); + // remove Open Case activity type since we're inside an existing case - if (($openActTypeId = array_search('Open Case', $allActTypes)) && - array_key_exists($openActTypeId, $aTypes) - ) { + if ($openActTypeId = array_search('Open Case', $allActTypes)) { unset($aTypes[$openActTypeId]); } //check for link cases. $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases(NULL, array($this->_caseID)); - if (empty($unclosedCases) && - ($linkActTypeId = array_search('Link Cases', $allActTypes)) && - array_key_exists($linkActTypeId, $aTypes) - ) { + if (empty($unclosedCases) && ($linkActTypeId = array_search('Link Cases', $allActTypes))) { unset($aTypes[$linkActTypeId]); } @@ -261,7 +259,24 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { asort($aTypes); } - $this->add('select', 'activity_type_id', ts('New Activity'), array('' => ts('- select activity type -')) + $aTypes); + $activityLinks = array('' => ts('Add Activity')); + foreach ($aTypes as $type => $label) { + if ($type == $emailActivityType) { + $url = CRM_Utils_System::url('civicrm/activity/email/add', + "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type", + FALSE, NULL, FALSE + ); + } + else { + $url = CRM_Utils_System::url('civicrm/case/activity', + "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type", + FALSE, NULL, FALSE + ); + } + $activityLinks[$url] = $label; + } + + $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu')); if ($this->_hasAccessToAllCases) { $this->add('select', 'report_id', ts('Run QA Audit / Redact'), array( diff --git a/templates/CRM/Case/Form/CaseView.js b/templates/CRM/Case/Form/CaseView.js new file mode 100644 index 0000000000..404c3c04fe --- /dev/null +++ b/templates/CRM/Case/Form/CaseView.js @@ -0,0 +1,22 @@ +// https://civicrm.org/licensing +cj(function($) { + + function refresh() { + $('#crm-main-content-wrapper').crmSnippet('refresh'); + } + + function open(url) { + if (CRM.config.ajaxPopupsEnabled) { + CRM.loadForm(url).on('crmFormSuccess', refresh); + } + else { + window.location = url; + } + } + + $('#crm-container') + .on('change', 'select[name=add_activity_type_id]', function() { + open($(this).val()); + $(this).select2('val', ''); + }); +}); diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 4f0402b89e..f24b401f3d 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -47,7 +47,7 @@ {if $hasRelatedCases} - + {/if} @@ -73,7 +73,7 @@ {/foreach} {if $hasRelatedCases} - + {/if} {/if} @@ -81,13 +81,13 @@ {ts}Subject{/ts}: {$caseDetails.case_subject} - {ts}Type{/ts}: {$caseDetails.case_type}  + {ts}Type{/ts}: {$caseDetails.case_type}  - {ts}Status{/ts}: {$caseDetails.case_status}  + {ts}Status{/ts}: {$caseDetails.case_status}  - {ts}Open Date{/ts}: {$caseDetails.case_start_date|crmDate}  + {ts}Open Date{/ts}: {$caseDetails.case_start_date|crmDate}  {ts}ID{/ts}: {$caseID} @@ -104,10 +104,10 @@ - + {if $hasAccessToAllCases} @@ -131,16 +131,12 @@ {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))} {/if}
{$form.activity_type_id.label}
{$form.activity_type_id.html} 
{$form.add_activity_type_id.html} - + {ts}Print Report{/ts}
- {ts}Assign to Another Contact{/ts} + {ts}Assign to Another Contact{/ts}
- -
{include file="CRM/Case/Page/CustomDataView.tpl"} @@ -259,15 +255,6 @@ deleteCaseRoles('caseRoles-selector'); } - function printCaseReport( ) { - var asn = 'standard_timeline'; - var dataUrl = {/literal}"{crmURL p='civicrm/case/report/print' q='all=1&redact=0' h='0'}"{literal}; - dataUrl = dataUrl + '&cid={/literal}{$contactID}{literal}' - + '&caseID={/literal}{$caseID}{literal}' - + '&asn={/literal}' + asn + '{literal}'; - - window.location = dataUrl; - } {/literal} @@ -420,46 +407,6 @@ }); } - function viewRelatedCases( mainCaseID, contactID ) { - cj("#view-related-cases").show( ); - cj("#view-related-cases").dialog({ - title: "Related Cases", - modal: true, - width : "680px", - height: 'auto', - resizable: true, - bgiframe: true, - overlay: { - opacity: 0.5, - background: "black" - }, - - beforeclose: function(event, ui) { - cj(this).dialog("destroy"); - }, - - open:function() { - var dataUrl = {/literal}"{crmURL p='civicrm/contact/view/case' h=0 q="snippet=4" }"{literal}; - dataUrl = dataUrl + '&id=' + mainCaseID + '&cid=' +contactID + '&relatedCases=true&action=view&context=case&selectedChild=case'; - - cj.ajax({ - url : dataUrl, - async : false, - success : function(html){ - cj("#related-cases-content" ).html( html ); - } - }); - }, - - buttons: { - "Done": function() { - cj(this).dialog("close"); - cj(this).dialog("destroy"); - } - } - }); - } - {/literal} @@ -469,11 +416,11 @@ {ts}Other Relationships{/ts}
- + {capture assign=relUrl}{crmURL p='civicrm/contact/view/rel' q="action=add&reset=1&cid=`$contactId`&caseID=`$caseID`"}{/capture} {if $clientRelationships} @@ -486,8 +433,8 @@ {else}
- {capture assign=crmURL}{crmURL p='civicrm/contact/view/rel' q="action=add&reset=1&cid=`$contactId`&caseID=`$caseID`"}{/capture} - {ts 1=$crmURL}There are no Relationships entered for this client. You can add one.{/ts} + {capture assign=link}class="action-item" href="{$relUrl}"{/capture} + {ts 1=$link}There are no Relationships entered for this client. You can add one.{/ts}
{/if} {literal} @@ -946,17 +893,6 @@ function checkSelection( field ) { successAction = "confirm('{/literal}{ts escape='js'}Are you sure you want to add a set of scheduled activities to this case?{/ts}{literal}');"; break; - case 'new_activity' : - validationMessage = '{/literal}{ts escape="js"}Please select an activity type from the list.{/ts}{literal}'; - validationField = 'activity_type_id'; - if ( document.getElementById('activity_type_id').value == 3 ) { - successAction = "window.location='{/literal}{$newActivityEmailUrl}{literal}' + document.getElementById('activity_type_id').value"; - } - else { - successAction = "window.location='{/literal}{$newActivityUrl}{literal}' + document.getElementById('activity_type_id').value"; - } - break; - case 'case_report' : validationMessage = '{/literal}{ts escape="js"}Please select a report from the list.{/ts}{literal}'; validationField = 'report_id'; @@ -1050,16 +986,6 @@ function setSelectorClass( ) { }); } -function printCaseReport( ) { - var asn = 'standard_timeline'; - var dataUrl = {/literal}"{crmURL p='civicrm/case/report/print' q='all=1&redact=0' h='0'}"{literal}; - dataUrl = dataUrl + '&cid={/literal}{$contactID}{literal}' - + '&caseID={/literal}{$caseID}{literal}' - + '&asn={/literal}' + asn + '{literal}'; - - window.location = dataUrl; -} - {/literal} @@ -1073,7 +999,7 @@ function printCaseReport( ) { {/literal} + {include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"} {/if} {* view related cases if end *} -{include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"} -- 2.25.1