<?php
$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'ivr-grid',
    'type' => 'striped bordered condensed',
    'itemsCssClass' => 'plTable items',
    'dataProvider' => $model->search(),
    'summaryText' => false,
    'headerTitle' => 'HEADER_TITLE', // optional
    'addButtonTitle' => 'ADD_NEW_VOICE_MENU', // optional
    'searchButtonTitle' => 'NAVBAR_SEARCH', // optional
    'hideHeader' => false,
    'filter' => $model,
    'createInModal' => false,
    'afterAjaxUpdate' => 'function(){
        setCreateButtonVisibility();
    }',
    'columns' => array(
        array(
            'name' => 'extension',
            'header' => $model->getAttributeLabel('extension'),
            'headerHtmlOptions' => array('data-translation-id' => 'IVR_MODEL_EXTENSION'),
        ),
        array(
            'name' => 'title',
            'header' => $model->getAttributeLabel('title'),
            'headerHtmlOptions' => array('data-translation-id' => 'IVR_MODEL_TITLE'),
        ),
        array(
            'name' => 'description',
            'header' => $model->getAttributeLabel('description'),
            'headerHtmlOptions' => array('data-translation-id' => 'IVR_MODEL_DESCRIPTION'),
        ),
        array(
            'htmlOptions' => array('class' => 'buttonColumnIcons', 'style' => 'width:55px;'),
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'template' => '{update}{delete}',
        )
    ),
));

$routingIVRMax = PhonalisaLicenseManager::routingIVRMax();
?>
<script>
    function setCreateButtonVisibility() {
        if (
                $("#ivr-grid tbody tr").length >= <?php echo $routingIVRMax; ?>
        && !$("#ivr-grid tbody tr td:first-child").hasClass("empty")
                && <?php echo $routingIVRMax; ?> >= 0
                ) {
            $("#ivr-gridCreateBtn").hide();
        } else {
            $("#ivr-gridCreateBtn").show();
        }
    }
    setCreateButtonVisibility();
</script>