<?php
// Copyright 1999-2012. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<?php echo $this->partial('partials/tabs.phtml', array('tabs' => $this->tabs, 'renderTo' => 'main')); ?>

<script type="text/javascript">
//<![CDATA[
Jsw.onReady(function() {

    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',
        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.baseUrl + '/mail-list/edit/id/' + item.id + '">' +
                        item.name.escapeHTML() + '@' + item.domainName.escapeHTML() +
                    '</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) {
                    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: [
            {
                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'
            }, {
                componentType: 'Jsw.bar.Separator'
            }<?php if ($this->serviceStatusEditable): ?>, {
                componentType: 'Jsw.SmallButton',
                title: <?php echo $this->serviceEnabled ? $this->jsLmsg('buttonTurnServiceOff') : $this->jsLmsg('buttonTurnServiceOn'); ?>,
                description: <?php echo $this->serviceEnabled ? $this->jsLmsg('hintTurnServiceOff') : $this->jsLmsg('hintTurnServiceOn'); ?>,
                addCls: '<?php echo $this->serviceEnabled ? 'sb-turn-off' : 'sb-turn-on'; ?>',
                href: '/mail-list/toggle-service/turn/<?php echo $this->serviceEnabled ? 'off' : 'on'; ?>/',
                attrs: {'data-method': 'post'}
            }, {
                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',
                        subtype: 'delete',
                        mouseEvent: event,
                        locale: {
                            confirmOnGroupOperation: <?php echo $this->mailListsList->jsLmsg('confirmOnDelete'); ?>
                        }
                    });
                }
            }
        ]
    });
});
//]]>
</script>
