<?php
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
?>
<script type="text/javascript">
//<![CDATA[
    new Jsw.Hint({
        renderTo: 'main',
        hint: <?php echo $this->jsLmsg('hint'); ?>
    });

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'webmails-list',
                searchFilters: <?php echo Zend_Json::encode($this->webmailsList->getSearchFilterConfig()); ?>,
                searchOveral: 'name',
                data: <?php echo Zend_Json::encode($this->webmailsList->fetchData()); ?>,
                dataUrl: '/webmail/list-data',
                disabledSelectHint: <?php echo $this->webmailsList->jsLmsg('disabledSelectHint');?>,
                operations: [
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddNewWebmail',
                        title: <?php echo $this->webmailsList->jsLmsg('buttonAddNewWebmail');?>,
                        description: <?php echo $this->webmailsList->jsLmsg('hintAddNewWebmail') ?>,
                        addCls: 'sb-add-new-webmail btn-primary',
                        href: '/webmail/create'
                    },{
                        componentType: 'Jsw.bar.Separator'
                    },{
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonEnableWebmail',
                        title: <?php echo $this->webmailsList->jsLmsg('buttonEnableWebmail');?>,
                        description: <?php echo $this->webmailsList->jsLmsg('hintEnableWebmail') ?>,
                        addCls: 'sb-activate',
                        handler: function() {
                            Jsw.getComponent('webmails-list').execGroupOperation({
                                url: '/webmail/enable',
                                subtype: 'toggle',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonDisableWebmail',
                        title: <?php echo $this->webmailsList->jsLmsg('buttonDisableWebmail');?>,
                        description: <?php echo $this->webmailsList->jsLmsg('hintDisableWebmail') ?>,
                        addCls: 'sb-suspend',
                        handler: function() {
                            Jsw.getComponent('webmails-list').execGroupOperation({
                                url: '/webmail/disable',
                                subtype: 'toggle',
                                skipConfirmation: true
                            });
                        }
                    },{
                        componentType: 'Jsw.bar.Separator'
                    },{
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveWebmail',
                        title: <?php echo $this->webmailsList->jsLmsg('buttonRemoveWebmail') ?>,
                        description: <?php echo $this->webmailsList->jsLmsg('hintRemoveWebmail') ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('webmails-list').execGroupOperation({
                                url: '/webmail/remove',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->webmailsList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    },
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->webmailsList->jsLmsg('name');?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function (item, isDisabled) {
                            var status = 'ok';
                            var statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/subscription-status-ok.png') ?>';
                            var statusDescription =<?php echo $this->webmailsList->jsLmsg('statusOk');?>;
                            if (!item.enabled) {
                                status = 'suspended';
                                statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/subscription-status-suspended.png') ?>';
                                statusDescription = <?php echo $this->webmailsList->jsLmsg('statusSuspended');?>;
                            }
                            var name = Jsw.escapeHtml(item.name);
                            if (item.url) {
                                name = '<a href="' + Jsw.prepareUrl('/webmail/edit/id/' + encodeURIComponent(item.id)) + '">' + name + '</a>';
                            }

                            return (
                                '<div class="b-indent">' +
                                    '<span class="b-indent-icon">' +
                                        '<span class="tooltipData">' + Jsw.escapeHtml(statusDescription) + '</span>' +
                                        '<img src="' + statusIcon + '" alt="' + status + '" title="">' +
                                    '</span> ' +
                                    name +
                                '</div>'
                            );
                        },
                    }, {
                        header: <?php echo $this->webmailsList->jsLmsg('url');?>,
                        sortable: false,
                        dataIndex: 'subscriptions',
                        renderer: function (item, isDisabled) {
                            var ret = item.url
                                ? "<a target='_blank' href='" + Jsw.escapeHtml(item.url) + "'>" + Jsw.escapeHtml(item.url) +"</a>"
                                : '';

                            return ret;
                        },
                    }
                ]
            })
        ]
    });
//]]>
</script>
