<?php
$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'routing_queue-grid',
    'headerTitle' => 'Header_title', // optional
    'addButtonTitle' => 'ADD_NEW_QUEUE', // optional
    'searchButtonTitle' => 'SEARCH_QUEUE', // optional
    'modalCreateHeader' => 'QUEUE_HEADER_CREATE', // optional
    'modalUpdateHeader' => 'QUEUE_HEADER_UPDATE', // optional
    'afterAjaxUpdate' => 'function(){
            
            setCreateButtonVisibility();
        }',
    'headerAttribute' => 'name', // TEST
    'itemsCssClass' => 'plTable items',
    'dataProvider' => $model->search(),
    'modalSize' => 'large', // null, 'large', 'small', 'huge'
    'filter' => $model,
    'columns' => array(
        array(
            'name' => 'extension',
            'header' => $model->getAttributeLabel('extension'),
            'headerHtmlOptions' => array('data-translation-id' => 'QUEUE_MODEL_EXTENSION'),
        ),
        array(
            'name' => 'name',
            'header' => $model->getAttributeLabel('name'),
            'headerHtmlOptions' => array('data-translation-id' => 'QUEUE_MODEL_NAME'),
        ),
        array(
            'name' => 'moh',
            'header' => $model->getAttributeLabel('moh'),
            'headerHtmlOptions' => array('data-translation-id' => 'QUEUE_MODEL_MOH',
            ),
            'value' => array($model, 'renderMohList'),
            'enableCustomDropdownFilter' => true,
            'filter' => $model->getAudioFileList(),
        ),
        array(
            'name' => 'strategy',
            'header' => $model->getAttributeLabel('strategy'),
            'headerHtmlOptions' => array('data-translation-id' => 'QUEUE_MODEL_STRATEGY'),
            'value' => array($model, 'renderQueueStrategy'),
            'enableCustomDropdownFilter' => true,
            'filter' => $model->getQueueStrategyList(),
        ),
        array(
            'name' => 'time_base_score',
            'header' => $model->getAttributeLabel('time_base_score'),
            'headerHtmlOptions' => array('data-translation-id' => 'QUEUE_MODEL_TIME_BASE_SCORE'),
            'value' => array($model, 'renderTimeBaseScore'),
            'enableCustomDropdownFilter' => true,
            'filter' => $model->getQueueTimeBaseScore(),
        ),
        array(
            'class' => 'ext.PlGrid.PlCButtonColumn',
            'template' => '{ajaxUpdate}{delete}',
        )
    ),
        )
);
$routingQueuesMax = PhonalisaLicenseManager::routingQueuesMax();
?>
<script>
    function setCreateButtonVisibility() {
        if (
                $("#routing_queue-grid tbody tr").length >= <?php echo $routingQueuesMax; ?>
        && !$("#routing_queue-grid tbody tr td:first-child").hasClass("empty")
                && <?php echo $routingQueuesMax; ?> >= 0
                ) {
            $("#routing_queue-gridCreateBtn").hide();
        } else {
            $("#routing_queue-gridCreateBtn").show();
        }
    }
    setCreateButtonVisibility();
</script>