<?php
// Copyright 1999-2012. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<p><?php echo $this->lmsg('hint'); ?></p>

<script type="text/javascript">
//<![CDATA[
Jsw.onReady(function() {
    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',
                        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->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 = item.name.escapeHTML();
                            if (item.isMain) {
                                ipAddressText = '<b>' + ipAddressText + '</b>';
                            }
                            var link = '<a href="' + Jsw.baseUrl + '/ip-address/edit/id/' + item.id + '">'
                                + ipAddressText
                                + '</a>';
                            var typeHint = ('shared' == item.type
                                ? ' <span class="hint"> (' + <?php echo $this->ipAddressesList->jsLmsg('typeSharedHint');?> + ')</span>'
                                : ' <span class="hint"> (' + <?php echo $this->ipAddressesList->jsLmsg('typeExclusiveHint');?> + ')</span>'
                            );

                            var repairButton = (item.canBeRepaired)
                            ? (' <a data-method="post" href="' + Jsw.baseUrl + '/ip-address/repair/id/' + item.id + '">'
                              + <?php echo $this->ipAddressesList->jsLmsg('repair'); ?>
                              + '</a>')
                            : '';
                            var statusHint = (item.isBroken)
                            ? ('<div class="hint-attention">'
                                + <?php echo $this->ipAddressesList->jsLmsg('ipAddressBroken'); ?>
                                + repairButton
                                + '</div>')
                            : '';

                            return link + typeHint + statusHint;
                        }
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('mask');?>,
                        sortable: true,
                        dataIndex: 'prefixSize',
                        renderer: function(item, isDisabled) {
                            return item.mask.escapeHTML();
                        }
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('interface');?>,
                        sortable: true,
                        dataIndex: 'interface'
<?php if ($this->needResellerCountColumn) : ?>
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('resellerCount');?>,
                        sortable: true,
                        dataIndex: 'resellerCount',
                        renderer: function(item, isDisabled) {
                            var link = '<a href="/plesk/server/ip-address@' + item.id + '/client@">'
                            + item.resellerCount
                            + '</a>';

                            return link;
                        }
<?php endif; ?>
<?php if ($this->needSubscriptionCountColumn) : ?>
                    }, {
                        header: <?php echo $this->ipAddressesList->jsLmsg('subscriptionCount');?>,
                        sortable: true,
                        dataIndex: 'subscriptionCount',
                        renderer: function(item, isDisabled) {
                            var link = '<a href="/plesk/server/ip-address@' + item.id + '/domain@">'
                                + item.subscriptionCount
                                + '</a>';

                            return link;
                        }
<?php endif; ?>
                    }
                ]
            })
        ]
    });
});
//]]>
</script>
