Skip to content

Instantly share code, notes, and snippets.

@luislobo
Last active December 19, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luislobo/5979360 to your computer and use it in GitHub Desktop.
Save luislobo/5979360 to your computer and use it in GitHub Desktop.
If you click on Approve or Revoke, all confirmations of all buttons are run. Using Yii 1.1.13
<?php
$rawData = array(
array( 'id' => 1, 'username' => 'User 1', 'email' => 'hello2@example.com' ),
array( 'id' => 2, 'username' => 'User 2', 'email' => 'hello2@example.com' ),
);
$arrayDataProvider = new CArrayDataProvider( $rawData, array( 'id' => 'id' ) );
$this->widget( 'zii.widgets.grid.CGridView',
array(
'id' => 'user-grid',
'dataProvider' => $arrayDataProvider,
'columns' => array(
'id',
'username',
'email',
array(
'class' => 'CButtonColumn',
'template' => '{approve}{revoke}',
'htmlOptions' => array( 'class' => 'button-column' ),
'buttons' => array(
'approve' => array(
'label' => 'Approve',
'url' => 'Yii::app()->createUrl("/approve", array("id" => $data["id"]))',
'options' => array( 'class' => 'btn btn-mini' ),
'click' => <<<EOD
function() {
if(!confirm("Are you sure to Approve this item?")) return false;
var th = this,
afterAction = function(link,success,data){ if(success) alert("Item Approved!"); };
jQuery('#user-grid').yiiGridView('update', {
type: 'POST',
url: jQuery(this).attr('href'),
success: function(data) {
jQuery('#user-grid').yiiGridView('update');
afterAction(th, true, data);
},
error: function(XHR) {
return afterAction(th, false, XHR);
}
});
return false;
}
EOD
),
'revoke' => array(
'label' => 'Revoke',
'url' => 'Yii::app()->createUrl("/revoke", array("id" => $data["id"]))',
'options' => array( 'class' => 'btn btn-mini' ),
'click' => <<<EOD
function() {
if(!confirm("Are you sure to Revoke this item?")) return false;
var th = this,
afterAction = function(link,success,data){ if(success) alert("Item Revoked!"); };
jQuery('#user-grid').yiiGridView('update', {
type: 'POST',
url: jQuery(this).attr('href'),
success: function(data) {
jQuery('#user-grid').yiiGridView('update');
afterAction(th, true, data);
},
error: function(XHR) {
return afterAction(th, false, XHR);
}
});
return false;
}
EOD
),
),
),
)
)
);
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment