<?php
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.
?>
<p><?php echo $this->lmsg($this->needResellerCountColumn ? 'hintWithResellers' : 'hint'); ?></p>

<script type="text/javascript">
//<![CDATA[
    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'admin-ip-address-list',
                data: <?php echo Zend_Json::encode($this->ipAddressesList->fetchData()); ?>,
                dataUrl: '/ip-address/list-data',
                searchFilters: <?php echo Zend_Json::encode($this->ipAddressesList->getSearchFilterConfig()); ?>,
                operations: [
                <?php if ($this->needAddButton) : ?>
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddIpAddress',
                        title: <?php echo $this->ipAddressesList->jsLmsg('buttonAddNewIpAddress');?>,
                        description: <?php echo $this->ipAddressesList->jsLmsg('buttonAddNewIpAddressDescription'); ?>,
                        addCls: 'sb-add-new-ip btn-primary',
                        href: '/ip-address/add'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    },
                <?php endif; ?>
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRereadConfiguration',
                        title: <?php echo $this->ipAddressesList->jsLmsg('buttonRereadConfiguration'); ?>,
                        description: <?php echo $this->ipAddressesList->jsLmsg('buttonRereadConfigurationDescription'); ?>,
                        addCls: 'sb-reread',
                        href: '/ip-address/refresh'
                <?php if ($this->needReloadPublicButton) : ?>
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonReloadPublic',
                        title: <?php echo $this->ipAddressesList->jsLmsg('buttonReloadPublic');?>,
                        description: <?php echo $this->ipAddressesList->jsLmsg('buttonReloadPublicDescription'); ?>,
                        addCls: 'sb-reload-public',
                        href: '/ip-address/reload-public'
                <?php endif; ?>
                <?php if ($this->needFirewallButton) : ?>
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonFirewall',
                        title: <?php echo $this->ipAddressesList->jsLmsg('buttonFirewall');?>,
                        description: <?php echo $this->ipAddressesList->jsLmsg('buttonFirewallDescription'); ?>,
                        addCls: 'sb-firewall',
                        href: '/ip-address/firewall'
                <?php endif; ?>
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemovePlan',
                        title: <?php echo $this->ipAddressesList->jsLmsg('buttonRemove');?>,
                        description: <?php echo $this->ipAddressesList->jsLmsg('buttonRemoveDescription'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('admin-ip-address-list').execGroupOperation({
                                url: '/ip-address/delete/',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->ipAddressesList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->ipAddressesList->jsLmsg('address');?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function (item, isDisabled) {
                            var ipAddressText = Jsw.escapeHtml(item.name);
                            if (item.isMain) {
                                ipAddressText = '<b>' + ipAddressText + '</b>';
                            }
                            var link = (
                                '<a href="' + Jsw.prepareUrl('/ip-address/edit/id/' + item.id) + '">' +
                                    ipAddressText +
                                '</a>'
                            );
                            var subNetmask = ' <span class="hint"> /' + Jsw.escapeHtml(item.mask)  + '</span>';
                            var repairButton = (item.canBeRepaired)
                            ? (' <a data-method="post" href="' + Jsw.prepareUrl('/ip-address/repair/id/' + item.id) + '">'
                              + <?php echo $this->ipAddressesList->jsLmsg('repair'); ?>
                              + '</a>')
                            : '';
                            var statusHint = '';
                            if (item.isBroken) {
                                statusHint = item.isBlacklisted ? <?php echo $this->ipAddressesList->jsLmsg('ipAddressBlacklisted'); ?>
                                    : <?php echo $this->ipAddressesList->jsLmsg('ipAddressBroken'); ?>;
                                statusHint = '<div class="hint-sub hint-attention">'
                                    + statusHint
                                    + repairButton
                                    + '</div>';
                            }

                            return link + subNetmask + statusHint;
                        }
                    },<?php if ($this->hasPublicIp) : ?>{
                        header: <?php echo $this->ipAddressesList->jsLmsg('publicAddress');?>,
                        sortable: true,
                        dataIndex: 'public_ip',
                        renderer: function (item, isDisabled) {
                            if (item.publicIp) {
                                var ipAddressText = Jsw.escapeHtml(item.publicIp);
                                if (item.isMain) {
                                    ipAddressText = '<b>' + ipAddressText + '</b>';
                                }
                                return ipAddressText;
                            }
                            return '';
                         }
                    },<?php endif; ?> {
                        header: <?php echo $this->ipAddressesList->jsLmsg('interface');?>,
                        sortable: true,
                        dataIndex: 'interface'
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('type');?>,
                        sortable: true,
                        dataIndex: 'type',
                        renderer: function (item, isDisabled) {
                            var typeHint = ('shared' === item.type
                                ? <?php echo $this->ipAddressesList->jsLmsg('typeSharedHint');?>
                                : <?php echo $this->ipAddressesList->jsLmsg('typeExclusiveHint');?>
                            );
                            return typeHint;
                        }
<?php if ($this->needResellerCountColumn) : ?>
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('resellerCount');?>,
                        sortable: true,
                        dataIndex: 'resellerCount',
                        renderer: function (item, isDisabled) {
                            return (
                                '<a href="/plesk/server/ip-address@' + item.id + '/client@">' +
                                    item.resellerCount +
                                '</a>'
                            );
                        }
<?php endif; ?>
<?php if ($this->needSubscriptionCountColumn) : ?>
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('subscriptionCount');?>,
                        sortable: true,
                        dataIndex: 'subscriptionCount',
                        renderer: function (item, isDisabled) {
                            return (
                                '<a href="/plesk/server/ip-address@' + item.id + '/domain@">' +
                                    item.subscriptionCount +
                                '</a>'
                            );
                        }
<?php endif; ?>
                    }
                ]
            })
        ]
    });
//]]>
</script>
