<?php
$columns = array();
$notRendered = array('lastEditedPhoneType');
foreach ($model->attributes as $attributeName => $attributeValue) {
    if (in_array($attributeName, $notRendered)) {
        continue;
    }
    $columns[] = array(
        'name' => $attributeName,
        'header' => $model->getAttributeLabel($attributeName),
        'headerHtmlOptions' => array('data-translation-id' => 'PROVISIONING_PROFILE_MODEL_' . strtoupper($attributeName)),
    );
}
$columns[] = array(
    'htmlOptions' => array('class' => 'buttonColumnIcons', 'style' => 'width:55px;'),
    'class' => 'bootstrap.widgets.TbButtonColumn',
    'template' => '{update}{delete}',
);
///TEST
$this->widget('ext.PlNavbar', array(
    'brand' => __('PROVISIONING_PROFILE_HEADER_TITLE'),
    'brandOptions' => array('data-translation-id' => 'PROVISIONING_PROFILE_HEADER_TITLE'),
    'items' => array(
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => array(
                array(
                    'label' => __('PROVISIONING_PROFILE_ADD_NEW_PROFILE'),
                    'url' => Yii::app()->createUrl('provisioningProfile/default/create'),
                    'icon' => 'plus',
                    'linkOptions' => array(
                        'id' => "provisioning-profile-gridCreateBtn",
                        'data-translation-id' => 'PROVISIONING_PROFILE_ADD_NEW_PROFILE',
                    ),
                ),
            ),
        ),
    ),
));

$this->widget('bootstrap.widgets.TbAlert', array(
    'block' => true, // display a larger alert block?
    'fade' => true, // use transitions?
    'closeText' => '&times;', // close link text - if set to false, no close link is displayed
));

Yii::app()->clientScript->registerScript(
        'autoHideAlert', 'setTimeout(function(){$(".alert").alert("close")}, 3000);', CClientScript::POS_READY
);

$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'provisioning-profile-grid',
    'dataProvider' => $model->search(),
    'summaryText' => false,
    'afterAjaxUpdate' => 'function(){        
        setCreateButtonVisibility();
    }',
    'summaryText' => false,
    'type' => 'striped bordered condensed', //change color from columns in 'white' and 'grey' responsively
    'itemsCssClass' => 'plTable items', //change design of the table, removed search bar
    'selectableRows' => 2,
    'columns' => $columns,
));
$provisioningProfileMax = PhonalisaLicenseManager::provisioningProfileMax();

if (Yii::app()->user->translateMode) {
    $tanslationTag = 'PROVISIONING_PARAMETERS_SHOULD_NOT_CONTAINS_GREATER_LESS_THAN_ERROR_MESSAGE';
    
    echo '<i data-translation-id="'.$tanslationTag.'">'.$tanslationTag.' => '.__($tanslationTag).'</i>';
}

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