<?php
/* @var $this TicketController */
/* @var $model Ticket */

$this->breadcrumbs = array(
    yii::t('default', 'Requests') => array('/dashboard/requests'),
    yii::t('default', 'Tickets') => array('index'),
);

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

<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>
<?php
    if (Yii::app()->user->checkAccess('System Admin') || Yii::app()->user->checkAccess('Super Admin') || Yii::app()->user->checkAccess('Facility Admin') || (User::model()->checkFoodManagerUser()))
        echo CHtml::link(Yii::t('default', 'New Department Ticket'), array('createDepartmentTicket'), array('class' => 'btn btn-primary', 'data-dismiss' => 'modal'));
?>
    &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' => 'ticket-grid',
        'type' => 'striped',
        'dataProvider' => $model->with(array('department', 'issuingReason', 'pos', 'schedule', 'user'))->search(),
        'filter' => $model,
        'columns' => array(
            'id',
            array(
                'name' => 'user_id',
                'value' => '$data->user->identifier',
                'filter' => CHtml::listData(User::getAll(), 'id', 'identifier')
            ),
            array(
                'name' => 'ticket_type',
                'filter' => array(yii::t('default', 'Department') => yii::t('default', 'Department'), yii::t('default', 'Person') => Yii::t('default', 'Person')),
            ),
//            'ticket_type',
            array(
                'name' => 'department_id',
                'value' => '$data->department->name',
            ),
            array(
                'name' => 'pos_id',
                'value' => '$data->pos->name',
            ),
            array(
                'name' => 'schedule_id',
                'value' => '$data->schedule->name',
            ),
            'date_time',
            'quantity',
            array(
                'name' => 'issuing_reason_id',
                'value' => '$data->issuingReason!=null?$data->issuingReason->reason:""',
            ),
            array(
                'name' => 'cancelled',
                'value' => '$data->cancelled==1?yii::t("default", "Yes"):yii::t("default", "No")',
                'filter' => array('1' => Yii::t('default', 'Yes'), '0' => Yii::t('default', 'No')),
            ),
            array(
                'class' => 'CButtonColumn',
                'htmlOptions' => array('width' => '90'),
                'template' => '{view} {Cancel} {Activate}',
                'buttons' => array(
                    'view' => array
                        (
                        'url' => 'array("/ticket/view","id"=>$data->id)',
                    ),
                    'Cancel' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/cancel_ticket.png',
                        'url' => 'array("/ticket/cancelled","id"=>$data->id)',
                        'visible' => '$data->cancelled==0?(Yii::app()->user->checkAccess("System Admin")?true:(Yii::app()->user->checkAccess("Super Admin")?true:false)):false',
                        'click' => "function(){
                            return confirm('" . Yii::t("default", "Are you sure you want to cancel this ticket?") . "');}
                          ",
                    ),
                    'Activate' => array
                        (
                        'imageUrl' => Yii::app()->request->baseUrl . '/css/flags/reactivate_ticket.png',
                        'url' => 'array("/ticket/cancelled","id"=>$data->id)',
                        'visible' => '$data->cancelled==1?(Yii::app()->user->checkAccess("System Admin")?true:(Yii::app()->user->checkAccess("Super Admin")?true:false)):false',
                        'click' => "function(){
                            return confirm('" . Yii::t("default", "Are you sure you want to activate this ticket?") . "');}
                          ",
                    ),
            )),
        ),
    )); ?>