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

<script type="text/javascript">
//<![CDATA[
    new Jsw.Hint({
        renderTo: 'main',
        hint: <?php echo $this->jsLmsg('hint'); ?>
    });

    new Jsw.List({
        id: 'mail-lists-list',
        renderTo: 'main',
        data: <?php echo Zend_Json::encode($this->mailListsList->fetchData()); ?>,
        dataUrl: '/mail-list/list-data<?php echo $this->domainIdParam; ?>',
        searchFilters: <?php echo Zend_Json::encode($this->mailListsList->getSearchFilterConfig()); ?>,
        searchOveral: 'name',
        columns: [
            Jsw.list.COLUMN_SELECTION,
            {
                header: <?php echo $this->mailListsList->jsLmsg('name');?>,
                sortable: true,
                cls: 'max',
                dataIndex: 'name',
                renderer: function(item) {
                    var link = '<a href="' + Jsw.prepareUrl('/mail-list/edit/id/' + item.id) + '<?php echo $this->domainIdParam; ?>">' +
                        Jsw.escapeHtml(item.name) + '@' + Jsw.escapeHtml(item.domainName) +
                    '</a>';

                    var status = '';
                    if (!item.statusEnabled) {
                        status = ' <span class="hint-failed">' + <?php echo $this->mailListsList->jsLmsg('statusNotEnabled'); ?> + '</span>';
                    } else if(!item.statusOperable) {
                        status = ' <span class="hint-attention">' + <?php echo $this->mailListsList->jsLmsg('statusNotOperable'); ?> + '</span>';
                    }

                    return link + status;
                }
            }, {
                header: <?php echo $this->mailListsList->jsLmsg('subscribers');?>,
                cls: 'minor text-right',
                headerCls: 't-r',
                renderer: function(item) {
                    return item.subscribersCount;
                }
            }<?php if ($this->mailListsWebPanelUrlTemplate): ?>, {
                header: '',
                renderer: function(item) {
                    if (!item.statusEnabled || !item.statusOperable) {
                        return '';
                    }
                    var urlTemplate = <?php echo $this->jsEscape($this->mailListsWebPanelUrlTemplate) ?>;
                    var url = urlTemplate
                        .replace('%%domainName%%', item.domainName)
                        .replace('%%name%%', item.name);
                    return '<a class="s-btn sb-manage-mail-list" href="' + url + '" target="_blank"><i><i><i><span>' +
                            <?php echo $this->mailListsList->jsLmsg('openWebPanel') ?> +
                        '</span></i></i></i></a>';
                }
            }<?php endif; ?>
        ],
        operations: [
            <?php if ($this->allowCreateMailList): ?>
            {
                componentType: 'Jsw.SmallButton',
                title: <?php echo $this->jsLmsg('buttonAddNewMailList');?>,
                description: <?php echo $this->jsLmsg('hintAddNewMailList'); ?> + <?php echo $this->jsEscape(' ' . $this->resourceUsage('max_maillists')); ?>,
                addCls: 'sb-add-mail-list',
                href: '/mail-list/create<?php echo $this->domainIdParam; ?>'
            }, {
                componentType: 'Jsw.bar.Separator'
            },
            <?php endif; ?>
            {
                componentType: 'Jsw.SmallButton',
                title: <?php echo $this->mailListsList->jsLmsg('remove');?>,
                description: <?php echo $this->mailListsList->jsLmsg('hintRemove'); ?>,
                addCls: 'sb-remove-selected',
                handler: function(event) {
                    Jsw.getComponent('mail-lists-list').execGroupOperation({
                        url: '/mail-list/delete<?php echo $this->domainIdParam; ?>',
                        subtype: 'delete',
                        mouseEvent: event,
                        locale: {
                            confirmOnGroupOperation: <?php echo $this->mailListsList->jsLmsg('confirmOnDelete'); ?>
                        }
                    });
                }
            }
        ]
    });
//]]>
</script>
