<?php
// Copyright 1999-2022. Plesk International GmbH. All rights reserved.
?>
<?php echo $this->partial('business-model-upgrade/_tabs.phtml', array(
    'currentTab' => 'subscriptions',
)); ?>

<p><?php echo $this->lmsg('description') ?></p>

<p><a href="#" onClick="top.OpenHelpWindow('business-model-upgrade.bunch.description');"><?php echo $this->lmsg('help') ?></a></p>

<div id="subscriptions-list"></div>

<script type="text/javascript">
//<![CDATA[
    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'subscriptions-list',
        items: [
            new Jsw.List({
                id: 'subscriptions-list',
                searchFilters: <?php echo Zend_Json::encode($this->subscriptionsList->getSearchFilterConfig()); ?>,
                searchOveral: 'name',
                data: <?php echo Zend_Json::encode($this->subscriptionsList->fetchData()); ?>,
                dataUrl: '/business-model-upgrade/subscriptions-data',
                operations: [
                    {
                         componentType: 'Jsw.list.AdditionalActions',
                         title: <?php echo $this->subscriptionsList->jsLmsg('bunchSolutions'); ?>,
                         operations: [
                            {
                                 componentType: 'Jsw.SmallButton',
                                 id: 'toCustomerApplyButton',
                                 title: <?php echo $this->subscriptionsList->jsLmsg('toCustomerApplyButton');?>,
                                 description: <?php echo $this->subscriptionsList->jsLmsg('toCustomerApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-subscription-to-customer',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('subscriptions-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-subscription-solution/solution/toCustomer/?redirect=/business-model-upgrade/subscriptions/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->subscriptionsList->jsLmsg('toCustomerApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->subscriptionsList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 'toSubscriptionWithUsersApplyButton',
                                 title: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithUsersApplyButton');?>,
                                 description: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithUsersApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-subscription-to-subscription-with-users',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('subscriptions-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-subscription-solution/solution/toSubscriptionWithUsers/?redirect=/business-model-upgrade/subscriptions/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithUsersApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->subscriptionsList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 'toSubscriptionWithoutUsersApplyButton',
                                 title: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithoutUsersApplyButton');?>,
                                 description: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithoutUsersApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-subscription-to-subscription-without-users',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('subscriptions-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-subscription-solution/solution/toSubscriptionWithoutUsers/?redirect=/business-model-upgrade/subscriptions/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->subscriptionsList->jsLmsg('toSubscriptionWithoutUsersApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->subscriptionsList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }
                         ]
                     }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->subscriptionsList->jsLmsg('subscriptionName');?>,
                        sortable: true,
                        dataIndex: 'subscriptionName',
                        cls: 'name',
                        renderer: function (item) {
                            return (
                                '<a href="' + Jsw.prepareUrl('/subscription/overview/id/' + item.id) + '">' +
                                    Jsw.escapeHtml(item.subscriptionName) +
                                '</a>'
                            );
                        }
                    }, {
                        header: <?php echo $this->subscriptionsList->jsLmsg('ownerName');?>,
                        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;
                        }
                    }
                ]
            })
        ]
    });
//]]>
</script>
