Problem With Refreshing Cjuidialog

Hi,

What I’m currently trying to do is that when I click on a clinkcolumn link in the cgridview, a cjuidialog pop-up form will appear. The form will consist of checkboxes and a submit button. When I check the checkbox and submit, I want it to update the database and the cjuidialog form to be refreshed so that the count on the form will increase.

I’m not sure how to go about doing it. But so far this is what I have tried and I’m not sure whether I’m on the right track.

Currently, after checking the checkbox, I can update the database through the controller. But when it goes into the controller, I can only redirect to the page whereby the cjuidialog is no longer there unless you click the link again. How to make it such that it updates the database and the cjuidialog still remains there and gets refreshed after the database update?

Index.php:




$this->widget('zii.widgets.grid.CGridView', array(

	'dataProvider'=>$dataProvider,

	'columns'=>array(

		array(

			'class'=>'CButtonColumn',

			'header'=>'Action',

			'buttons'=> array(

				'dialogFormButton'=>array(

					'label'=>'Dialog Form', 

					'url'=>'Yii::app()->createUrl("project/default/viewDialog", array("proj_id"=>$data->project_id))',

					'options'=>array(  

						'ajax'=>array(

							'type'=>'POST',

								// ajax post will use 'url' specified above 

							'url'=>"js:$(this).attr('href')", 

							'update'=>'#id_view',

						),

					),

				),

							

			),

			'template'=>'{dialogFormButton}',

		),

	),

));



DefaultController:




public function actionViewDialog()

{

	$proj_id=$_GET['proj_id'];

	

	if (Yii::app()->request->isAjaxRequest)

	{

		//render formDialog.php view

		$this->renderPartial('formDialog', 

			array(

			   'model'=>$this->loadProjectModel($proj_id),

			 ),false,false);

		//js-code to open the dialog    

		  if (!empty($_GET['asDialog'])) 

			echo CHtml::script('$("#dialog-view").dialog("open")'); //open the dialog

		Yii::app()->end();

		

	}

	else

	{

                //process cjuidialog form

		$autoIdAll = $_POST['autoId'];  

		if(count($autoIdAll)>0)

		{

			foreach($autoIdAll as $autoId)

			{

				... // logic codes

				

				//update to database

				if($model->save())

					echo 'ok';

				else

					throw new Exception("Sorry",500);

					

			}

		}

		

		$this->redirect(array('/project')); //redirect back to view page

			

		

	}

	

}



formDialog.php:




<?php 


$form=$this->beginWidget('CActiveForm', array(

    'enableAjaxValidation'=>true,

)); 


?>




<?php

$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'my-grid',

	'dataProvider'=>$dataProvider,

	'columns'=>array(

		array(

			'id'=>'autoId',

			'class'=>'CCheckBoxColumn',

			'header'=>'',

			'selectableRows'=>'2', 

		),

			

	),

));

	


?>


<script type="text/javascript">

function reloadGrid(data) {

    $.fn.yiiGridView.update('my-grid');

}

</script>


<div align="right">

<?php 

	echo CHtml::ajaxSubmitButton('Reject',array('Default/ViewDialog','act'=>'doReject'), array('success'=>'reloadGrid')); 

?>

</div>


<?php 

	$this->endWidget(); 

?>