<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<?php echo $this->partial('partials/tabs.phtml', array('tabs' => $this->tabs, 'renderTo' => 'main')); ?>

<script type="text/javascript">
//<![CDATA[
Jsw.onReady(function() {

    new Jsw.Hint({
        renderTo: 'main',
        hint: <?php echo $this->jsLmsg('hint'); ?>
    });

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'ftp-users-list',
                searchOveral: 'name',
                searchFilters: <?php echo Zend_Json::encode($this->usersList->getSearchFilterConfig()); ?>,
                data: <?php echo Zend_Json::encode($this->usersList->fetchData()); ?>,
                dataUrl: '/ftp/users-list-data',
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->jsLmsg('headerType'); ?>,
                        headerCls: 'icon',
                        sortable: true,
                        dataIndex: 'type',
                        cls: 'min',
                        renderer: function(item) {
                            var typeIcon = '';
                            switch (item.type) {
                                case '<?php echo Smb_View_List_FtpUsers::USER_TYPE_HOSTING ?>':
                                    typeIcon = '<?php echo $this->skinUrl('/icons/16/plesk/ftpsession-domain-user.png') ?>';
                                    break;
                                case '<?php echo Smb_View_List_FtpUsers::USER_TYPE_WEB ?>':
                                    typeIcon = '<?php echo $this->skinUrl('/icons/16/plesk/ftpsession-web-user.png') ?>';
                                    break;
                                case '<?php echo Smb_View_List_FtpUsers::USER_TYPE_FTP ?>':
                                    typeIcon = '<?php echo $this->skinUrl('/icons/16/plesk/ftpsession-sub-user.png') ?>';
                                    break;
                            }
                            return '<span class="b-indent-icon">' +
                                '<span class="tooltipData">' + Jsw.escapeHtml(item.typeTitle) + '</span>' +
                                '<img width="16" height="16" title="' + Jsw.escapeAttribute(item.typeTitle) + '" src="' + typeIcon + '"/>' +
                                '</span>';
                        }
                    }, {
                        header: <?php echo $this->jsLmsg('headerName'); ?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function (item) {
                            return '<a href="' + Jsw.prepareUrl(item.link) + '">'
                                + Jsw.escapeHtml(item.name) + '</a>';
                        }
                    }, {
                        header: <?php echo $this->jsLmsg('headerHome');?>,
                        sortable: true,
                        dataIndex: 'home',
                        renderer: function(item) {
                            var hint = '';
                            if (item.home_in_system_area) {
                                return '<b>' + Jsw.escapeHtml(item.home) + '</b>';
                            }
                            if (item.broken_dir) {
                                hint = ' <img src="<?php echo $this->skinUrl('/icons/16/plesk/att.png') ?>" alt=""> '
                                    + '(' + <?php echo $this->jsLmsg('brokenDir'); ?> + ')';
                            }
                            return Jsw.escapeHtml(item.home) + hint;
                        }
                    }
                ],
                operations: [
                <?php if ($this->allowCreateUser): ?>
                {
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->jsLmsg('buttonAddUser');?>,
                    description: <?php echo $this->jsLmsg('buttonAddUserHint'); ?> + <?php echo $this->jsEscape(' ' . $this->resourceUsage('max_subftp_users')); ?>,
                    addCls: 'sb-add-user btn-primary',
                    href: '/ftp/create-user'
                }, {
                    componentType: 'Jsw.bar.Separator'
                },
                <?php endif; ?>
                {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonRemoveUser',
                    title: <?php echo $this->jsLmsg('buttonRemoveUser');?>,
                    description: <?php echo $this->jsLmsg('buttonRemoveUserHint'); ?>,
                    addCls: 'sb-remove-selected',
                    handler: function(event) {
                        Jsw.getComponent('ftp-users-list').execGroupOperation({
                            url: '/ftp/delete-users',
                            subtype: 'delete',
                            mouseEvent: event,
                            locale: {
                                confirmOnGroupOperation: <?php echo $this->jsLmsg('confirmOnDelete'); ?>
                            }
                        });
                    }
                }],
                isDisabledItem: function(item) {
                    return '<?php echo Smb_View_List_FtpUsers::USER_TYPE_FTP ?>' != item.type;
                }
            })
        ]
    });

});
//]]>
</script>
