<style>
    #invoice-grid {
	width: auto !important;
    }

    #invoice-flash-msg .alert {
	width: 1065px !important;
    }
</style>
<script type="text/javascript">
    var tid_id = '<?php echo $tid_id; ?>';
</script>
<?php if ($page_name == 'view_tid') {
 ?>
    <div id="invoice-flash-msg">
        <br>
<?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>
<?php } ?>

<?php
$this->widget('yiiwheels.widgets.grid.WhGridView', array(
    'id' => 'invoice-grid',
    'ajaxUrl' => Yii::app()->createUrl('invoice/index', array('tid_id' => $tid_id, 'from' => 'inside','rendered_from'=>$page_name)),
    'beforeAjaxUpdate' => 'function(id,options) {
                var url=options.url;
		options.url = options.url+ "&Invoice%5Bfrom_tid%5D="+tid_id;
	    }',
    'template' => ($page_name == 'view_tid') ? '{summary}{items}{pager}' : "{items}{pager}",
    'dataProvider' => $model->search($tid_id),
    'filter' => $model,
    'columns' => array(
	array(
	    'type' => 'html',
	    'name' => 'number',
	    'value' => 'CHtml::link($data->number, array("/invoice/view", "id" => $data->id))',
	),
	'value',
	'description',
	'comments',
	array(
	    'class' => 'CButtonColumn',
	    'htmlOptions' => array('width' => '60'),
	    'template' => ($page_name != 'view_tid') ? '' : '{update} {delete} {add_asset}',
	    'afterDelete' => 'function(link,success,data){ if(success) $("#invoice-flash-msg").html(data); }',
	    'buttons' => array(
		'delete' => array
		    (
		    'url' => 'Yii::app()->createAbsoluteUrl("invoice/delete", array("id" => $data->id))',
		    'visible' => 'Yii::app()->user->checkAccess(User::SYSTEM_ADMIN_ROLE)',
		),
		'update' => array
		    (
		    'url' => 'Yii::app()->createAbsoluteUrl("invoice/update", array("id" => $data->id))',
		    'visible' => '!Yii::app()->user->isGuest'
		),
		'add_asset' => array(
		    'label' => Yii::t('default', 'Add New Asset'),
		    'url' => 'array("asset/create","invoice_id"=>$data->id,"tid_id"=>$data->tid_id)',
		    'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/add_asset.png',
		    'visible' => '!Yii::app()->user->isGuest'
		),
		'manage_asset' => array(
		    'label' => Yii::t('default', 'Add New Asset'),
		    'url' => 'array("asset/index","invoice_id"=>$data->id)',
		    'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/manage.png',
		    'visible' => '!Yii::app()->user->isGuest'
		),
	    ),
	),
    ),
));
?>
