<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
?>

<script type="text/javascript">
//<![CDATA[
    new Jsw.Panel({
        cls: 'list-box',
        renderTo: 'main',
        items: [
            new Jsw.List({
                id: 'admin-event-handlers-list',
                data: <?php echo Zend_Json::encode($this->handlersList->fetchData()); ?>,
                dataUrl: '/event-handlers/list-data',
                searchFilters: <?php echo Zend_Json::encode($this->handlersList->getSearchFilterConfig()); ?>,
                searchOveral: 'name',
                operations: [
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddEventHandler',
                        title: <?php echo $this->handlersList->jsLmsg('buttonAddNewEventHandler');?>,
                        description: <?php echo $this->handlersList->jsLmsg('buttonAddNewEventHandlerDescription'); ?>,
                        addCls: 'sb-add-new btn-primary',
                        href: '/event-handlers/add'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemovePlan',
                        title: <?php echo $this->handlersList->jsLmsg('buttonRemove');?>,
                        description: <?php echo $this->handlersList->jsLmsg('buttonRemoveDescription'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('admin-event-handlers-list').execGroupOperation({
                                url: '/event-handlers/delete/',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->handlersList->jsLmsg('confirmOnDelete'); ?>
                                }
                            });
                        }
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->handlersList->jsLmsg('event');?>,
                        sortable: true,
                        dataIndex: 'name',
                        renderer: function (item) {
                            return (
                                '<a href="<?php echo $this->baseUrl('/event-handlers/edit/id/') ?>' + item.id + '">' +
                                    Jsw.escapeHtml(item.name) +
                                '</a>'
                            );
                        }
                    }, {
                        header: <?php echo $this->handlersList->jsLmsg('priority');?>,
                        sortable: true,
                        dataIndex: 'priority',
                        renderer: function (item) {
                            var priorityDescriptions = {
                                '100': <?php echo $this->handlersList->jsLmsg('priorityHighest', ['value' => 100]) ?>,
                                '75': <?php echo $this->handlersList->jsLmsg('priorityHigh', ['value' => 75]) ?>,
                                '50': <?php echo $this->handlersList->jsLmsg('priorityNormal', ['value' => 50]) ?>,
                                '25': <?php echo $this->handlersList->jsLmsg('priorityLow', ['value' => 25]) ?>,
                                '0': <?php echo $this->handlersList->jsLmsg('priorityLowest', ['value' => 0]) ?>
                            };

                            var priority = item['priority'];
                            if (priorityDescriptions.hasOwnProperty(priority)) {
                                priority = priorityDescriptions[priority];
                            }

                            return priority;
                        }
                    }, {
                        header: <?php echo $this->handlersList->jsLmsg('user');?>,
                        sortable: true,
                        dataIndex: 'user'
                    }, {
                        header: <?php echo $this->handlersList->jsLmsg('command');?>,
                        sortable: true,
                        dataIndex: 'command'
                    }
                ]
            })
        ]
    });
//]]>
</script>
