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

<script type="text/javascript">
//<![CDATA[
Jsw.namespace('AdminPanel.MailSettings');
AdminPanel.MailSettings.Queue = {
    getMsgHdr: function (id) {
        <?php if ($this->serviceNodeId) echo "id += '&serviceNodeId={$this->serviceNodeId}';"; ?>
        var url = "/mail-settings/message-header?msg=" + id;
        window.open(Jsw.prepareUrl(url), "getmsghdr", "height=500,width=700,innerHeight=500,innerWidth=700,location=no,menubar=no,personalbar=no,scrollbars=yes,status=yes,titlebar=yes,toolbar=no,resizable=yes");
    },

    clean: function (context) {
        context.disable();
        var url = '/mail-settings/clean-queue<?php if ($this->serviceNodeId) echo "?serviceNodeId={$this->serviceNodeId}"; ?>';
        Jsw.api.post(Jsw.prepareUrl(url))
            .then(function (status) {
                if (status.redirect) {
                    Jsw.redirect(status.redirect);
                } else {
                    context.reload();
                }
                Jsw.clearStatusMessages();
                status.statusMessages.forEach(function (message) {
                    Jsw.addStatusMessage(message.status, message.content);
                });
            })
            .finally(function () {
                context.enable();
            });
    }
};

    new Jsw.Hint({
        id: 'mail-queue-hint',
        renderTo: 'main',
        hint: <?php echo $this->jsEscape($this->mailQueue->getHint()); ?>
    });

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'mail-queue',
                listCls: 'list list--word-breakable',
                searchFilters: <?php echo Zend_Json::encode($this->mailQueue->getSearchFilterConfig()); ?>,
                data: <?php echo Zend_Json::encode($this->mailQueue->fetchData()); ?>,
                dataUrl: '/mail-settings/queue-data<?php if ($this->serviceNodeId) echo "?serviceNodeId={$this->serviceNodeId}"; ?>',
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->mailQueue->jsLmsg('subject');?>,
                        sortable: true,
                        dataIndex: 'subject',
                        renderer: function (item) {
                            return (
                                '<div class="b-indent">' +
                                    '<span class="b-indent-icon">' +
                                        '<span class="tooltipData">' + Jsw.escapeHtml(item.queueDescription) + '</span>' +
                                        '<img src="' + Jsw.escapeHtml(item.queueIcon) + '" alt="' + Jsw.escapeHtml(item.queueDescription) + '" />' +
                                    '</span> ' +
                                    '<a href="#" onclick="AdminPanel.MailSettings.Queue.getMsgHdr(\'' + item.id + '\')">' +
                                        Jsw.escapeHtml(item.subject) +
                                    '</a>' +
                                '</div>'
                            );
                        }
                    }, {
                        header: <?php echo $this->mailQueue->jsLmsg('sender');?>,
                        sortable: true,
                        dataIndex: 'sender'
                    }, {
                        header: <?php echo $this->mailQueue->jsLmsg('recipients');?>,
                        sortable: true,
                        dataIndex: 'recipients'
                    }, {
                        header: <?php echo $this->mailQueue->jsLmsg('date');?>,
                        sortable: true,
                        dataIndex: 'date'
                    }, {
                        header: <?php echo $this->mailQueue->jsLmsg('age');?>,
                        sortable: true,
                        dataIndex: 'age'
                    }, {
                        header: <?php echo $this->mailQueue->jsLmsg('size');?>,
                        sortable: true,
                        dataIndex: 'size'
                    }
                ],
                operations: [{
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->mailQueue->jsLmsg('buttonRefresh');?>,
                    description: <?php echo $this->mailQueue->jsLmsg('buttonRefreshHint'); ?>,
                    addCls: 'sb-refresh',
                    handler: function () {
                        Jsw.getComponent('mail-queue').reload();
                    }
                }, {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonRemove',
                    title: <?php echo $this->mailQueue->jsLmsg('buttonRemove');?>,
                    description: <?php echo $this->mailQueue->jsLmsg('buttonRemoveHint'); ?>,
                    addCls: 'sb-remove-selected',
                    handler: function (event) {
                        Jsw.getComponent('mail-queue').execGroupOperation({
                            url: '/mail-settings/delete-queue<?php if ($this->serviceNodeId) echo "?serviceNodeId={$this->serviceNodeId}"; ?>',
                            subtype: 'delete',
                            mouseEvent: event,
                            locale: {
                                confirmOnGroupOperation: <?php echo $this->mailQueue->jsLmsg('confirmOnDelete'); ?>
                            }
                        });
                    }
                }, {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonClean',
                    title: <?php echo $this->mailQueue->jsLmsg('buttonClean');?>,
                    description: <?php echo $this->mailQueue->jsLmsg('buttonCleanHint'); ?>,
                    addCls: 'sb-clean',
                    handler: function () {
                        Jsw.messageBox.show({
                            'type': Jsw.messageBox.TYPE_YESNO,
                            'subtype': 'clean',
                            'text': <?php echo $this->mailQueue->jsLmsg('confirmOnClean')?>,
                            'buttonTitles': {
                                yes: <?php echo $this->jsLmsg('components.buttons.yes')?>,
                                no: <?php echo $this->jsLmsg('components.buttons.no')?>
                            },
                            'onYesClick': function () {
                                var context = Jsw.getComponent('mail-queue');
                                AdminPanel.MailSettings.Queue.clean(context);
                            }
                        });
                    }
                }],
                onRedraw: function () {
                    if (this._additionalData && this._additionalData.queueHint) {
                        Jsw.getComponent('mail-queue-hint').setHint(
                            Jsw.escapeHtml(this._additionalData.queueHint)
                        );
                    }
                },
            })
        ]
    });
//]]>
</script>
