From c91df8b4e80b489686a6fdfbeb18c7a1cb3a999d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 21 Mar 2014 17:26:44 -0400 Subject: [PATCH] CRM-13966 - Remove autocompletes and improve case ui --- CRM/Activity/Page/AJAX.php | 35 ++- CRM/Case/Form/CaseView.php | 2 +- CRM/Contact/Page/AJAX.php | 22 +- templates/CRM/Case/Form/CaseView.js | 140 +++++++-- templates/CRM/Case/Form/CaseView.tpl | 286 ++---------------- .../CRM/Case/xml/configuration/Settings.xml | 2 +- 6 files changed, 181 insertions(+), 306 deletions(-) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 6210224d38..e18d452750 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -248,33 +248,40 @@ class CRM_Activity_Page_AJAX { // set user name, email and edit columns links // idx will count number of current row / needed by edit links $idx = 1; - foreach ($caseRelationships as $key => $row) { + foreach ($caseRelationships as &$row) { + // Get rid of the "
(Case Manager)" from label + list($typeLabel) = explode('<', $row['relation']); // view user links - if ($caseRelationships[$key]['cid']) { - $caseRelationships[$key]['name'] = ''.$caseRelationships[$key]['name'].''; + if ($row['cid']) { + $row['name'] = ''.$row['name'].''; } // email column links/icon - if ($caseRelationships[$key]['email']) { - $caseRelationships[$key]['email'] = ' - '; + if ($row['email']) { + $row['email'] = ''; } // edit links if ($hasAccessToAllCases) { - switch($caseRelationships[$key]['source']){ + switch($row['source']){ case 'caseRel': - $caseRelationships[$key]['actions'] = - ' - '; + $row['actions'] = + ''. + ''. + ''. + ''. + ''. + ''; break; case 'caseRoles': - $caseRelationships[$key]['actions'] = - ''; + $row['actions'] = + ''. + ''. + ''; break; } } else { - $caseRelationships[$key]['actions'] = ''; + $row['actions'] = ''; } $idx++; } diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index afee03c000..b8124d2830 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -412,7 +412,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { foreach ($relType as $k => $v) { $roleTypes[substr($k, 0, strpos($k, '_'))] = $v; } - $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes); + $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty')); $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); if (is_array($hookCaseSummary)) { diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 1ea4489e60..1be7e61152 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -242,10 +242,10 @@ class CRM_Contact_Page_AJAX { } static function relationship() { - $relType = CRM_Utils_Array::value('rel_type', $_REQUEST); - $relContactID = CRM_Utils_Array::value('rel_contact', $_REQUEST); - $relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST); // this used only to determine add or update mode - $caseID = CRM_Utils_Array::value('case_id', $_REQUEST); + $relType = CRM_Utils_Request::retrieve('rel_type', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); + $relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); + $relationshipID = CRM_Utils_Array::value('rel_id', $_REQUEST); // this used only to determine add or update mode + $caseID = CRM_Utils_Request::retrieve('case_id', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); // check if there are multiple clients for this case, if so then we need create // relationship and also activities for each contacts @@ -253,6 +253,8 @@ class CRM_Contact_Page_AJAX { // get case client list $clientList = CRM_Case_BAO_Case::getCaseClients($caseID); + $ret = array('is_error' => 0); + foreach($clientList as $sourceContactID) { $relationParams = array( 'relationship_type_id' => $relType . '_a_b', @@ -283,18 +285,22 @@ class CRM_Contact_Page_AJAX { // create new or update existing relationship $return = CRM_Contact_BAO_Relationship::create($relationParams, $relationIds); - $status = 'process-relationship-fail'; if (!empty($return[4][0])) { $relationshipID = $return[4][0]; - $status = 'process-relationship-success'; //create an activity for case role assignment.CRM-4480 CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $relationshipID, $relContactID); } + else { + $ret = array( + 'is_error' => 1, + 'error_message' => ts('The relationship type definition for the case role is not valid for the client and / or staff contact types. You can review and edit relationship types at Administer >> Option Lists >> Relationship Types.', + array(1 => CRM_Utils_System::url('civicrm/admin/reltype', 'reset=1'))) + ); + } } - $relation['status'] = $status; - echo json_encode($relation); + echo json_encode($ret); CRM_Utils_System::civiExit(); } diff --git a/templates/CRM/Case/Form/CaseView.js b/templates/CRM/Case/Form/CaseView.js index 1eb7e27b9d..6a9e8ea66d 100644 --- a/templates/CRM/Case/Form/CaseView.js +++ b/templates/CRM/Case/Form/CaseView.js @@ -1,13 +1,19 @@ // https://civicrm.org/licensing (function($, CRM) { - function refresh() { - $('#crm-main-content-wrapper').crmSnippet('refresh'); + function refresh(table) { + if (table) { + $(table).dataTable().fnDraw(); + } else { + $('#crm-main-content-wrapper').crmSnippet('refresh'); + } } - function open(url, options) { + function open(url, options, table) { if (CRM.config.ajaxPopupsEnabled) { - CRM.loadForm(url, options).on('crmFormSuccess', refresh); + CRM.loadForm(url, options).on('crmFormSuccess', function() { + refresh(table); + }); } else { window.location.href = url; @@ -26,37 +32,105 @@ * The CaseView form includes some extra fields which are meant to open in a dialog. * We stash them initially and pop them up as needed * TODO: Creating a separate form class for each of these and opening them as standard popup links would be simpler and more reusable - * @type {*} + * @type {pre, post} */ - var detached = {}, - miniForms = { - '#manageTags': function() { - var tagsChecked = $("#manageTags #tags").select2('val').join(','), + var miniForms = { + '#manageTagsDialog': { + post: function(data) { + var tagsChecked = $("#tags", this).select2('val').join(','), tagList = {}, url = CRM.url('civicrm/case/ajax/processtags'); - $("#manageTags input[name^=case_taglist]").each(function() { + $("input[name^=case_taglist]", this).each(function() { var tsId = $(this).attr('id').split('_'); tagList[tsId[2]] = $(this).val(); }); - var data = { + $.extend(data, { case_id: caseId(), tag: tagsChecked, - taglist: tagList, - key: $(this).data('key') - }; + taglist: tagList + }); return $.post(url, data); - }, - '#merge_cases': function() { + } + }, + '#mergeCasesDialog': { + post: function(data) { if ($('select#merge_case_id').val()) { $('select#merge_case_id').appendTo('form#CaseView'); $('[name="_qf_CaseView_next_merge_case"]').click(); + } else { + return false; + } + } + }, + '#deleteCaseRoleDialog': { + post: function(data) { + data.case_id = caseId(); + return $.post(CRM.url('civicrm/ajax/delcaserole'), data); + } + }, + '#addCaseRoleDialog': { + pre: function() { + $('[name=role_type]', this).val('').change(); + $('[name=add_role_contact_id]', this).val('').crmEntityRef({create: true, api: {params: {contact_type: 'Individual'}}}); + }, + post: function(data) { + var contactID = $('[name=add_role_contact_id]').val(), + relType = $('[name=role_type]').val(); + if (contactID && relType) { + $.extend(data, { + case_id: caseId(), + rel_contact: contactID, + rel_type: relType, + contact_id: contactId() + }); + return $.post(CRM.url('civicrm/ajax/relation'), data); + } + return false; + } + }, + '#editCaseRoleDialog': { + pre: function() { + $('[name=edit_role_contact_id]', this).val('').crmEntityRef({create: true, api: {params: {contact_type: 'Individual'}}}); + }, + post: function(data) { + data.rel_contact = $('[name=edit_role_contact_id]').val(); + if (data.rel_contact) { + $.extend(data, { + case_id: caseId(), + contact_id: contactId() + }); + return $.post(CRM.url('civicrm/ajax/relation'), data); } + return false; + } + }, + '#addClientDialog': { + pre: function() { + $('[name=add_client_id]', this).val('').crmEntityRef({create: true}); + }, + post: function(data) { + data.contactID = $('[name=add_client_id]').val(); + if (data.contactID) { + data.caseID = caseId(); + return $.post(CRM.url('civicrm/case/ajax/addclient'), data); + } + return false; + } + }, + '#addMembersToGroupDialog': { + pre: function() { + $('[name=add_member_to_group_contact_id]', this).val('').crmEntityRef({create: true}); }, - '#deleteCaseRole': function() { - var params = $.extend({case_id: caseId()}, $(this).data()); - return $.post(CRM.url('civicrm/ajax/delcaserole'), params); + post: function(data) { + data.contact_id = $('[name=add_member_to_group_contact_id]').val(); + if (data.contact_id) { + return CRM.api3('group_contact', 'create', data); + } + return false; } - }; + } + }, + detached = {}; function detachMiniForms() { detached = {}; @@ -80,7 +154,7 @@ title: $('option:first', this).text(), message: ts('Add the %1 set of scheduled activities to this case?', {1: '' + $('option:selected', this).text() + ''}) }) - .on('crmConfirmYes', function () { + .on('crmConfirmYes', function() { $('[name=_qf_CaseView_next]').click(); }) .on('crmConfirmNo', function() { @@ -105,15 +179,30 @@ $el = $(this), target = $el.attr('href'); function submit() { - var submission = miniForms[target].call($el[0]); + // Call post function with dialog as context and link data as param + var submission = miniForms[target].post.call(dialog[0], $.extend({}, $el.data())); + // Function should return a deferred object if (submission) { dialog.parent().block(); - submission.done(function() { + submission.done(function(data) { dialog.dialog('close'); - refresh(); + var table = $el.closest('table.dataTable'); + refresh(table.length ? table : $el.attr('rel')); + if ($.isPlainObject(data) && data.is_error && data.error_message) { + CRM.alert(data.error_message, ts('Error'), 'error'); + } }); return false; } + // Validation failed - show an error msg on empty fields + else if (submission === false) { + $(':input', dialog).not('.select2-container *').each(function() { + if (!$(this).val()) { + $(this).crmError(ts('Please select a value')); + } + }) + } + return submission; } dialog = CRM.confirm(submit, { title: $(this).attr('title') || $(this).text(), @@ -121,7 +210,8 @@ close: function() { detached[target] = $(target, dialog).detach(); $(dialog).dialog('destroy').remove(); - } + }, + open: miniForms[target].pre }); return false; }); diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index c464d990e6..97d653462c 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -43,9 +43,12 @@ {foreach from=$caseRoles.client item=client name=clients} {$client.display_name}{if not $smarty.foreach.clients.last},   {/if} {/foreach} - - + + +
+ +
{if $hasRelatedCases} {/if} @@ -119,9 +122,9 @@ {/if} {if $mergeCases} - {ts}Merge Case{/ts} + {ts}Merge Case{/ts} {$form._qf_CaseView_next_merge_case.html} - + {$form.merge_case_id.html} {/if} @@ -144,10 +147,21 @@ {if $hasAccessToAllCases} +
+
{$form.role_type.label}
+
{$form.role_type.html}

+
+
{/if} +
+
+
+
+ @@ -160,7 +174,7 @@
{ts}Case Role{/ts}
-
+
{ts}Are you sure you want to delete this case role?{/ts}
@@ -231,152 +245,6 @@ {/literal}
-
- {ts}Begin typing last name of contact.{/ts}
- - -
- -{literal} - -{/literal} {if $hasAccessToAllCases}