Hey ifdattic,
I am using your extension and I really like it. Now that I got update and create action working I am struggeling a bit with the actionDelete, would be great if you can assist me somehow with it.
I started editing the controller (setFlash, actions are defined) and this is the delete action:
public function actionDelete()
{
$model = $this->loadModel();
if( Yii::app()->request->isAjaxRequest )
{
// Stop jQuery from re-initialization
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
if( isset( $_POST['action'] ) && $_POST['action'] == 'confirmDelete' )
{
$model->delete();
echo CJSON::encode( array(
'status' => 'success',
'content' => 'Deleted succussfully',
));
exit;
}
else if( isset( $_POST['action'] ) )
{
echo CJSON::encode( array(
'status' => 'canceled',
'content' => 'Deletion canceled',
));
exit;
}
else
{
echo CJSON::encode( array(
'status' => 'failure',
'content' => $this->renderPartial( 'delete', array(
'model' => $model ), true, true ),
));
exit;
}
}
else
{
if( isset( $_POST['confirmDelete'] ) )
{
$model->delete();
$this->redirect( array( 'admin' ) );
}
else if( isset( $_POST['denyDelete'] ) )
$this->redirect( array( 'view', 'id' => $model->id ) );
else
$this->render( 'delete', array( 'model' => $model ) );
}
}
then from what I’ve taken from the wiki page is that I need to edit my CGridView>CButtonColumn like this:
'class' => 'CButtonColumn',
'template'=>'{view} {update} {delete} {add Note} {ToDo}',
'deleteButtonUrl' => 'Yii::app()->createUrl(
"/tool/dTool/delete",
array( "id" => $data->primaryKey ) )',
'buttons' => array(
// Delete button
'delete' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/adjokerHome/icons/Delete.png',
'click' => "function( e ){
e.preventDefault();
$( '#update-dialog' ).children( ':eq(0)' ).empty(); // Stop auto POST
updateDialog( $( this ).attr( 'href' ) );
$( '#update-dialog' )
.dialog( { title: 'Delete confirmation' } )
.dialog( 'open' ); }",
'options' => array(
'data-update-dialog-title' => Yii::t( 'app', 'Delete confirmation' ),
),
),
and last adding a view, I called it "delete" and placed it into the views/controllerXYZ folder:
<?php $form = $this->beginWidget( 'CActiveForm', array(
'id' => 'location-delete-form',
'enableAjaxValidation' => false,
'focus' => '#confirmDelete',
)); ?>
<div class="buttons">
<?php
echo CHtml::submitButton( 'Yes', array( 'name' => 'deleteConfirmed' ) );
echo CHtml::submitButton( 'No', array( 'name' => 'deleteCanceled' ) );
?>
</div>
<?php $this->endWidget(); ?>
but for some reason either the dialog is showing up nor the model gets deleted.
Do you have any idea? Am I doing anything wrong?
Best Regards,
-Seb