<?php
// Copyright 1999-2015. Parallels IP Holdings GmbH. All Rights Reserved.
?>

<script type="text/javascript">
//<![CDATA[
Jsw.onReady(function() {

    new Jsw.Panel({
        renderTo: 'main',
        cls: 'list-box',
        items: [
            new Jsw.List({
                id: 'domains-list',
                searchFilters: <?php echo Zend_Json::encode($this->domainsList->getSearchFilterConfig()); ?>,
                searchOveral: 'domainName',
                data: <?php echo Zend_Json::encode($this->domainsList->fetchData()); ?>,
                dataUrl: '<?php echo $this->url(['action' => $this->dataAction]); ?>',
                disabledSelectHint: <?php echo $this->domainsList->jsLmsg('disabledSelectHint');?>,
                operations: [
                    {
                    <?php if ($this->allowCreateDomain): ?>
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddDomain',
                        cls: 's-btn sb-new-domain',
                        title: <?php echo $this->domainsList->jsLmsg('buttonAddDomain'); ?>,
                        description: <?php echo $this->domainsList->jsLmsg('hintAddDomain'); ?>,
                        handler: function() {
                            Jsw.redirect('<?php echo $this->url(['action' => 'add-domain']); ?>');
                        }
                    }, {
                    <?php endif; ?>
                    <?php if ($this->allowManageSubdomain): ?>
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddSubDomain',
                        cls: 's-btn sb-new-subdomain',
                        title: <?php echo $this->domainsList->jsLmsg('buttonAddSubdomain'); ?>,
                        description: <?php echo $this->domainsList->jsLmsg('hintAddSubdomain'); ?>,
                        handler: function() {
                            Jsw.redirect('<?php echo $this->url(['action' => 'add-subdomain']); ?>');
                        }
                    }, {
                    <?php endif; ?>
                    <?php if ($this->allowManageDomainAliases): ?>
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddDomainAlias',
                        cls: 's-btn sb-new-domain-alias',
                        title: <?php echo $this->domainsList->jsLmsg('buttonAddDomainAlias'); ?>,
                        description: <?php echo $this->domainsList->jsLmsg('hintAddDomainAlias'); ?>,
                        handler: function() {
                            Jsw.redirect('<?php echo $this->url(['action' => 'add-domain-alias']); ?>');
                        }
                    }, {
                    <?php endif; ?>
                    <?php if ($this->allowCreateDomain || $this->allowManageSubdomain || $this->allowManageDomainAliases): ?>
                        componentType: 'Jsw.bar.Separator'
                    }, {
                    <?php endif; ?>
                        componentType: 'Jsw.list.AdditionalActions',
                        title: <?php echo $this->domainsList->jsLmsg('buttonChangeStatus'); ?>,
                        operations: [
                            {
                                componentType: 'Jsw.SmallButton',
                                id: 'buttonSuspendDomains',
                                title: <?php echo $this->domainsList->jsLmsg('buttonSuspendDomains');?>,
                                description: <?php echo $this->domainsList->jsLmsg('hintSuspendDomains'); ?>,
                                addCls: 'sb-suspend',
                                cls: 'sb-btn',
                                handler: function() {
                                    Jsw.getComponent('domains-list').execGroupOperation({
                                        url: '/domain/suspend/?redirect=<?php echo $this->url(); ?>',
                                        skipConfirmation: true
                                    });
                                }
                            }, {
                                componentType: 'Jsw.SmallButton',
                                id: 'buttonDisableDomains',
                                title: <?php echo $this->domainsList->jsLmsg('buttonDisableDomains');?>,
                                description: <?php echo $this->domainsList->jsLmsg('hintDisableDomains'); ?>,
                                addCls: 'sb-turn-off',
                                cls: 'sb-btn',
                                handler: function() {
                                    Jsw.getComponent('domains-list').execGroupOperation({
                                        url: '/domain/disable/?redirect=<?php echo $this->url(); ?>',
                                        skipConfirmation: true
                                    });
                                }
                            }, {
                                componentType: 'Jsw.SmallButton',
                                id: 'buttonActivateDomains',
                                title: <?php echo $this->domainsList->jsLmsg('buttonActivateDomains');?>,
                                description: <?php echo $this->domainsList->jsLmsg('hintActivateDomains'); ?>,
                                addCls: 'sb-activate',
                                cls: 'sb-btn',
                                handler: function() {
                                    Jsw.getComponent('domains-list').execGroupOperation({
                                        url: '/domain/activate/?redirect=<?php echo $this->url(); ?>',
                                        skipConfirmation: true
                                    });
                                }
                            }
                        ]
                    <?php if ($this->showDeleteButton): ?>
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveSite',
                        title: <?php echo $this->domainsList->jsLmsg('buttonRemove'); ?>,
                        description: <?php echo $this->domainsList->jsLmsg('hintRemove'); ?>,
                        cls: 's-btn sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('domains-list').execGroupOperation({
                                url: '<?php echo $this->url(['action' => $this->deleteAction]); ?>',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->domainsList->jsLmsg('removeConfirmation'); ?>
                                },
                                isAjax: <?php echo $this->isHomonymSearchEnabled ? 'true' : 'false' ?>,
                                requestUrl: '<?php echo $this->url(['action' => 'search-homonym-data']); ?>',
                                loadingTitle: <?php echo $this->jsLmsg('components.homonyms.loading'); ?>
                            });
                        }
                    <?php endif ?>
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->domainsList->jsLmsg('domainName');?>,
                        sortable: true,
                        dataIndex: 'domainDisplayName',
                        renderer: function(item, isDisabled) {
                            var message = '';
                            if (item.domainStatus != 0) {
                                var messageText = <?php echo $this->domainsList->jsLmsg('statusDisabled'); ?>;
                                var messageIcon = '<?php echo $this->skinUrl('/icons/16/plesk/off.png') ?>';
                                var messageAlt = 'disabled';
                                if (item.turnOffAction == 'suspend') {
                                    messageText = <?php echo $this->domainsList->jsLmsg('statusSuspended'); ?>;
                                    messageIcon = '<?php echo $this->skinUrl('/icons/16/plesk/subscription-status-suspended.png') ?>';
                                    messageAlt = 'suspended';
                                }
                                message += '<div class="b-indent"><span class="b-indent-icon"><span>' +
                                    '<span class="tooltipData">' + messageText + '</span>' +
                                    '<img src="' + messageIcon + '" alt="' + messageAlt + '" title="">' +
                                    '</span>';
                            }
                            <?php if (!$this->isPoaAvailable): ?>
                                var returnUrl = Jsw.baseUrl + '/subscription/overview/id/' + item.webspaceId;
                                message += '<a href="' + Jsw.baseUrl + '/subscription/login/id/' + item.webspaceId + '?pageUrl=%2Fweb%2Foverview%2Fid%2F' +
                                    encodeURIComponent(item.id.replace('alias', 'a').replace('domain', item.parentDomainId > 0 ? 's': 'd')) + '&returnUrl=' + encodeURIComponent(returnUrl) + '">' +
                                    item.domainDisplayName.escapeHTML() + '</a>';
                            <?php else: ?>
                            message += item.domainDisplayName.escapeHTML();
                            <?php endif ?>
                            if (item.domainStatus != 0) {
                                message += '</span></div>';
                            }

                            var description = '';
                            if (item.adminDescription) {
                                description += '<div class="hint">' + item.adminDescription.truncate(50, '...').escapeHTML()  + '<span class="tooltipData">' + item.adminDescription.escapeHTML() + '</span></div>';
                            }
                            if (item.resellerDescription) {
                                var descriptionTitle = (item.hideResellerTitleDescription) ? '' : <?php echo $this->domainsList->jsLmsg('resellerDescription');?> +  ': ';
                                description += '<div class="hint">'
                                    + descriptionTitle
                                    + item.resellerDescription.truncate(50, '...').escapeHTML() + '<span class="tooltipData">' + item.resellerDescription.escapeHTML() + '</span></div>';
                            }
                            if (item.ownerDescription) {
                                description += '<div class="hint">' + <?php echo $this->domainsList->jsLmsg('ownerDescription');?>
                                    + ': ' + item.ownerDescription.truncate(50, '...').escapeHTML() + '<span class="tooltipData">' + item.ownerDescription.escapeHTML() + '</span></div>';
                            }
                            message += description;

                            return message;
                        }
                    }, <?php echo $this->partial('partials/icp-permit-classic.phtml', [
                            'link' => Plesk_Config::get()->domainManagement->features->icpPermitLink,
                        ]) ?>{
                        header: <?php echo $this->domainsList->jsLmsg('hostingType');?>,
                        sortable: true,
                        dataIndex: 'hostingType',
                        renderer: function(item, isDisabled) {
                            var message = '';

                            if (item.hostingType == 'alias') {
                                message = '<img src="<?php echo $this->skinUrl('/icons/16/plesk/dns.png') ?>"/>'
                                    + ' '
                                    + <?php echo $this->domainsList->jsLmsg('aliasFor'); ?>
                                    + ' '
                                    + '<a href="http://' + item.realDomainName.escapeHTML() + '" target="_blank">'
                                    + item.realDomainDisplayName.escapeHTML()
                                    + '</a>';
                            } else if (item.hostingType == 'vrt_hst') {
                                message = '<img src="<?php echo $this->skinUrl('/icons/16/plesk/website.png') ?>"/>'
                                    + ' '
                                    + (item.parentDomainId > 0 ?
                                    <?php echo $this->domainsList->jsLmsg('subdomainWebsite') ?> :
                                    <?php echo $this->domainsList->jsLmsg('website'); ?>);

                            } else if (item.hostingType == 'none') {
                                message = '<img src="<?php echo $this->skinUrl('/icons/16/plesk/spacer.png') ?>" />'
                                    + '<em class="hint">' + <?php echo $this->domainsList->jsLmsg('noHosting'); ?> + '</em>';

                            } else if (item.hostingType == 'frm_fwd' || item.hostingType == 'std_fwd') {

                                message = '<img src="<?php echo $this->skinUrl('/icons/16/plesk/forward-to-dom.png') ?>"/>'
                                    + ' '
                                    + <?php echo $this->domainsList->jsLmsg('forwardingTo'); ?>
                                    + ' '
                                    + '<a href="' + item.forwardingUrl.escapeHTML() + '" target="_blank">'
                                    + item.forwardingDisplayUrl.escapeHTML()
                                    + '</a>';
                            }

                            return message;
                        }
                    <?php if ($this->showOwnerName): ?>
                    }, {
                        header: <?php echo $this->domainsList->jsLmsg('ownerName');?>,
                        sortable: true,
                        dataIndex: 'ownerName',
                        renderer: function(item, isDisabled) {
                            var linkHref = null;
                            <?php if (!$this->isPoaAvailable): ?>
                            if (item.ownerId != <?php echo \Session::get()->auth()->getUser()->getClient()->getId() ?>) {
                                if ('client' == item.ownerType) {
                                    linkHref = 'customer';
                                } else if ('reseller' == item.ownerType) {
                                    linkHref = 'reseller';
                                }
                            }
                            <?php endif; ?>
                            var link =
                                (linkHref ? '<a href="' + Jsw.baseUrl + '/' + linkHref + '/overview/id/' + item.ownerId + '">' : '')
                                    + item.ownerName.escapeHTML() +
                                (linkHref ? '</a>' : '') +
                                (item.ownerCompanyName ? ', ' + item.ownerCompanyName.escapeHTML() : '');
                            return link;
                        }
                    <?php endif ?>
                    }, {
                        header: <?php echo $this->domainsList->jsLmsg('setupDate');?>,
                        sortable: true,
                        dataIndex: 'setupDate',
                        renderer: function(item, isDisabled) {
                            return item.setupDateString.escapeHTML();
                        }
                    <?php if ($this->showExpirationDate): ?>
                    }, {
                        header: <?php echo $this->domainsList->jsLmsg('expirationDate');?>,
                        sortable: false,
                        dataIndex: 'expirationDate',
                        renderer: function(item, isDisabled) {
                            if (item.expirationDateString) {
                                return item.expirationDateString.escapeHTML();
                            } else {
                                return '&mdash;';
                            }
                        }
                    <?php endif ?>
                    }, {
                        header: <?php echo $this->domainsList->jsLmsg('diskUsage');?>,
                        sortable: true,
                        dataIndex: 'realSize',
                        renderer: function(item, isDisabled) {
                            return item.diskUsage.escapeHTML();
                        }
                    }, {
                        header: <?php echo $this->domainsList->jsLmsg('traffic');?>,
                        sortable: false,
                        dataIndex: 'traffic'
                    }, {
                        header: '',
                        sortable: false,
                        renderer: function(item, isDisabled) {
                            if (item.hostingType == 'none') {
                                return '';
                            }

                            return '<a href="http://' + item.realDomainName + '" class="s-btn sb-view-site" target="_blank"><span>' +
                                    <?php echo $this->domainsList->jsLmsg('viewSite'); ?> +
                                    '</span></a>';
                        }
                    <?php if (!$this->isPoaAvailable): ?>
                    }, {
                        header: '',
                        sortable: false,
                        renderer: function(item, isDisabled) {
                            if (item.ownerId == <?php echo \Session::get()->auth()->getUser()->getClient()->getId() ?>) {
                                return '';
                            }

                            var href = '/admin' + (item.ownerType == '<?php echo Client::TYPE_RESELLER ?>' ? '/reseller' : '/customer') + '/login/id/' + item.ownerId +
                                    '?pageUrl=' + encodeURIComponent('/smb/account/switch/all/true?returnUrl=/web/overview/id/' + item.id.replace('alias', 'a').replace('domain', item.parentDomainId > 0 ? 's': 'd'));

                            return '<a href="' + href + '" class="s-btn sb-login"><span>' +
                                    (item.ownerType == '<?php echo Client::TYPE_RESELLER ?>' ? <?php echo $this->domainsList->jsLmsg('manageInResellerPanel') ?> : <?php echo $this->domainsList->jsLmsg('manageInCustomerPanel') ?>) +
                                    '</span></a>';
                        }
                    <?php endif ?>
                    }
                ]
            })
        ]
    });
});
//]]>
</script>
