Hi,
I have a 3 tiered table structure for some config settings in my database
Object table - the parent of the settings that describes the settings and holds multiple "sets" of values
Sets table - a set of values that belong to an object
Values table - multiple value records that belong to a set
In my admin page I have the following code to generate the delete button in the gridview
array(
'class'=>'CButtonColumn',
'template'=>'{view}{update}{delete}', //($data->drawroundcount > 0 ? "{view}" : "{view}{update}{delete})',
'viewButtonUrl'=>'Yii::app()->createUrl("Settingconfigobj/view", array("id"=>$data->id))',
'updateButtonUrl'=>'Yii::app()->createUrl("Settingconfigobj/update", array("id"=>$data->id))',
'deleteButtonUrl'=>'Yii::app()->createUrl("Settingconfigobj/delete", array("id"=>$data->id))',
),
In the same grid I have an option to copy an Object along with the sets and values it contains which does call the copysettings action, here is the code for that:
/* COLUMN CODE FROM GRIDVIEW */
'class'=>'CButtonColumn',
'template'=>'{copy}',
'buttons'=>array(
'copy' => array(
'label' => 'COPY',
'url' => 'Yii::app()->createUrl("/settingconfigobj/copysettings", array("id"=>$data->id))',
'options'=>array('class'=>'to-copy'),
),
/* JQUERY TO LOAD INTO PAGE FOR COPY FUNCTION */
$confirm = 'jQuery("#settingconfigobj-grid a.to-copy").live("click",function() {
if(!confirm("Are you sure you want copy this item?")) return false;
var url = $(this).attr("href");
// do your post request here
$.post(url,function(res){
// alert(res);
});
return false;
});';
$cs = Yii::app()->clientScript;
$cs->registerScript('copyobj', $confirm, CClientScript::POS_READY);
Here is the controller action that should be getting called for the Delete action:
public function actionDelete($id)
{
$model = $this->loadModel($id);
$orgid = $model->orgid;
if($model->compcount > 0)
{
Yii::app()->user->setFlash('error', "Cannot delete Config Settings that is attached to a comp");
}
else {
try {
$transaction = $model->dbConnection->beginTransaction();
//delete all the values in each set first
$sets = Settingconfigset::model()->findAll('settingconfigid=:id', array(':id'=>$id));
foreach($sets as $set) {
Settingconfigvalue::model()->deleteAll('settingconfigsetid=:id', array(':id'=>$set->id));
}
//now delete the sets
Settingconfigset::model()->deleteAll('settingconfigid=:id', array(':id'=>$id));
//lastly, delete the actual ojbject
$model->delete();
$transaction->commit;
Yii::app()->user->setFlash('success', 'Deleted "'.$model->configname.'" successfully');
}
catch (Exception $ex) {
$transaction->rollback();
Yii::app()->user->setFlash('error', 'could not delete');
}
}
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'id'=>$orgid));
}
The page loads the default delete jquery code which works fine on other pages.
When I click the delete icon, I am prompted with the text from the jquery delete function, so this part is working. It doesnt seem to fire the actionDelete function from the controller tho. I dont see any flash messaging either.
Any help would be greatly appreciated.
Regards
Greg J