how to make button like delete button

how to make a confirmation message like delete button in admin page.

i want make a confirm button. when i click this button, that button will change status in database to 1.

and i won’t the page reload all, but just reload gridview only.

can someone help me for this problem?

this is my code




'buttons'=>array(

        'accept'=>array(

	'imageUrl'=>Yii::app()->request->baseUrl.'/image/check.png',                          

        'url' => 'Yii::app()->createUrl("/adsBanner/accept", array("id" => $data->id_ads_banner))',

        'options'=>array('confirm'=>'Are you sure want to quit?'),

	),

)




ajaxlink?

read this thread.

The delete button code is itself a good start, you should study the code behind it. I mean in the view and the controller.

i should study the code behind it, but stilll not working…

i want to make button like delete button. i make this in CButtonColumn.

this is my view


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

	'id'=>'ads-banner-grid',

	'dataProvider'=>$model->pending(),

	'filter'=>$model,

	'columns'=>array(

		array(

		'class'=>'CButtonColumn',

		'template'=>'{view}{accept}',

		'buttons'=>array(

			'accept'=>array(

				'imageUrl'=>Yii::app()->request->baseUrl.'/images/check.png',                          

                                'url' => 'Yii::app()->createUrl("/adsBanner/accept", array("id" => $data->id_ads_banner))',

                                'options'=>array('confirm'=>'Are you sure want to quit?'),

				),

			)

		),

and this is my controller.




public function actionAccept($id)

{

	$model=$this->loadModel($id);

	$model->status = 1;

	$model->id_admin = Yii::app()->user->getState('id_admin');

	if($model->save())

	{

		$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('pending'));

	}

	else

	{

		echo "<script type='text/javascript'>alert('Data can't modify at this time, please try again in few minutes')</script>";

	}

}



in this case when i click accept button, the page will be reload,…

this is not i want, i want when i click accept button just reload gridview, not page.

somebody help me…

Hi,




jQuery('#nns-ticket-grid a.delete').live('click',function() {

	if(!confirm('Are you sure?')) return false;

	var th=this;

	var afterDelete=function(){};

	$.fn.yiiGridView.update('nns-ticket-grid', {

		type:'POST',

		url:$(this).attr('href'),

		data:{ 'YII_CSRF_TOKEN':'49cb016b8bb156888586ab4e1640c8636ab3e083' },

		success:function(data) {

			$.fn.yiiGridView.update('nns-ticket-grid');

			afterDelete(th,true,data);

		},

		error:function(XHR) {

			return afterDelete(th,false,XHR);

		}

	});

	return false;

});



This is a javascript fragment that I have found in the html output of a page that has a grid.

As you know, this is for the delete button.

The code is not written manually, but generated automatically by Yii.

You may find almost the same code in the html output of your own.

So why don’t you write your own version of code for your ‘accept’ button?

It’s not that complicated. :)

And note that your actionAccept() should behave like actionDelete().

thanks for fast reply.

but where I should put that code??

i’m beginner in yii

Use CClientScript::registerScript().

http://www.yiiframework.com/doc/api/1.1/CClientScript/#registerScript-detail

You can find an example in ‘admin.php’ view file of Gii generated CRUD.




Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('some-data-grid', {

		data: $(this).serialize()

	});

	return false;

});

");



[EDIT]

The code above is just for illustrating the usage of CClientScript::registerScript. It doesn’t have any meaning with your ‘accept’ button issue.

thank you.

i use your code like this in view file




	'columns'=>array(

	array(

		'class'=>'CButtonColumn',

		'template'=>'{view}{accept}',

		'buttons'=>array(

				'accept'=>array(

				'imageUrl'=>Yii::app()->request->baseUrl.'/images/check.png',                          

                                'url' => 'Yii::app()->createUrl("/adsBanner/accept", array("id" => $data->id_ads_banner))',

                      		'click'=>'function(){if(!confirm("Are you sure accept this banner?")) return false;

							var th = this;

							var afterUpdate = function(){};

							$.fn.yiiGridView.update("ads-banner-grid", {

								type:"POST",

								url:$(this).attr("href"),

								success:function(data) {

									$.fn.yiiGridView.update("ads-banner-grid");

									afterUpdate(th,true);

								},

									error:function(XHR) {

									return afterUpdate(th,false,XHR);

									}

								});

							return false;

							}',

				),

			)

		),

		'id_ads_banner',




just created a small extension xbuttoncolumn, take a look it might be what you wanted

thanks…

it’s very usefull…