<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<script type="text/javascript">
//<![CDATA[

Jsw.onReady(function() {

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'statistics-list',
                searchOveral: 'domain',
                searchFilters: <?php echo Zend_Json::encode($this->statisticsList->getSearchFilterConfig()); ?>,
                data: <?php echo Zend_Json::encode($this->statisticsList->fetchData()); ?>,
                dataUrl: '/statistics/list-data',
                columns: [
                    {
                        header: <?php echo $this->jsLmsg('webspace'); ?>,
                        sortable: true,
                        renderer: function (item) {
                            var returnUrl = Jsw.prepareUrl('/statistics/details');
                            var subscriptionName = '<a href="' + Jsw.prepareUrl('/account/switch/id/' + item.id + '?hideNotice=1&returnUrl=' + encodeURIComponent(returnUrl)) + '">'
                                + item.domain + '</a>';

                            return subscriptionName;
                        },
                    }, {
                        header: <?php echo $this->jsLmsg('systemUser'); ?>,
                        sortable: true,
                        dataIndex: 'systemUser'
                    }, {
                        header: <?php echo $this->jsLmsg('diskSpace'); ?>,
                        sortable: false,
                        headerParams: { width: 250 },
                        cls: 'minor',
                        renderer: function(item) {
                            if (-1 == item.diskSpaceDetails.percent) {
                                return '<div class="progress-label">' + item.diskSpaceDetails.usageString + '</div>';
                            }

                            var overuseClass = '';
                            if (100 == item.diskSpaceDetails.percent) {
                                overuseClass = 'progress-bar-danger';
                            }

                            var result =
                                '<div class="progress-box">' +
                                    '<div class="progress progress-sm">' +
                                        '<div class="progress-bar ' + overuseClass + '" style="width: ' + item.diskSpaceDetails.percent + '%;"></div>' +
                                    '</div>' +
                                    '<div class="progress-label">' + item.diskSpaceDetails.usageString + '</div>' +
                                '</div>';

                            return result;
                        }
                    }, {
                        header: <?php echo $this->jsLmsg('traffic'); ?>,
                        sortable: false,
                        headerParams: { width: 250 },
                        cls: 'minor',
                        renderer: function(item) {
                            if (-1 == item.trafficDetails.percent) {
                                return '<div class="progress-label">' + item.trafficDetails.usageString + '</div>';
                            }

                            var overuseClass = '';
                            if (100 == item.trafficDetails.percent) {
                                overuseClass = 'progress-bar-danger';
                            }

                            var result =
                                '<div class="progress-box">' +
                                    '<div class="progress progress-sm">' +
                                        '<div class="progress-bar ' + overuseClass + '" style="width: ' + item.trafficDetails.percent + '%;"></div>' +
                                    '</div>' +
                                    '<div class="progress-label">' + item.trafficDetails.usageString + '</div>' +
                                '</div>';

                            return result;
                        }
                    }, {
                        header: '',
                        sortable: false,
                        cls: 'min',
                        renderer: function(item) {
                            return '<span class="tooltipData">' + <?php echo $this->jsLmsg('buttonOverviewHint');?> + '</span>' +
                                '<a href="' + Jsw.prepareUrl('/smb/web/overview/id/' + item.id + '/type/domain') +'" class="s-btn sb-customize"><span></span></a>';
                        }
                    }
                ]
            })
        ]
    });
});
//]]>
</script>
