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

<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: 'admin-plan-item-list',
                data: <?php echo Zend_Json::encode($this->planItemsList->fetchData()); ?>,
                dataUrl: '/plan-item/list-data',
                searchFilters: <?php echo Zend_Json::encode($this->planItemsList->getSearchFilterConfig()); ?>,
                operations: [
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddCustomItem',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonAddNewCustomItemButton');?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonAddNewCustomItemButtonDescription'); ?>,
                        addCls: 'sb-add-new btn-primary',
                        href: '/plan-item/create'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonMakeVisible',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemVisible'); ?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemVisibleDescription'); ?>,
                        addCls: 'sb-make-visible',
                        handler: function() {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/make-visible',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonMakeInvisible',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemInvisible'); ?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemInvisibleDescription'); ?>,
                        addCls: 'sb-make-invisible',
                        handler: function() {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/make-invisible',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveCustomItem',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonRemoveCustomItem');?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonRemoveCustomItemDescription'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/remove',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->planItemsList->jsLmsg('confirmOnDeleteSupportButton'); ?>
                                }
                            });
                        }
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->planItemsList->jsLmsg('name');?>,
                        sortable: true,
                        dataIndex: 'description',
                        renderer: function (item, isDisabled) {

                            var status = (1 != item.visible)
                            ? ( '<span class="hint-attention ">' +
                                    <?php echo $this->planItemsList->jsLmsg('itemInvisible'); ?> +
                                '</span>')
                            : '';
                            var link = (item.editable
                                ? '<span class="b-indent-icon">' +
                                    (item.img
                                        ? '<span>' +
                                          '<img src="' + item.img + '?' + <?php echo $this->jsEscape(md5(time()));?>
                                          + '" alt="" title="" width="16" height="16">' +
                                          '</span>'
                                        : ''
                                         ) +
                                  '</span>' + ' ' +
                                  '<a href="' + Jsw.prepareUrl('/plan-item/edit/id/' + item.id) + '">'
                                : '')
                                + Jsw.escapeHtml(item.description)
                                + (item.editable ? '</a>' : '')
                                + status + '<br/>'
                                + '<span class="hint">' + Jsw.escapeHtml(item.hint) + '</span>';

                            return link;
                        }
                    }, {
                        header: <?php echo $this->planItemsList->jsLmsg('numberOfSubscriptions');?>,
                        sortable: true,
                        dataIndex: 'numberOfSubscriptions',
                        renderer: function (item, isDisabled) {
                            return (
                                '<a href="' + Jsw.prepareUrl('/subscription/list/?force-show-search=true&searchFilter[planItem][searchText]=' + item.id) + '">' +
                                    Jsw.escapeHtml(item.numberOfSubscriptions) +
                                '</a>'
                            );
                        }
                    }
                ]
            })
        ]
    });
//]]>
</script>
