<?php
// Copyright 1999-2021. Plesk 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: 'service-instance-list',
                searchFilters: <?php echo Zend_Json::encode($this->serviceInstanceList->getSearchFilterConfig()); ?>,
                searchOveral: 'name',
                data: <?php echo Zend_Json::encode($this->serviceInstanceList->fetchData()); ?>,
                dataUrl: '/service-instance/list-data/package/<?php echo $this->packageId ?>/',
                <?php if ($this->showAddButton) { ?>
                operations: [
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddNewService',
                        title: <?php echo $this->serviceInstanceList->jsLmsg('buttonAddServiceToSubscription');?>,
                        description: <?php echo $this->serviceInstanceList->jsLmsg('buttonAddServiceToSubscriptionHint') ?>,
                        addCls: 'sb-add-new',
                        href: '/service-instance/create/package/<?php echo $this->packageId ?>'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemove',
                        addCls: 'sb-remove-selected',
                        title: <?php echo $this->serviceInstanceList->jsLmsg('buttonRemove'); ?>,
                        description: <?php echo $this->serviceInstanceList->jsLmsg('buttonRemoveHint'); ?>,
                        handler: function(event) {
                            Jsw.getComponent('service-instance-list').execGroupOperation({
                                url: '/service-instance/delete/package/<?php echo $this->packageId ?>?redirect=/service-instance/list/package/<?php echo $this->packageId ?>',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->serviceInstanceList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    }
                ],
                <?php } ?>
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->serviceInstanceList->jsLmsg('name');?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function (item, isDisabled) {
                            var itemHtml;
                            if (item.hasPropertiesForm || item.hasResources) {
                                itemHtml = '<a href="' + Jsw.prepareUrl('/service-instance/edit/reference/' + encodeURIComponent(item.reference) + '">' + Jsw.escapeHtml(item.name) + '</a>';
                            } else {
                                itemHtml = Jsw.escapeHtml(item.name);
                            }

                            var status = 'ok';
                            var statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/subscription-status-ok.png') ?>';
                            var statusDescription =<?php echo $this->serviceInstanceList->jsLmsg('isEnabled');?>;
                            if (!item.enabled) {
                                status = 'suspended';
                                statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/subscription-status-suspended.png') ?>';
                                statusDescription = <?php echo $this->serviceInstanceList->jsLmsg('isDisabled');?>;
                            }

                            return (
                                '<div class="b-indent">' +
                                    '<span class="b-indent-icon">' +
                                        '<span class="tooltipData">' + Jsw.escapeHtml(statusDescription) + '</span>' +
                                        '<img src="' + statusIcon + '" alt="' + status + '" title="">' +
                                    '</span> '
                                    '<nobr>' + itemHtml + '</nobr>' +
                                + '</div>'
                            );
                        },
                    }, {
                        header: <?php echo $this->serviceInstanceList->jsLmsg('type');?>,
                        sortable: true,
                        dataIndex: 'type',
                        renderer: function (item, isDisabled) {
                            return Jsw.escapeHtml(item.type);
                        },
                    }, {
                        header: <?php echo $this->serviceInstanceList->jsLmsg('requiredServices');?>,
                        sortable: true,
                        dataIndex: 'requiredInstances',
                        renderer: function (item, isDisabled) {
                            var requiredItems = '';
                            var i;
                            var r;
                            for (i = 0; i < item.requiredInstances.length; i++) {
                                r = item.requiredInstances[i];
                                if (r.hasPropertiesForm || r.hasResources) {
                                    requiredItems += '<a href="' + Jsw.prepareUrl('/service-instance/edit/reference/' + encodeURIComponent(r.packageReference) + '">' + Jsw.escapeHtml(r.name) + '</a>';
                                } else {
                                    requiredItems += Jsw.escapeHtml(r.name);
                                }
                                requiredItems += '&nbsp;&nbsp;';
                            }
                            return '<nobr>' + requiredItems + '</nobr>';
                        },
                    }, {
                        header: <?php echo $this->serviceInstanceList->jsLmsg('description');?>,
                        sortable: true,
                        dataIndex: 'description',
                        renderer: function (item, isDisabled) {
                            return '<span class="hint">' + Jsw.escapeHtml(item.description) + '</span>';
                        },
                    },
                ]
            })
        ]
    });
//]]>
</script>
