<?php
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.
?>
<?php echo $this->partial('partials/tabs.phtml', ['tabs' => $this->tabs, 'renderTo' => 'main', 'renderMode' => 'top']); ?>

<p><?php echo $this->jailList->lmsg('pageHint'); ?></p>

<script type="text/javascript">
    //<![CDATA[
        new Jsw.Panel({
            cls: 'list-box',
            renderTo: 'main',
            items: [
                new Jsw.List({
                    id: 'jail-list',
                    data: <?php echo Zend_Json::encode($this->jailList->fetchData()); ?>,
                    dataUrl: '/server-protection/jail-list-data',
                    searchFilters: <?php echo Zend_Json::encode($this->jailList->getSearchFilterConfig()); ?>,
                    operations: [{
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddJail',
                        title: <?php echo $this->jailList->jsLmsg('buttonAddJail') ?>,
                        description: <?php echo $this->jailList->jsLmsg('hintAddJail') ?>,
                        addCls: 'sb-add-new btn-primary',
                        href: '/server-protection/add-jail'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonDisableJails',
                        title: <?php echo $this->jailList->jsLmsg('buttonDisableJails');?>,
                        description: <?php echo $this->jailList->jsLmsg('hintDisableJails'); ?>,
                        addCls: 'sb-turn-off',
                        handler: function() {
                            Jsw.getComponent('jail-list').execGroupOperation({
                                url: '/server-protection/disable-jails',
                                skipConfirmation: true
                            });
                        }
                    <?php if ($this->showActivateJailsButton): ?>
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonActivateJails',
                        title: <?php echo $this->jailList->jsLmsg('buttonActivateJails');?>,
                        description: <?php echo $this->jailList->jsLmsg('hintActivateJails'); ?>,
                        addCls: 'sb-activate',
                        handler: function() {
                            Jsw.getComponent('jail-list').execGroupOperation({
                                url: '/server-protection/enable-jails',
                                skipConfirmation: true
                            });
                        }
                    <?php endif; ?>
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonManageFilters',
                        title: <?php echo $this->jailList->jsLmsg('buttonManageFilters') ?>,
                        description: <?php echo $this->jailList->jsLmsg('hintManageFilters') ?>,
                        addCls: 'sb-manage',
                        href: '/server-protection/filters-list'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveJail',
                        title: <?php echo $this->jailList->jsLmsg('buttonRemoveJail') ?>,
                        description: <?php echo $this->jailList->jsLmsg('hintRemoveJail') ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('jail-list').execGroupOperation({
                                url: '/server-protection/delete-jails',
                                subtype: 'delete',
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->jailList->jsLmsg('confirmOnDelete') ?>
                                }
                            });
                        }
                    }],
                    columns: [
                        Jsw.list.COLUMN_SELECTION,
                        {
                            header: <?php echo $this->jailList->jsLmsg('name');?>,
                            sortable: true,
                            dataIndex: 'name',
                            renderer: function (item) {
                                var url = Jsw.prepareUrl('/server-protection/overview-jail/id/' + encodeURIComponent(item.id));
                                return '<a href="' + url + '">' + Jsw.escapeHtml(item.name) + '</a>';
                            }
                        }, {
                            header: <?php echo $this->jailList->jsLmsg('status');?>,
                            sortable: true,
                            dataIndex: 'enabled',
                            renderer: function (item) {
                                var disabledHint = <?php echo $this->jailList->jsLmsg('disabled')?>;
                                var activeHint = <?php echo $this->jailList->jsLmsg('active')?>;
                                var statusIcon = item.enabled
                                    ? '<?php echo $this->skinUrl('/icons/16/plesk/ok.png') ?>'
                                    : '<?php echo $this->skinUrl('/icons/16/plesk/att.png') ?>';

                                var html = (
                                    '<span class="b-indent-icon">' +
                                        '<span>' +
                                            '<img src="' + statusIcon + '" alt="' + '' + '" title="">' +
                                        '</span>' +
                                    '</span>'
                                );

                                html += item.enabled ? activeHint : disabledHint;

                                return html;
                            }
                        }
                    ]
                })
            ]
        });
    //]]>
</script>
