<?php

$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'call-group-grid',
    'headerTitle' => 'HEADER_TITLE', // optional
    'addButtonTitle' => 'ADD_NEW_GROUP', // optional
    'modalCreateHeader' => 'ROUTINGCALLGROUP_ADD_NEW_GROUP', // optional
    'modalUpdateHeader' => 'ROUTINGCALLGROUP_HEADER_UPDATE', // optional
    'afterAjaxUpdate' => 'function(){    
        setCreateButtonVisibility();
    }',
    'itemsCssClass' => 'plTable items',
    'modalSize' => 'large', // null, 'large', 'small', 'huge'
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'extension',
        'name',
        'description',
        array(
            'name' => 'playlistId',
            'type' => 'raw',
            'value' => array($model, 'renderPlayListID'),
            'filter' => $model->humanReadableSearchFilterForPlaylistID(),
            'enableCustomDropdownFilter' => true,
        ),
        array(
            'name' => 'night_circut',
            'type' => 'raw',
            'value' => array($model, 'renderActiveNightCircut'),
            'htmlOptions' => array('style' => 'text-align:center'),
            'headerHtmlOptions' => array(
                'style' => 'text-align:center',
                'width' => 200,
            ),
            'disableSearchField' => true,
        ),
        array(
            'header' => __('ROUTING_CALL_GROUP_MODEL_USERNUMBER'),
            'type' => 'raw',
            'value' => '$data->getUserNumber()',
            'htmlOptions' => array('style' => 'text-align:center'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'ROUTING_CALL_GROUP_MODEL_USERNUMBER',
                'style' => 'text-align:center',
                'width' => 80,
            ),
            'disableSearchField' => true,
        ),
        array(
            'class' => 'ext.PlGrid.PlCButtonColumn',
            'header' => '&nbsp;',
            'template' => '{ringMap}',
            'buttons' => array(
                'ringMap' => array(
                    'label' => '<i class="icon-align-center"></i>',
                    'options' => array(
                        'title' => __('ROUTING_CALL_GROUP_MODEL_RINGMAP_BUTTON'),
                        'data-translation-id' => 'ROUTING_CALL_GROUP_MODEL_RINGMAP_BUTTON',
                    ),
                    'url' => 'Yii::app()->createUrl("routingCallGroup/default/ringMap", array("id"=>"$data->id"))',
                ),
            )
        ),
        array(
            'class' => 'ext.PlGrid.PlCButtonColumn',
            'template' => '{ajaxUpdate}{delete}',
        )
    ),
        )
);
$routingCallGroupMax = PhonalisaLicenseManager::routingCallGroupMax();
?>
<script>
    function setCreateButtonVisibility() {
        if (
                $("#call-group-grid tbody tr").length >= <?php echo $routingCallGroupMax; ?>
        && !$("#call-group-grid tbody tr td:first-child").hasClass("empty")
                && <?php echo $routingCallGroupMax; ?> >= 0
                ) {
            $("#call-group-gridCreateBtn").hide();
        } else {
            $("#call-group-gridCreateBtn").show();
        }
    }
    setCreateButtonVisibility();
</script>