<style>
    span.required {
	color: #eee!important;
    }

    .red-star {
	color: #eee!important;
	display: none;
    }
</style>
<?php
/* @var $this AssetController */
/* @var $model Asset */

$this->breadcrumbs = array(
    yii::t('default', 'TIDs Management') => array('dashboardLayout/tids'),
    yii::t('default', 'Assets') => array('index'),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#asset-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
  $('#cancel_button').click(function(){
	$('#renew-form').removeClass('in');
    });
");
?>
<?php
if (!Yii::app()->user->isGuest)
    echo CHtml::link(Yii::t('default', 'Add'), array('create'), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal')); ?>
&nbsp;

<?php echo CHtml::link(Yii::t('default', 'Export'), array('exportToExcel', 'invoice_id' => $invoice_id), array('class' => 'btn btn-success')); ?>
&nbsp;
<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button btn')); ?>
&nbsp;
<?php
if (!Yii::app()->user->isGuest)
    echo CHtml::link(Yii::t('default', 'Renew'), array('generalRenew'), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal')); ?>


<div class="search-form" style="display:none">
    <?php
    $this->renderPartial('_search', array(
	'model' => $model,
    )); ?>
</div><!-- search-form -->

<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>


<?php
    $this->widget('yiiwheels.widgets.grid.WhGridView', array(
	'id' => 'asset-grid',
	'dataProvider' => $model->search($invoice_id),
	'filter' => $model,
	'afterAjaxUpdate' => 'function(id,options) {
                hide_column();
		$("td.empty").show();
	    }',
	'columns' => array(
	    'type_of_asset_id',
	    array(
		'type' => 'html',
		'name' => 'tid_no',
		'value' => 'CHtml::link($data->tid_no, array("/tid/view", "id" => $data->tid_id))',
	    //'filter' => Tid::getNumberForView()
	    ),
	    array(
		'type' => 'html',
		'name' => 'invoice_number',
		'value' => 'CHtml::link($data->invoice_number, array("/invoice/view", "id" => $data->invoice_id))',
	    //'filter' => Invoice::getNumberForView()
	    ),
	    'po_number',
	    array(
		'name' => 'segment_name',
		'value' => '$data->segment_name',
		'filter' => Segment::getNamesForView()
	    ),
	    'serial_number',
	    array(
		'type' => 'html',
		'name' => 'asset_number',
		'value' => 'CHtml::link($data->asset_number, array("/asset/view", "id" => $data->id))',
	    ),
	    'part_number',
	    array(
		'name' => 'type_of_asset_name',
		'value' => '$data->type_of_asset_name',
		'filter' => TypeOfAsset::getNamesForView()
	    ),
	    array(
		'name' => 'asset_status',
		'value' => '$data->asset_status',
		'filter' => Asset::getAssetStatusOptions()
	    ),
//	    'chassis_number',
//	    'plate_number',
//	    'radioactive_license_number',
	    array(
		'name' => 'status',
		'value' => '$data->status',
		'filter' => Asset::getStatusOptions()
	    ),
	    array(
		'name' => 'expiry_date',
		'value' => '$data->expiry_date',
	    ),
	    array(
		'class' => 'CButtonColumn',
		'htmlOptions' => array('width' => '60'),
		'template' => '{update} {delete} {renew}',
		'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
		'buttons' => array(
		    'delete' => array
			(
			'visible' => 'Yii::app()->user->checkAccess(User::SYSTEM_ADMIN_ROLE)',
		    ),
		    'update' => array
			(
			'visible' => '!Yii::app()->user->isGuest',
		    ),
		    'renew' => array
			(
			'label' => Yii::t('default', 'Renew'),
			'url' => '"#"',
			'click' => 'function(){
                             var rowIndex = $(this).closest("tr").index();
                             var rowId = $("#"+$(this).closest("div.grid-view").attr("id")+" > div.keys > span:eq("+rowIndex+")").text();
			     model_id = rowId;
			     var type_of_asset = $(this).parent().parent().children(":nth-child(1)").text();			      
			     checkTypeOfAssetModal(type_of_asset);
			     $("#renew-form").addClass("in");                            
                             return false;}',
			'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
			'visible' => '!Yii::app()->user->isGuest && ($data->type_of_asset_id == Setting::getRadioActiveTypeOfAsset() || $data->type_of_asset_id == Setting::getVehicleTypeOfAsset())',
		    ),
		),
	    ),
	),
    ));

    Yii::app()->controller->renderPartial('/asset/_modal', array('from_view' => null));
?>

<script type="text/javascript">
    var model_id =  '';
    var expiry_date =  '';



</script>
