From 4cd3574431c86f36fb5a49550043567a12c81ced Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Sun, 17 Mar 2013 16:30:04 +0530 Subject: [PATCH] worked on CRM-12012, delete case roles for all the client if deleted for one. also move delete to ajax action and remove page reload --- CRM/Activity/Page/AJAX.php | 8 +++---- CRM/Case/Page/AJAX.php | 13 +++++++++++ CRM/Case/xml/Menu/Case.xml | 4 ++++ templates/CRM/Case/Form/CaseView.tpl | 32 ++++++++++++++++++++++++---- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 2cc9e18e9161..454f531f8a61 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -254,12 +254,12 @@ static function getCaseRoles() { foreach ($caseRelationships as $key => $row) { // view user links if ($caseRelationships[$key]['cid']) { - $caseRelationships[$key]['name'] = ''.$caseRelationships[$key]['name'].''; } // email column links/icon if ($caseRelationships[$key]['email']) { - $caseRelationships[$key]['email'] = ' + $caseRelationships[$key]['email'] = ' '; } // edit links @@ -267,12 +267,12 @@ static function getCaseRoles() { switch($caseRelationships[$key]['source']){ case 'caseRel': $caseRelationships[$key]['actions'] = - '
  
'; + '
  
'; break; case 'caseRoles': $caseRelationships[$key]['actions'] = - '
'; + '
'; break; } } else { diff --git a/CRM/Case/Page/AJAX.php b/CRM/Case/Page/AJAX.php index 00c70611cd8e..860566625c39 100644 --- a/CRM/Case/Page/AJAX.php +++ b/CRM/Case/Page/AJAX.php @@ -182,5 +182,18 @@ function addClient() { echo json_encode(TRUE); CRM_Utils_System::civiExit(); } + + /** + * Function to delete relationships specific to case and relationship type + */ + static function deleteCaseRoles() { + $caseId = CRM_Utils_Type::escape($_POST['case_id'], 'Integer'); + $relType = CRM_Utils_Type::escape($_POST['rel_type'], 'Integer'); + + $sql = "DELETE FROM civicrm_relationship WHERE case_id={$caseId} AND relationship_type_id={$relType}"; + CRM_Core_DAO::executeQuery($sql); + + CRM_Utils_System::civiExit(); + } } diff --git a/CRM/Case/xml/Menu/Case.xml b/CRM/Case/xml/Menu/Case.xml index be30bf1dbafe..5d5e622429a3 100644 --- a/CRM/Case/xml/Menu/Case.xml +++ b/CRM/Case/xml/Menu/Case.xml @@ -135,4 +135,8 @@ civicrm/case/ajax/details CRM_Case_Page_AJAX::CaseDetails + + civicrm/ajax/delcaserole + CRM_Case_Page_AJAX::deleteCaseRoles + diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 7306f212e081..8618bcaab1d1 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -187,9 +187,34 @@ var oTable; cj(function() { + cj().crmAccordions(); buildCaseRoles(false); }); + function deleteCaseRoles(caseselector) { + cj('.case-role-delete').click(function(){ + var caseID = cj(this).attr('case_id'); + var relType = cj(this).attr('rel_type'); + + CRM.confirm(function() { + var postUrl = {/literal}"{crmURL p='civicrm/ajax/delcaserole' h=0 }"{literal}; + cj.post( postUrl, { + rel_type: relType, case_id: caseID, key: {/literal}"{crmKey name='civicrm/ajax/delcaserole'}"{literal}}, + function(data) { + // reloading datatable + var oTable = cj('#' + caseselector).dataTable(); + oTable.fnDraw(); + } + ); + } + ,{ + title: ts('Delete case role'), + message: ts('Are you sure you want to delete this case role.') + }); + return false; + }); + } + function buildCaseRoles(filterSearch) { if(filterSearch) { oTable.fnDestroy(); @@ -243,6 +268,9 @@ cj("#caseRoles-selector td:last-child").each( function( ) { cj(this).parent().addClass(cj(this).text() ); }); + + // also bind delete action once rows are rendered + deleteCaseRoles('caseRoles-selector'); } function printCaseReport( ) { @@ -254,10 +282,6 @@ window.location = dataUrl; } - - cj(function() { - cj().crmAccordions(); - }); {/literal}