Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worked on CRM-12012, delete case roles for all the client if deleted for... #170

Merged
merged 1 commit into from
Mar 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CRM/Activity/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,25 @@ static function getCaseRoles() {
foreach ($caseRelationships as $key => $row) {
// view user links
if ($caseRelationships[$key]['cid']) {
$caseRelationships[$key]['name'] = '<a href='.CRM_Utils_System::url('civicrm/contact/view',
$caseRelationships[$key]['name'] = '<a href='.CRM_Utils_System::url('civicrm/contact/view',
'action=view&reset=1&cid='.$caseRelationships[$key]['cid']).'>'.$caseRelationships[$key]['name'].'</a>';
}
// email column links/icon
if ($caseRelationships[$key]['email']) {
$caseRelationships[$key]['email'] = '<a href="'.CRM_Utils_System::url('civicrm/contact/view/activity', 'action=reset=1&action=add&atype=3&cid='.$caseRelationships[$key]['cid']).'" title="compose and send an email"><div class="icon email-icon" title="compose and send an email"></div>
$caseRelationships[$key]['email'] = '<a href="'.CRM_Utils_System::url('civicrm/contact/view/activity', 'action=reset=1&action=add&atype=3&cid='.$caseRelationships[$key]['cid']).'" title="compose and send an email"><div class="icon email-icon" title="compose and send an email"></div>
</a>';
}
// edit links
if ($hasAccessToAllCases) {
switch($caseRelationships[$key]['source']){
case 'caseRel':
$caseRelationships[$key]['actions'] =
'<a href="#" title="edit case role" onclick="createRelationship( '.$caseRelationships[$key]['relation_type'].', '.$caseRelationships[$key]['cid'].', '.$caseRelationships[$key]['rel_id'].', '.$idx.', \''.$caseRelationships[$key]['relation'].'\' );return false;"><div class="icon edit-icon" ></div></a>&nbsp;&nbsp;<a href="'.CRM_Utils_System::url('civicrm/contact/view/rel', 'action=delete&reset=1&cid='. $caseRelationships[$key]['client_id'].'&id='.$caseRelationships[$key]['rel_id'].'&caseID='.$caseID.'').'" onclick = "if (confirm(\'Are you sure you want to remove this person from their case role?\') ) this.href+=\'&confirmed=1\'; else return false;"><div class="icon delete-icon" title="remove contact from case role"></div></a>';
'<a href="#" title="edit case role" onclick="createRelationship( '.$caseRelationships[$key]['relation_type'].', '.$caseRelationships[$key]['cid'].', '.$caseRelationships[$key]['rel_id'].', '.$idx.', \''.$caseRelationships[$key]['relation'].'\' );return false;"><div class="icon edit-icon" ></div></a>&nbsp;&nbsp;<a href="#" class="case-role-delete" case_id="'.$caseID.'" rel_type="'.$caseRelationships[$key]['relation_type'].'"><div class="icon delete-icon" title="remove contact from case role"></div></a>';
break;

case 'caseRoles':
$caseRelationships[$key]['actions'] =
'<a href="#" title="edit case role" onclick="createRelationship( '.$caseRelationships[$key]['relation_type'].', null, null, '.$idx.', \''.$caseRelationships[$key]['relation'].'\');return false;"><div class="icon edit-icon"></div></a>';
'<a href="#" title="edit case role" onclick="createRelationship('.$caseRelationships[$key]['relation_type'].', null, null, '.$idx.', \''.$caseRelationships[$key]['relation'].'\');return false;"><div class="icon edit-icon"></div></a>';
break;
}
} else {
Expand Down
13 changes: 13 additions & 0 deletions CRM/Case/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

4 changes: 4 additions & 0 deletions CRM/Case/xml/Menu/Case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@
<path>civicrm/case/ajax/details</path>
<page_callback>CRM_Case_Page_AJAX::CaseDetails</page_callback>
</item>
<item>
<path>civicrm/ajax/delcaserole</path>
<page_callback>CRM_Case_Page_AJAX::deleteCaseRoles</page_callback>
</item>
</menu>
32 changes: 28 additions & 4 deletions templates/CRM/Case/Form/CaseView.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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( ) {
Expand All @@ -254,10 +282,6 @@

window.location = dataUrl;
}

cj(function() {
cj().crmAccordions();
});
</script>
{/literal}
</div><!-- /.crm-accordion-body -->
Expand Down