<?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'); ?>,
        expandable: true
    });

    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'users-list',
                searchOveral: 'name',
                data: <?php echo Zend_Json::encode($this->usersList->fetchData()); ?>,
                dataUrl: '/user/list-data',
                disabledSelectHint: <?php echo $this->usersList->jsLmsg('disabledSelectHint');?>,
        		searchFilters: <?php echo Zend_Json::encode($this->usersList->getSearchFilterConfig()); ?>,
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->usersList->jsLmsg('contactName');?>,
                        sortable: true,
                        dataIndex: 'contactName',
                        renderer: function(item, isDisabled) {
                            var linkName = item.contactName ? item.contactName : item.login;
                            var link = '<a href="' + Jsw.prepareUrl('/user/overview/id/' + item.id) + '">'
                                + Jsw.escapeHtml(linkName) + '</a>';

                            var status = (1 == item.isLocked)
                                ? ( '<span class="hint-attention ">' +
                                        <?php echo $this->usersList->jsLmsg('statusBlocked'); ?> +
                                    '</span>')
                                : '';

                            return link + status;
                        }
                    }, {
                        header: <?php echo $this->usersList->jsLmsg('email');?>,
                        sortable: true,
                        cls: 'minor',
                        dataIndex: 'email',
                        renderer: function(item) {
                            return item.email
                                ? '<a href="mailto:' + item.email + '">' + item.email + '</a>'
                                : '';
                        }
                    }, {
                        header: <?php echo $this->usersList->jsLmsg('role');?>,
                        cls: 'minor',
                        sortable: true,
                        dataIndex: 'roleName'
                    }
                ],
                operations: [{
                        componentType: 'Jsw.SmallButton',
                        title: <?php echo $this->jsLmsg('buttonAddNewUser');?>,
                        description: <?php echo $this->jsLmsg('hintAddNewUser'); ?>,
                        addCls: 'sb-add-user',
                        href: '/user/create'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveUser',
                        title: <?php echo $this->usersList->jsLmsg('remove');?>,
                        description: <?php echo $this->usersList->jsLmsg('hintRemove'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('users-list').execGroupOperation({
                                url: '/user/delete/?redirect=/user/list/',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->usersList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    }
                ],
                isDisabledItem: function(item) {
                    return ((1 == item.isBuiltIn) || (item.id == <?php echo $this->currentUser->id; ?>));
                }
            })
        ]
    });
});
//]]>
</script>
