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

<script type="text/javascript">
//<![CDATA[
    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: 'roles-list',
                data: <?php echo Zend_Json::encode($this->rolesList->fetchData()); ?>,
                dataUrl: '/role/list-data',
                disabledSelectHint: <?php echo $this->rolesList->jsLmsg('disabledSelectHint');?>,
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->rolesList->jsLmsg('name'); ?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function(item) {
                            return '<a href="' + Jsw.prepareUrl('/role/edit/id/' + item.id) + '">' + Jsw.escapeHtml(item.name) + '</a>';
                        }
                    }, {
                        header: <?php echo $this->rolesList->jsLmsg('numberOfUsers'); ?>,
                        sortable: true,
                        cls: 'minor text-right',
                        headerCls: 't-r',
                        dataIndex: 'usersOnRole',
                        renderer: function(item) {
                            return '<a href="' + Jsw.prepareUrl('/user/list?force-show-search=true&searchFilter[role][searchText]='
                                + item.id) + '">' + item.usersOnRole + '</a>';
                        }
                    }
                ],
                operations: [{
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->jsLmsg('buttonAddNewRole'); ?>,
                    description: <?php echo $this->jsLmsg('hintAddNewRole'); ?>,
                    addCls: 'sb-add-role btn-primary',
                    href: '/role/create'
                }, {
                    componentType: 'Jsw.bar.Separator'
                }, {
                    componentType: 'Jsw.SmallButton',
                    title: <?php echo $this->rolesList->jsLmsg('remove'); ?>,
                    description: <?php echo $this->rolesList->jsLmsg('hintRemove'); ?>,
                    addCls: 'sb-remove-selected',
                    handler: function(event) {
                        Jsw.getComponent('roles-list').execGroupOperation({
                            url: '/role/delete',
                            subtype: 'delete',
                            mouseEvent: event,
                            locale: {
                                confirmOnGroupOperation: <?php echo $this->rolesList->jsLmsg('confirmOnDelete'); ?>
                            }
                        });
                    }
                }],
                isDisabledItem: function(item) {
                    return ((1 == item.isBuiltIn) || (item.usersOnRole > 0));
                }
            })
        ]
    });
//]]>
</script>
