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

$this->breadcrumbs = array(
    yii::t('default', 'Badges') => array('index'),
);
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', 'Add'), array('create'), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal')); ?>
&nbsp;
<?php
//Add Batch Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Add Batch'), 'url' => array('/badge/addBatch')),
    ),
));

//Batch Extend Badges Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Batch Extend Badges'), 'url' => array('/badge/batchExtendBadges')),
    ),
));


//Add Export Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Export'), 'url' => array('/badge/exportToExcel')),
    ),
));


?>
<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->with('person')->search(),
        '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' => 'person_id',
                'value' => 'isset($data->person)&&($data->person!=null)?$data->person->name:""',
            ),
            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' => '{Assign} {Reassign} {Un-Assign} {Renew} {update}{delete}',
                'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
                'buttons' => array(
                    'Assign' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl."/css/flags/assign.png",
                        'label' => Yii::t('default', 'Assign Badge'),
                        'url' => 'array("assignPersonToBadge","id"=>$data->id)', //A PHP expression for generating the URL of the button.
                        'visible' => '$data->person_id=="" && $data->status=="Free"',
                    ),
                    'Reassign' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl."/css/flags/reassign.png",
                        'label' => Yii::t('default', 'Reassign Badge'),
                        'url' => 'array("assignPersonToBadge","id"=>$data->id)', //A PHP expression for generating the URL of the button.
                        'visible' => '$data->person_id!="" && $data->type->allow_reassign && $data->status!="Deleted"',
                    ),
                    'delete' => array(
                        'htmlOptions' => array('width' => '60'),
                        'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
                    ),
                    'Un-Assign' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/unassign.png',
                        'url' => 'array("unAssignBadge","id"=>$data->id)',
                        'visible' => '$data->person_id!=null',
                        'click' => "function(){
                            return confirm('" . Yii::t("default", "Are you sure you want to un-assign this badge ?") . "');}
                          ",
                        'Un-AssignConfirmation' => 'echo $data->person_id',
                    ),
                    'Renew' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/renew.png',
                        'url' => 'array("renew","id"=>$data->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?") . "');}",
                    )
            )),
        ),
    )); ?>
