<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<?php $additionalColumns = $this->subserviceInstancesList->getAdditionalColumns(); ?>
new Jsw.Panel({
    cls: 'list-box',
    title: <?php echo $this->jsLmsg('subserviceTitle', array('service' => $this->serviceName)); ?>,
    items: [
        new Jsw.Hint({
            hint: <?php echo $this->jsLmsg('subserviceHint'); ?>
        }),

        new Jsw.List({
            id: 'subservice-instances-list-<?php echo $this->apsMetaId; ?>',
            searchOveral: 'id',
            data: <?php echo Zend_Json::encode($this->subserviceInstancesList->fetchData()); ?>,
            dataUrl: '/subservice/instances-list-data/resourceId/<?php echo $this->registryResourceId; ?>/metaId/<?php echo $this->apsMetaId; ?>',
            columns: [
                Jsw.list.COLUMN_SELECTION,
                {
                    header: <?php echo $this->subserviceInstancesList->jsLmsg('serviceName');?>,
                    renderer: function(item) {
                        return '<a href="' + Jsw.prepareUrl('/service/index/resourceId/' + item.registryResourceId) + '">'
                            + <?php echo $this->jsEscape($this->serviceName); ?> + '</a>';
                    }
                } <?php if (!isset($additionalColumns['_email'])): ?>, {
                    header: <?php echo $this->subserviceInstancesList->jsLmsg('userName');?>,
                    cls: 'minor',
                    sortable: true,
                    dataIndex: 'userName',
                    renderer: function(item, isDisabled) {
                        if (item.userId) {
                            return '<a href="' + Jsw.prepareUrl('/user/edit/id/' + item.userId) + '">'
                                + Jsw.escapeHtml(item.userName) + '</a>';
                        } else {
                            return '';
                        }
                    }
                } <?php endif; ?> <?php foreach ($additionalColumns as $column): ?>, {
                    header: <?php echo $this->jsEscape($column) ?>,
                    dataIndex: <?php echo $this->jsEscape($column) ?>
                } <?php endforeach; ?>
            ],
            operations: [
                {
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->jsLmsg('buttonAddNewSubserviceInstance', array('name' => $this->serviceName));?>,
                    description: <?php echo $this->jsLmsg('hintAddNewSubserviceInstance', array('name' => $this->serviceName)); ?>,
                    addCls: 'sb-add-subservice-instance',
                    href: '/service/install/resourceId/<?php echo $this->registryResourceId; ?>/metaId/<?php echo $this->apsMetaId; ?>'
                }, {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->jsLmsg('buttonCustomizeColumns');?>,
                    description: <?php echo $this->jsLmsg('hintCustomizeColumns'); ?>,
                    addCls: 'sb-customize-columns',
                    href: '/subservice/customize-list-columns/resourceId/<?php echo $this->registryResourceId; ?>/metaId/<?php echo $this->apsMetaId; ?>'
                }, {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonRemoveSubserviceInstance',
                    title: <?php echo $this->subserviceInstancesList->jsLmsg('remove');?>,
                    description: <?php echo $this->subserviceInstancesList->jsLmsg('hintRemove'); ?>,
                    addCls: 'sb-remove-selected',
                    handler: function(event) {
                        Jsw.getComponent('subservice-instances-list-<?php echo $this->apsMetaId; ?>').execGroupOperation({
                            url: '/subservice/delete-instance',
                            subtype: 'delete',
                            mouseEvent: event,
                            locale: {
                                confirmOnGroupOperation: <?php echo $this->subserviceInstancesList->jsLmsg('confirmOnDelete'); ?>
                            }
                        });
                    }
                }
            ]
        })
    ]
})
