It works thank you. I will open a new topic on how to include it using the
customization hook. Below a summary of the customization steps
modules->accounts->adapters-columns-> DeleteRelatedAccountListViewColumnAdapter
class DeleteRelatedAccountListViewColumnAdapter extends ListViewColumnAdapter
{
public function renderGridViewData()
{
return array(
'name' => $this->attribute,
'header' => '',
'value' => $this->resolveToRenderDeleteLink('$data->' . 'id'),
'type' => 'raw',
'htmlOptions' => array('class' => 'delete-opportunity-column')
);
}
protected function resolveToRenderDeleteLink($modelId)
{
$checkboxId = 'closeTask' . $modelId;
// Begin Not Coding Standard
$content = 'CHtml::link("Delete<span class='icon'></span>", "#",
array("class" => "remove",
"onclick" => "actionDeleteOpportunityFromRelation (this, '' .
$this->view->getRelationAttribName() . '',' . ''' .
$modelId . '',' . ''' .
$this->view->getRelationModelId() . ''' . ')"))';
Yii::app()->clientScript->registerScript('deleteOpportunityRelationFromListViewScript',
"
function actionDeleteOpportunityFromRelation(element,relName, opportunityId, accountId)
{
$.ajax({
url : '" . Yii::app()->createUrl('opportunities/default/DelRelAccFromAjax') . "?relName=' + relName + '&opportunityId=' + opportunityId + '&accountId=' + accountId ,
type : 'GET',
dataType : 'json',
success : function(data)
{
//remove row
$(element).parent().parent().remove();
},
error : function()
{
//todo: error call
}
});
}
",
CClientScript::POS_END);
// End Not Coding Standard
return $content;
}
}
modules->accounts->views->related->OpportunitiesRelatedListView.php Add the Following column in the related grid
array('cells' =>
array(
array(
'elements' => array(
array('attributeName' => 'null',
'type' => 'DeleteRelatedAccount',
),
),
),
)
),
And add the following functions
public function getRelationModelId()
{
return $this->params["relationModel"]->id;
}
public function getRelationAttribName()
{
return $this->getRelationAttributeName();
}
public function getRelationModuleId()
{
return $this->params["relationModuleId"];
}
public function getUniqueLayoutId()
{
return $this->uniqueLayoutId;
}
modules->accounts ->controllers->DefaultController.php Add the following function
public function actionDelRelAccFromAjax($relName,
$opportunityId,
$accountId)
{
if ($relName == 'account') {
$account = Account::GetById(intval($accountId));
ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($account);
$opportunity = Opportunity::GetById(intval($opportunityId));
$account->opportunities->remove($opportunity);
$account->save();
}
}
The result will be a button to as shown in the attached image