<?php
cs()->registerScript('alertAutoClose', 'window.setTimeout(function() { $(".alert").alert("close"); }, 5000)');
$this->widget('ext.PlNavbar', array(
    'brand' => __('PHONESETTINGSCALLFORWARDS_PRESETLIST_HEADER_TITLE'),
    'htmlOptions' => array(
        'data-translation-id' => 'PHONESETTINGSCALLFORWARDS_PRESETLIST_HEADER_TITLE',
    ),
    'items' => array(
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => array(
                array(
                    'label' => __('PHONESETTINGSCALLFORWARDS_PRESETLIST_ADD_NEW_PRESET'),
                    'icon' => 'plus',
                    'url' => url('phonesettingsCallforward/default/create'),
                    'active' => false,
                    'linkOptions' => array(
                        'data-translation-id' => 'PHONESETTINGSCALLFORWARDS_PRESETLIST_ADD_NEW_PRESET'
                    ),
                ),
            ),
        ),
    ),
));

$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
    'alerts' => array(// configurations per alert type
        'success' => array( // success, info, warning, error or danger
            'block' => true,
            'fade' => true,
            'closeText' => '&times;'
        ),
        'info' => array( // success, info, warning, error or danger
            'block' => true,
            'fade' => true,
            'closeText' => '&times;'
        ),
        'danger' => array(  // success, info, warning, error or danger
            'block' => true,
            'fade' => true,
            'closeText' => '&times;'
        ),
    ),
));

$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
    'alerts' => array(// configurations per alert type
        'error' => array( // success, info, warning, error or danger
            'block' => true,
            'fade' => true,
            'closeText' => '&times;'
        ),
    ),
));

$user = app()->user->sudoUserInstance;


echo CHtml::beginForm();
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'presets-grid',
    'itemsCssClass' => 'plTable ',
    'dataProvider' => $dataProvider,
    'summaryText' => false,
    'type' => 'striped bordered ', //condensed
    'columns' => array(
        array(
            'class' => 'ForwardSetRadioColumn',
            'name' => 'id',
            'header' => __('FORWARD_PRESET_ACTIVE'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_ACTIVE'),
            'checked' => '$data->id == app()->user->sudoUserInstance->callForwardSet',
        ),
        array(
            'class' => 'ForwardSetRadioColumn',
            'name' => 'id',
            'header' => __('FORWARD_PRESET_DEFAULT'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_DEFAULT'),
            'checked' => '$data->id == app()->user->sudoUserInstance->defaultCallForwardSet',
        ),
        array(
            'name' => 'id',
            'htmlOptions' => array('width' => '40'),
            'header' => __('FORWARD_PRESET_FEATURE_PHONE_KEY'),
            'type' => 'raw',
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_FEATURE_PHONE_KEY'),
            'value' => '$data->renderPhoneKeyInput()',
        ),
        array(
            'name' => 'name',
            'header' => $model->getAttributeLabel('name'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_MODEL_NAME'),
        ),
        array(
            'name' => 'description',
            'header' => $model->getAttributeLabel('description'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_MODEL_DESCRIPTION'),
        ),
        array(
            'name' => 'forwardType',
            'type' => 'raw',
            'header' => $model->getAttributeLabel('forwardType'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_MODEL_FORWARD_TYPE'),
            'value' => 'ForwardType::translateType($data->forwardType)',
        ),
        array(
            'name' => 'type',
            'type' => 'raw',
            'header' => $model->getAttributeLabel('type'),
            'headerHtmlOptions' => array('data-translation-id' => 'FORWARD_PRESET_MODEL_TYPE'),
            //'value' => '$model->renderType($data)',
            'value' => '$data->renderTypeBadge()',
        ),
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'template' => '{view}{update}{delete}',
            'htmlOptions' => array(
                'data-translation-target' => 'USER_ERROR_MESSAGE_TRANSLATIONS',
                'class' => 'buttonColumnIcons',
            ),
            'buttons' => array(
                'view' => array(
                    'visible' => '$data->type != ForwardPresetType::PrivatePreset &&'
                        . ' $data->forwardType != ForwardType::Disabled',
                ),
                'update' => array(
                    'visible' => '$data->type == ForwardPresetType::PrivatePreset',
                ),
                'delete' => array(
                    'visible' => '$data->type == ForwardPresetType::PrivatePreset',
                ),
            )
        )
    ),
));



//$t->delete();

$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    'type' => 'primary',
    'label' => __('GLOBAL_SAVE_BUTTON'),
    'htmlOptions' => array(
        "data-translation-id" => "GLOBAL_SAVE_BUTTON"
    )
));
echo CHtml::endForm();


if (Yii::app()->user->translateMode) {
    echo '<p '
        . 'data-translation-id="FORWARD_PRESET_FEATURE_KEY_ISNOT_UNIQUE"'
        . '>'
        . __('FORWARD_PRESET_FEATURE_KEY_ISNOT_UNIQUE')
        . '</p>';
}
?>
<style>
    .grid-view {
        padding-top: 0;
    }

    #presets-grid tr td:nth-child(3) input{
        width: 30px;
        text-align: center;
    }
</style>