<?php

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'firewall-form',
    'enableAjaxValidation' => true,
        ));

echo '<div class="form">';
echo "<div id='alertFlash'></div>";
$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'firewall-grid',
    'headerTitle' => 'NETWORK_FIREWALL_TITLE', // optional
    'dataProvider' => $model->search($chain),
    'useCustomTitle' => true,
    'selectableRows' => 1,
    'summaryText' => false,
    'showAlertBlock' => true,
    'alertAutoHide' => false,
    'enableAddButton' => false,
    'enableSearchButton' => false,
    'customButtons' => $this->getTabItems($chain),
    'columns' => array(
        array(
            'value' => '"<i class=\"icon-fullscreen\"></i>"',
            'type' => 'raw'
        ),
        array(
            'name' => 'active',
            'type' => 'raw',
            'header' => $model->getAttributeLabel('active'),
            'headerHtmlOptions' => array('data-translation-id' => 'NETWORK_FIREWALL_MODEL_ACTIVE'),
            'value' => array($this, 'renderActiveCell'),
        ),
        array(
            'name' => 'protocol',
            'type' => 'raw',
            'value' => array($this, 'renderDropdownCell'),
            'header' => $model->getAttributeLabel('protocol'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_PROTOCOL'
            ),
            'htmlOptions' => array(
                'class' => 'firewallTableSmallHeader'
            )
        ),
        array(
            'name' => 'source',
            'type' => 'raw',
            'value' => array($this, 'renderTextCell'),
            'header' => $model->getAttributeLabel('source'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_SOURCE'
            )
        ),
        array(
            'name' => 'sport',
            'type' => 'raw',
            'value' => array($this, 'renderPortCell'),
            'header' => $model->getAttributeLabel('sport'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_SPORT'
            ),
            'htmlOptions' => array(
                'class' => 'firewallTableSmallHeader'
            )
        ),
        array(
            'name' => 'destination',
            'type' => 'raw',
            'value' => array($this, 'renderTextCell'),
            'header' => $model->getAttributeLabel('destination'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_DESTINATION'
            )
        ),
        array(
            'name' => 'dport',
            'type' => 'raw',
            'value' => array($this, 'renderPortCell'),
            'header' => $model->getAttributeLabel('dport'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_DPORT'
            ),
            'htmlOptions' => array(
                'class' => 'firewallTableSmallHeader'
            )
        ),
        array(
            'name' => 'action',
            'value' => array($this, 'renderDropdownCell'),
            'header' => $model->getAttributeLabel('action'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_ACTION'
            ),
            'htmlOptions' => array(
                'class' => 'firewallTableSmallHeader'
            )
        ),
        array(
            'name' => 'comment',
            'type' => 'raw',
            'value' => array($this, 'renderTextCell'),
            'header' => $model->getAttributeLabel('comment'),
            'headerHtmlOptions' => array(
                'data-translation-id' => 'NETWORK_FIREWALL_MODEL_COMMENT'
            )
        ),
        array(
            'name' => 'chain',
            'type' => 'raw',
            'htmlOptions' => array('style' => 'display:none'),
            'headerHtmlOptions' => array('style' => 'display:none'),
            'value' => array($this, 'renderhiddenSortCell')
        ),
        array(
            'name' => 'sort',
            'type' => 'raw',
            'htmlOptions' => array(
                'style' => 'display:none',
                'class' => 'hiddenSortIndex'
            ),
            'headerHtmlOptions' => array('style' => 'display:none'),
            'value' => array($this, 'renderhiddenSortCell'),
        ),
        array(
            'class' => 'bootstrap.widgets.TbButtonColumn',
            'htmlOptions' => array('class' => 'buttonColumnIcons'),
            'template' => '{delete}',
            'buttons' => array(
                'delete' => array('visible' => '$data->id != "new"'),
            ),
        ),
    ),
));
echo CHtml::submitButton('save', array('id' => 'firewallAction', 'style' => 'display:none'));

$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'button',
    'type' => 'primary',
    'label' => __('GLOBAL_SAVE_BUTTON'),
    'loadingText' => 'loading...',
    'htmlOptions' => array(
        'id' => 'saveNewFirewallRuleButton',
        'data-translation-id' => 'GLOBAL_SAVE_BUTTON',
    ),
));

$this->endWidget();
echo "</div>";

if (Yii::app()->user->translateMode) {
    $this->renderPartial('_translationTags');
}
$this->renderPartial('firewallScripts');
