<?php
// Copyright 1999-2024. WebPros 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: 'customer-service-plan-list',
                data: <?php echo Zend_Json::encode($this->plansList->fetchData()); ?>,
                dataUrl: '/customer-service-plan/list-data',
                disabledSelectHint: <?php echo $this->plansList->jsLmsg('disabledSelectHint');?>,
                searchFilters: <?php echo Zend_Json::encode($this->plansList->getSearchFilterConfig()); ?>,
        		<?php if ($this->ownerColumnRequired) : ?>
                searchOveral: 'planName',
                <?php endif; ?>
                operations: [
                    <?php if ($this->hasChangeLimitsPermission): ?>
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddNewPlan',
                        title: <?php echo $this->plansList->jsLmsg('buttonAddNewPlan');?>,
                        description: <?php echo $this->plansList->jsLmsg('hintAddNewPlan'); ?>,
                        addCls: 'sb-add-new-plan btn-primary',
                        href: '/customer-service-plan/create'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonDuplicatePlans',
                        title: <?php echo $this->plansList->jsLmsg('buttonDuplicatePlans');?>,
                        description: <?php echo $this->plansList->jsLmsg('hintDuplicatePlans'); ?>,
                        addCls: 'sb-copy-selected',
                        handler: function(event) {
                            Jsw.getComponent('customer-service-plan-list').execGroupOperation({
                                url: '/customer-service-plan/duplicate-plans/?redirect=/customer-service-plan/list/',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddNewAddonPlan',
                        title: <?php echo $this->plansList->jsLmsg('buttonAddNewAddonPlan');?>,
                        description: <?php echo $this->plansList->jsLmsg('hintAddNewAddonPlan'); ?>,
                        addCls: 'sb-add-new-addon',
                        href: '/customer-service-plan/create-addon'
                    },
                    {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemovePlan',
                        title: <?php echo $this->plansList->jsLmsg('buttonRemove');?>,
                        description: <?php echo $this->plansList->jsLmsg('hintRemove'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('customer-service-plan-list').execGroupOperation({
                                url: '/customer-service-plan/delete/?redirect=/customer-service-plan/list/',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->plansList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    }
                    <?php endif; ?>
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->plansList->jsLmsg('planName');?>,
                        sortable: true,
                        dataIndex: 'planName',
                        renderer: function (item, isDisabled) {
                            var link = (
                                '<span><a href="' + Jsw.prepareUrl('/customer-service-plan/edit/id/' + item.id) + '">' +
                                    Jsw.escapeHtml(item.planName) +
                                '</a></span>'
                            );
                            return link +
                                ('domain_addon' === item.planType
                                    ? ' <span class="hint">' + <?php echo $this->plansList->jsLmsg('addonPlanType');?> + '</span>'
                                    : ''
                                );

                        },
                    }, {
                        header: <?php echo $this->plansList->jsLmsg('planTraffic');?>,
                        sortable: true,
                        dataIndex: 'traffic',
                        renderer: function (item, isDisabled) {
                            return Jsw.escapeHtml(item.trafficString);
                        },
                    }, {
                        header: <?php echo $this->plansList->jsLmsg('planDiskSpace');?>,
                        sortable: true,
                        dataIndex: 'diskSpace',
                        renderer: function (item, isDisabled) {
                            return Jsw.escapeHtml(item.diskSpaceString);
                        },
<?php if ($this->ownerColumnRequired) : ?>
                    }, {
                        header: <?php echo $this->plansList->jsLmsg('planOwner');?>,
                        sortable: true,
                        dataIndex: 'ownerContactName',
                        renderer: function (item, isDisabled) {
                            var linkHref = null;
                            if ('client' == item.ownerType) {
                                linkHref = 'customer';
                            } else
                            if ('reseller' == item.ownerType) {
                                linkHref = 'reseller';
                            }
                            var link =
                                (linkHref ? '<a href="' + Jsw.prepareUrl('/' + linkHref + '/overview/id/' + item.ownerId) + '">' : '')
                                    + Jsw.escapeHtml(item.ownerContactName) +
                                (linkHref ? '</a>' : '') +
                                (item.ownerCompanyName ? ', ' + Jsw.escapeHtml(item.ownerCompanyName) : '');
                            return link;
                        },
<?php endif; ?>
                    }, {
                        header: <?php echo $this->plansList->jsLmsg('planSubscriptions');?>,
                        sortable: true,
                        dataIndex: 'subscriptions',
                        renderer: function (item, isDisabled) {
                            return (
                                '<a href="' + Jsw.prepareUrl('/subscription/list?force-show-search=true&searchFilter[planName][searchText]=' + item.id) + '">' +
                                    Jsw.escapeHtml(item.subscriptions) +
                                '</a>'
                            );
                        },
                    },
                ],
            })
        ]
    });
//]]>
</script>
