<?php
/* @var $this PersonController */
/* @var $model Person */

$this->breadcrumbs = array(
    yii::t('default', 'Persons') => array('index'),
);

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


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


<?php
//Add Person Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
    'buttons' => array(
        array('label' => Yii::t('default', 'Add'), 'items' => array(
                array('label' => Yii::t('default', 'LDAP Person'), 'url' => array('/lDAPPerson/personSearch')),
                array('label' => Yii::t('default', 'Non-LDAP Person'), 'url' => array('/nonLDAPPerson/create')),
        )),
    ),
));

//Add Batch Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Add Batch'), 'items' => array(
                array('label' => Yii::t('default', 'LDAP Persons'), 'url' => array('/lDAPPerson/addBatch')),
                array('label' => Yii::t('default', 'Non-LDAP Persons'), 'url' => array('/nonLDAPPerson/addBatch')),
        )),
    ),
));

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

//Add Batch assign to POSs Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Batch assign to POSs'),  'url' => array('/personpos/batchPersonPOSs')),
    ),
));

//Add Export Button
$this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type' => 'primary',
    'buttons' => array(
        array('label' => Yii::t('default', 'Export'),  'url' => array('/person/exportToExcel')),
    ),
));
?>
&nbsp;
<?php echo CHtml::link(Yii::t('default', 'Advance Search'), '#', array('class' => 'search-button btn')); ?>

<div class="search-form" style="display:none">
    <?php
    $this->renderPartial('_search', array(
        'model' => $model,
    ));
    ?>
</div><!-- search-form -->
<?php
    $this->widget('ext.bootstrap.widgets.TbGridView', array(
        'id' => 'person-grid',
        'type' => 'striped',
        'dataProvider' => $model->search(),
        'filter' => $model,
        'columns' => array(
            'number',
            'name',
            'alias',
            'email',
            array(
                'name' => 'type_id',
                'value' => '$data->type->name',
                'filter' => CHtml::listData(PersonType::getAll(), 'id', 'name')
            ),
            array(
                'name' => 'status',
                'type' => 'html',
                'filter' => array('Active' => Yii::t('default', 'Active')
                    , 'On Leave' => Yii::t('default', 'On Leave')
                    , 'Terminated' => Yii::t('default', 'Terminated')
                    , 'Resigned' => Yii::t('default', 'Resigned')
                    , 'Transferred' => Yii::t('default', 'Transferred')
                    , 'Inactive' => Yii::t('default', 'Inactive')
                ),
                'htmlOptions' => array('style' => 'text-align:center;'),
            ),
            array(
                'class' => 'CButtonColumn',
                'template' => '{view}{update}{delete}{Assign}',
                'htmlOptions' => array('width' => '70'),
                'afterDelete' => 'function(link,success,data){ if(success) $("#flash-msg").html(data); }',
                'viewButtonUrl' => '$data->getViewUrl()',
                'updateButtonUrl' => '$data->getUpdateUrl()',
                'buttons' => array(
                    'Assign' => array
                        (
                        'label' =>Yii::t('default', 'Assign Badge'),
                        'url' => 'array("badge/assignBadgeToPerson","id"=>$data->id)', //A PHP expression for generating the URL of the button.
                        'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/assign.png',

                    ),
        )),
        ),
    )); ?>