From 3c0b6a408b43c445479c26dd56e7d3de5f062c99 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 17 Jul 2014 13:09:56 +0100 Subject: [PATCH] CRM-15003 - Allow autocomplete to select closed cases --- CRM/Case/BAO/Case.php | 13 +++++++++---- CRM/Case/Page/AJAX.php | 6 ++++-- css/civicrm.css | 3 ++- js/Common.js | 8 ++++---- templates/CRM/Activity/Form/Task/FileOnCase.tpl | 4 ++++ templates/CRM/Case/Form/Activity/LinkCases.tpl | 4 ++++ templates/CRM/Case/Form/ActivityToCase.tpl | 4 ++++ 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 74233ba5ed..0ca273ae2f 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -2038,9 +2038,9 @@ SELECT civicrm_contact.id as casemanager_id, * * @return array of case and related data keyed on case id */ - static function getUnclosedCases($params = array(), $excludeCaseIds = array(), $excludeDeleted = TRUE) { + static function getUnclosedCases($params = array(), $excludeCaseIds = array(), $excludeDeleted = TRUE, $includeClosed = FALSE) { //params from ajax call. - $where = array('( ca.end_date is null )'); + $where = array($includeClosed ? '(1)' : '(ca.end_date is null)'); if ($caseType = CRM_Utils_Array::value('case_type', $params)) { $where[] = "( civicrm_case_type.title LIKE '%$caseType%' )"; } @@ -2079,15 +2079,18 @@ SELECT civicrm_contact.id as casemanager_id, ca.id, ca.subject as case_subject, civicrm_case_type.title as case_type, - ca.start_date as start_date + ca.start_date as start_date, + ca.end_date as end_date, + ca.status_id FROM civicrm_case ca INNER JOIN civicrm_case_contact cc ON ca.id=cc.case_id INNER JOIN civicrm_contact c ON cc.contact_id=c.id INNER JOIN civicrm_case_type ON ca.case_type_id = civicrm_case_type.id WHERE {$whereClause} - ORDER BY c.sort_name + ORDER BY c.sort_name, ca.end_date {$limitClause} "; $dao = CRM_Core_DAO::executeQuery($query); + $statuses = CRM_Case_PseudoConstant::caseStatus(); $unclosedCases = array(); while ($dao->fetch()) { if ($doFilterCases && !array_key_exists($dao->id, $filterCases)) { @@ -2098,7 +2101,9 @@ SELECT civicrm_contact.id as casemanager_id, 'case_type' => $dao->case_type, 'contact_id' => $dao->contact_id, 'start_date' => $dao->start_date, + 'end_date' => $dao->end_date, 'case_subject' => $dao->case_subject, + 'case_status' => $statuses[$dao->status_id], ); } $dao->free(); diff --git a/CRM/Case/Page/AJAX.php b/CRM/Case/Page/AJAX.php index 7b466e7f09..c5033fdd46 100644 --- a/CRM/Case/Page/AJAX.php +++ b/CRM/Case/Page/AJAX.php @@ -50,12 +50,14 @@ class CRM_Case_Page_AJAX { if (!empty($_GET['excludeCaseIds'])) { $excludeCaseIds = explode(',', CRM_Utils_Type::escape($_GET['excludeCaseIds'], 'String')); } - $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds); + $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds, TRUE, TRUE); $results = array(); foreach ($unclosedCases as $caseId => $details) { $results[] = array( 'id' => $caseId, - 'text' => $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')', + 'label' => $details['sort_name'] . ' - ' . $details['case_type'] . ($details['end_date'] ? ' (' . ts('closed') . ')' : ''), + 'label_class' => $details['end_date'] ? 'strikethrough' : '', + 'description' => array($details['case_subject'] . ' (' . $details['case_status'] . ')'), 'extra' => $details, ); } diff --git a/css/civicrm.css b/css/civicrm.css index bdb6defb4d..ccad1be529 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -4714,7 +4714,8 @@ span.crm-status-icon { background-position: -101px -222px;background-image: url("../i/icons/jquery-ui-3E3E3E.gif"); } -.crm-container .survey-completed { +.crm-container .survey-completed, +.crm-container .strikethrough { text-decoration: line-through; } diff --git a/js/Common.js b/js/Common.js index 028875f9f2..da542f2a14 100644 --- a/js/Common.js +++ b/js/Common.js @@ -348,7 +348,7 @@ CRM.strings = CRM.strings || {}; } }, minimumInputLength: 1, - formatResult: formatSelect2Result, + formatResult: CRM.utils.formatSelect2Result, formatSelection: function(row) { return row.label; }, @@ -441,7 +441,7 @@ CRM.strings = CRM.strings || {}; }); }; - function formatSelect2Result(row) { + CRM.utils.formatSelect2Result = function (row) { var markup = '
'; if (row.image !== undefined) { markup += '
'; @@ -449,14 +449,14 @@ CRM.strings = CRM.strings || {}; else if (row.icon_class) { markup += '
'; } - markup += '
' + row.label + '
'; + markup += '
' + row.label + '
'; markup += '
'; $.each(row.description || [], function(k, text) { markup += '

' + text + '

'; }); markup += '
'; return markup; - } + }; function formatSelect2CreateLinks($el) { var diff --git a/templates/CRM/Activity/Form/Task/FileOnCase.tpl b/templates/CRM/Activity/Form/Task/FileOnCase.tpl index 14a415d4da..6049c453bc 100644 --- a/templates/CRM/Activity/Form/Task/FileOnCase.tpl +++ b/templates/CRM/Activity/Form/Task/FileOnCase.tpl @@ -50,6 +50,10 @@ CRM.$(function($) { $('input[name=unclosed_case_id]', $form).crmSelect2({ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal}, minimumInputLength: 1, + formatResult: CRM.utils.formatSelect2Result, + formatSelection: function(row) { + return row.label; + }, ajax: { url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal}, data: function(term) { diff --git a/templates/CRM/Case/Form/Activity/LinkCases.tpl b/templates/CRM/Case/Form/Activity/LinkCases.tpl index b98ebfd2d7..3e1b00f392 100644 --- a/templates/CRM/Case/Form/Activity/LinkCases.tpl +++ b/templates/CRM/Case/Form/Activity/LinkCases.tpl @@ -37,6 +37,10 @@ $('input[name=link_to_case_id]', $form).crmSelect2({ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal}, minimumInputLength: 1, + formatResult: CRM.utils.formatSelect2Result, + formatSelection: function(row) { + return row.label; + }, ajax: { url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal}, data: function(term) { diff --git a/templates/CRM/Case/Form/ActivityToCase.tpl b/templates/CRM/Case/Form/ActivityToCase.tpl index c54400fa54..1f5a9da24b 100644 --- a/templates/CRM/Case/Form/ActivityToCase.tpl +++ b/templates/CRM/Case/Form/ActivityToCase.tpl @@ -49,6 +49,10 @@ $('input[name=file_on_case_unclosed_case_id]', '#fileOnCaseDialog').crmSelect2({ placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal}, minimumInputLength: 1, + formatResult: CRM.utils.formatSelect2Result, + formatSelection: function(row) { + return row.label; + }, ajax: { url: {/literal}"{crmURL p='civicrm/case/ajax/unclosed' h=0}"{literal}, data: function(term) { -- 2.25.1