Confirmation on CButtonColumn

hi!!

I’m having a problem with CButtonColumn buttons.

My objective is, when i click the "remove" button, a dialog opens so the user can confirm his/her choice.

My code, until the moment:




?php 




if(isset($_GET['Community'])){

	$dataProvider->attributes = $_GET['Community'];

}


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

	'id'=>'community-grid',

	'dataProvider'=>$dataProvider->searchPerUser($model->id),

	'filter'=>$dataProvider,

	'columns'=>array(

		'id',

		//'photo',

		'name',

		//'description',

		//'founder_id',

		array(

			'name'=>'is_active',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("is_active")',

		),

		array(

			'name'=>'is_open',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("is_open")',

		),

		array(

			'name'=>'can_publish',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("can_publish")',

		),

		array(

			'name'=>'is_permanent',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("is_permanent")',

		),

		array(

			'name'=>'is_formal',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("is_formal")',

		),

		array(

			'name'=>'has_advanced_search',

			'filter'=>array(0=>'Não', 1=> 'Sim'),

			'value'=>'$data->getYesNo("has_advanced_search")',

		),

		array( 'class'=>'CButtonColumn',

			'template'=>'{modifyPermissions}{removeUser}',

			'buttons'=>array(

					'modifyPermissions' => array(

								    'label'=>'Modificar permissões do membro',     // text label of the button

								    'url'=>'Yii::app()->createUrl("/admin/userrights",array("id_user"=>'.$model->id.', "id_community"=>$data->id))',       // a PHP expression for generating the URL of the button

								    'imageUrl'=>'images/buttons/16x16/gif/69.gif',  // image URL of the button. If not set or false, a text link is used

								    'htmlOptions'=>array('title'=>'modificar permissões'), // HTML options for the button tag

								    'visible'=>'1',   // a PHP expression for determining whether the button is visible

								),

					'removeUser' => array(

								    'label'=>'Retirar da comunidade',

								    'url'=>'Yii::app()->createUrl("/admin/removeuserfromcommunity",array("id_user"=>'.$model->id.', "id_community"=>$data->id))',

								    'imageUrl'=>'images/buttons/16x16/gif/33.gif',

								    'htmlOptions'=>array('title'=>'retirar o utilizador da comunidade','onClick'=>"if(confirm('Tem a certeza que quer remover o utilizador da comunidade?'))alert('Removido');else alert('Cancelado')"),

								    'visible'=>'1',

								),

					

				)

		),

	),

));

 ?>



The problem is that no dialog is open when i click the button…

anyone?

Did you try

‘click’=>‘your js code’ ?

http://www.yiiframework.com/doc/api/CButtonColumn#buttons-detail

/Tommy




<?php




$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

    ),

));


echo 'dialog content here';


$this->endWidget('zii.widgets.jui.CJuiDialog');




$this->breadcrumbs=array(

	'Utilizadores'=>array('index'),

	$model->name,

);


$this->menu=array(

	array('label'=>'Listar utilizadores', 'url'=>array('/user/index')),

	array('label'=>'Criar utilizador', 'url'=>array('/user/create')),

	array('label'=>'Editar utilizador', 'url'=>array('/user/update', 'id'=>$model->id)),

	array('label'=>'Apagar utilizador', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Tem a certeza que deseja apagar este utilizador?')),

	array('label'=>'Gerir utilizadores', 'url'=>array('admin')),

	array('label'=>'Adicionar a uma comunidade', 'url'=>array('/admin/AddUserToCommunity', 'id_user'=>$model->id, 'type'=>'add-communities'))

);

?>


<h1>Utilizador <?php echo $model->username; ?></h1>


<div class="profile-photo">

	<?php echo CHtml::image($model->photo,'',array('width'=>100,'height'=>100))?>

</div>


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

	'data'=>$model,

	'attributes'=>array(

		'id',

		'id_clip',

		'username',

		//'password',

		'name',

		'photo',

		'location',

		'birthday',

		array(

			'name'=>'sex',

			'value'=>$model->sexWord(),

		),

	),

)); ?>







<?php 




if(isset($_GET['Community'])){

	$dataProvider->attributes = $_GET['Community'];

}


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

	'id'=>'community-grid',

	'dataProvider'=>$dataProvider->searchPerUser($model->id),

	'filter'=>$dataProvider,

	'columns'=>array(

		'id',

		//'photo',

		'name',

		//'description',

		//'founder_id',


		array( 'class'=>'CButtonColumn',

			'template'=>'{modifyPermissions}{removeUser}',

			'buttons'=>array(

					'modifyPermissions' => array(

								    'label'=>'Modificar permissões do membro',     // text label of the button

								    'url'=>'Yii::app()->createUrl("/admin/userrights",array("id_user"=>'.$model->id.', "id_community"=>$data->id))',       // a PHP expression for generating the URL of the button

								    'imageUrl'=>'images/buttons/16x16/gif/69.gif',  // image URL of the button. If not set or false, a text link is used

								    'htmlOptions'=>array('title'=>'modificar permissões'), // HTML options for the button tag

								    'visible'=>'1',   // a PHP expression for determining whether the button is visible

								),

					'removeUser' => array(

								    'label'=>'Retirar da comunidade',

								    'url'=>'Yii::app()->createUrl("/admin/removeuserfromcommunity",array("id_user"=>'.$model->id.', "id_community"=>$data->id))',

								    'imageUrl'=>'images/buttons/16x16/gif/33.gif',

									'click'=>'$("#mydialog").dialog("open"); return false;',

								    'htmlOptions'=>array('title'=>'retirar o utilizador da comunidade'),

								    'visible'=>'1',

								),

					

				)

		),

	),

));

 ?>



i stiiiiiill doesn’t show the dialog… :mellow:

I’m trying to use the CJuiDialog, the example in this page http://www.yiiframework.com/doc/api/CJuiDialog

the funny thing is that the echoed “aaaaa…” is shown in the webpage too!!! ::) Shouldn’t it only be displayed in the dialog??????

Try this




'click'=>'function(){$("#mydialog").dialog("open"); return false;}',



/Tommy

Thanks! Works perfectly now! :)

Another easy solution:




'mybutton'   => array(

   ...

   'click' => 'function() {if(!confirm("Are you sure?")) {return false;}}',

   'options'  => Array(

  	'class' => 'btn-your-button-class',

   ),

),



Bye