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

<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="customers-list"></div>

<script type="text/javascript">
//<![CDATA[
    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'customers-list',
        items: [
            new Jsw.List({
                id: 'customers-list',
                searchFilters: <?php echo Zend_Json::encode($this->customersList->getSearchFilterConfig()); ?>,
                searchOveral: 'name',
                data: <?php echo Zend_Json::encode($this->customersList->fetchData()); ?>,
                dataUrl: '/business-model-upgrade/customers-data',
                operations: [
                    {
                        componentType: 'Jsw.list.AdditionalActions',
                        title: <?php echo $this->customersList->jsLmsg('bunchSolutions'); ?>,
                        operations: [
                             {
                                 componentType: 'Jsw.SmallButton',
                                 id: 't1s1ApplyButton',
                                 title: <?php echo $this->customersList->jsLmsg('t1s1ApplyButton');?>,
                                 description: <?php echo $this->customersList->jsLmsg('t1s1ApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-t1s1',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('customers-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-customer-solution/solution/t1s1/?redirect=/business-model-upgrade/customers/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->customersList->jsLmsg('t1s1ApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->customersList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 't1s2ApplyButton',
                                 title: <?php echo $this->customersList->jsLmsg('t1s2ApplyButton');?>,
                                 description: <?php echo $this->customersList->jsLmsg('t1s2ApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-t1s2',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('customers-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-customer-solution/solution/t1s2/?redirect=/business-model-upgrade/customers/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->customersList->jsLmsg('t1s2ApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->customersList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 't1s3ApplyButton',
                                 title: <?php echo $this->customersList->jsLmsg('t1s3ApplyButton');?>,
                                 description: <?php echo $this->customersList->jsLmsg('t1s3ApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-t1s3',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('customers-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-customer-solution/solution/t1s3/?redirect=/business-model-upgrade/customers/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->customersList->jsLmsg('t1s3ApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->customersList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 't1s6cApplyButton',
                                 title: <?php echo $this->customersList->jsLmsg('t1s6cApplyButton');?>,
                                 description: <?php echo $this->customersList->jsLmsg('t1s6cApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-t1s6c',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('customers-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-customer-solution/solution/t1s6c/?redirect=/business-model-upgrade/customers/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->customersList->jsLmsg('t1s6cApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->customersList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }<?php if ($this->isUpgradeToResellerAvailable): ?>, {
                                 componentType: 'Jsw.SmallButton',
                                 id: 't1s6rApplyButton',
                                 title: <?php echo $this->customersList->jsLmsg('t1s6rApplyButton');?>,
                                 description: <?php echo $this->customersList->jsLmsg('t1s6rApplyHint') ?>,
                                 addCls: 'sb-business-model-upgrade-solution sb-business-model-upgrade-solution-t1s6r',
                                 cls: 'sb-btn',
                                 handler: function() {
                                     Jsw.getComponent('customers-list').execGroupOperation({
                                         url: '/business-model-upgrade/manual-customer-solution/solution/t1s6r/?redirect=/business-model-upgrade/customers/',
                                         subtype: 'toggle',
                                         needAttention: true,
                                         needAttentionText: <?php echo $this->customersList->jsLmsg('t1s6rApplyHint'); ?>,
                                         needAttentionBlockSubmit: true,
                                         locale: {
                                             confirmOnGroupOperation: <?php echo $this->customersList->jsLmsg('applyConfirmation'); ?>
                                         }
                                     });
                                 }
                             }<?php endif; ?>
                        ]
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->customersList->jsLmsg('customerName');?>,
                        sortable: true,
                        dataIndex: 'customerName',
                        cls: 'name',
                        renderer: function (item) {
                            return (
                                '<a href="' + Jsw.prepareUrl('/customer/overview/id/' + item.id) + '">' +
                                    Jsw.escapeHtml(item.customerName) +
                                '</a>' +
                                (item.companyName && item.companyName.length ? ', ' + Jsw.escapeHtml(item.companyName) : '')
                            );
                        }
                    }<?php if ($this->isUpgradeToResellerAvailable): ?>, {
                        header: <?php echo $this->customersList->jsLmsg('ownerName');?>,
                        sortable: true,
                        dataIndex: 'ownerName',
                        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.ownerName) +
                                (linkHref ? '</a>' : '') +
                                (item.ownerCompanyName ? ', ' + Jsw.escapeHtml(item.ownerCompanyName) : '');
                            return link;
                        }
                    }<?php endif; ?>, {
                        header: <?php echo $this->customersList->jsLmsg('subscription');?>,
                        sortable: false,
                        dataIndex: 'subscriptions',
                        renderer: function (item) {
                            var ret = '';
                            $A(item.subscriptions).each(function(subscription){
                                ret += '<div class="owned-subscription"><a href="' + Jsw.prepareUrl('/subscription/overview/id/' + subscription.id) + '">';
                                ret += Jsw.escapeHtml(subscription.domainDisplayName);
                                ret += '</a></div>';
                            });
                            return ret;
                        }
                    }
                ]
            })
        ]
    });
//]]>
</script>
