|
<?php |
|
$rawData = array( |
|
array( 'id' => 1, 'username' => 'User 1', 'email' => '[email protected]' ), |
|
array( 'id' => 2, 'username' => 'User 2', 'email' => '[email protected]' ), |
|
); |
|
$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; |