<?php
 /* @var $this BadgeController */
 /* @var $model Badge */

 $this->breadcrumbs = array(
     yii::t('default', 'Persons') => array('/person/index'),
     $person->identifier => $person->getViewUrl(),
     yii::t('default', 'View Badges'),
 );

 Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('badge-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<?php echo CHtml::link(Yii::t('default', 'Assign Badge'), array('/badge/assignBadgeToPerson', 'id' => $id), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal')); ?>
&nbsp;
<div id="flash-msg">
     <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>
<?php
     $this->widget('ext.bootstrap.widgets.TbGridView', array(
         'id' => 'badge-grid',
         'type' => 'striped',
         'dataProvider' => $model->search(false),
         'filter' => $model,
         'columns' => array(
             'number',
             array(
                 'name' => 'type_id',
                 'value' => '$data->type->name',
                 'filter' => CHtml::listData(BadgeType::getAll(), 'id', 'name')
             ),
             'activation_start_date',
             'activation_end_date',
             'max_served_meals',
             array(
                 'name' => 'status',
                 'type' => 'html',
                 'filter' => array('Free' => Yii::t('default', 'Free'),
                     'Active' => Yii::t('default', 'Active'),
                     'Inactive' => Yii::t('default', 'Inactive'),
                     'Deleted' => Yii::t('default', 'Deleted'),
                     'Lost' => Yii::t('default', 'Lost'),
                 ),
                 'htmlOptions' => array('style' => 'text-align:center;'),
             ),
             array(
                 'class' => 'CButtonColumn',
                 'htmlOptions' => array('width' => '90'),
                 'template' => '{update} {Un-Assign} {Renew}',
                 'buttons' => array(
                     'update' => array
                         (
                         'url' => 'array("/badge/update","id"=>$data->id,"person_id"=>' . $id . ')',
                     ),
                     'Un-Assign' => array
                         (
                         'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/unassign.png',
                         'url' => 'array("/badge/unAssignBadge","id"=>$data->id,"person_id"=>' . $id . ')',
                         'visible' => '$data->person_id!=null',
                         'click' => "function(){
                            return confirm('" . Yii::t("default", "Are you sure you want to un-assign this badge ?") . "');}
                          ",
                     ),
                     'Renew' => array
                         (
                         'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
                         'url' => 'array("/badge/renew","id"=>$data->id,"person_id"=>' . $id . ')',
                         'visible' => '$data->person_id!=null&&($data->status=="Active"||$data->status=="Inactive")',
                         'click' => "function(){ return confirm('" . Yii::t("default", "Are you sure you want to renew the activation period of the badge?") . "');}",
                     )
             )),
         ),
     )); ?>
