Yii Framework Forum: how to make button like delete button - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to make button like delete button Rate Topic: -----

#1 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 12:35 AM

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?'),
	),
)


belajar itu mudah..
0

#2 User is offline   rootbear 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 222
  • Joined: 17-June 11

Posted 19 April 2012 - 12:49 AM

ajaxlink?

read this thread.
I enjoy the Yii.sy coding life here.
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 19 April 2012 - 01:24 AM

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

#4 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 01:33 AM

View Postbennouna, on 19 April 2012 - 01:24 AM, said:

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...
belajar itu mudah..
0

#5 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 01:54 AM

View Postrootbear, on 19 April 2012 - 12:49 AM, said:

ajaxlink?

read this thread.


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..
belajar itu mudah..
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,074
  • Joined: 16-February 11
  • Location:Japan

Posted 19 April 2012 - 03:54 AM

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().
0

#7 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 04:15 AM

View Postsoftark, on 19 April 2012 - 03:54 AM, said:

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
belajar itu mudah..
0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,074
  • Joined: 16-February 11
  • Location:Japan

Posted 19 April 2012 - 05:20 AM

Use CClientScript::registerScript().
http://www.yiiframew...erScript-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.
0

#9 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 06:36 AM

View Postsoftark, on 19 April 2012 - 05:20 AM, said:

Use CClientScript::registerScript().
http://www.yiiframew...erScript-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',


belajar itu mudah..
0

#10 User is offline   rootbear 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 222
  • Joined: 17-June 11

Posted 19 April 2012 - 04:01 PM

just created a small extension xbuttoncolumn, take a look it might be what you wanted
I enjoy the Yii.sy coding life here.
1

#11 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 09:09 PM

View Postrootbear, on 19 April 2012 - 04:01 PM, said:

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


thanks...
it's very usefull..
belajar itu mudah..
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users