<?php
// Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<script type="text/javascript">
    //<![CDATA[
    Jsw.onReady(function () {
        var publicStatesInfo = {
            enabled: {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_PUBLIC); ?>',
                alt: <?php echo $this->customButtonsList->jsLmsg('altPublicEnabledIcon'); ?>,
                description: <?php echo $this->customButtonsList->jsLmsg('publicEnabledDescription'); ?>
            },
            disabled: {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_PUBLIC_DISABLED); ?>',
                alt: <?php echo $this->customButtonsList->jsLmsg('altPublicDisabledIcon'); ?>,
                description: <?php echo $this->customButtonsList->jsLmsg('publicDisabledDescription'); ?>
            }
        };

        var placeIcons = {
            'admin': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_ADMIN); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeAdminDescription'); ?>
            },
            'admin-settings': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_ADMIN_SETTINGS); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeAdminSettingsDescription'); ?>
            },
            'client': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_CLIENT); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeClientDescription'); ?>
            },
            'domain': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_DOMAIN); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeDomainDescription'); ?>
            },
            'domain-properties': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_DOMAIN_PROPERTIES); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeDomainPropertiesDescription'); ?>
            },
            'navigation': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_NAVIGATION); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeNavigationDescription'); ?>
            },
            'reseller': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_RESELLER); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeResellerDescription'); ?>
            },
            'reseller-settings': {
                icon: '<?php echo $this->skinUrl('icons/16/plesk/' . Skin::ICON_CUSTOM_BUTTON_PLACE_RESELLER_SETTINGS); ?>',
                description: <?php echo $this->customButtonsList->jsLmsg('placeResellerSettingsDescription'); ?>
            }
        };

        new Jsw.Panel({
            cls: 'list-box',
            renderTo: 'main',
            items: [
                new Jsw.List({
                    id: 'custom-buttons-list',
                    data: <?php echo Zend_Json::encode($this->customButtonsList->fetchData()); ?>,
                    dataUrl: '/custom-buttons/list-data',
                    searchFilters: <?php echo Zend_Json::encode($this->customButtonsList->getSearchFilterConfig()); ?>,
                    operations: [
                        {
                            componentType: 'Jsw.SmallButton',
                            id: 'buttonAdd',
                            title: <?php echo $this->customButtonsList->jsLmsg('buttonAdd'); ?>,
                            description: <?php echo $this->customButtonsList->jsLmsg('buttonAddDescription'); ?>,
                            addCls: 'sb-add-new',
                            href: '<?php echo $this->url(['controller' => 'custom-buttons', 'action' => 'create'], null, true); ?>'
                        },
                        {
                            componentType: 'Jsw.bar.Separator'
                        },
                        {
                            componentType: 'Jsw.SmallButton',
                            id: 'buttonRemove',
                            title: <?php echo $this->customButtonsList->jsLmsg('buttonRemove'); ?>,
                            description: <?php echo $this->customButtonsList->jsLmsg('buttonRemoveDescription'); ?>,
                            addCls: 'sb-remove-selected',
                            handler: function (event) {
                                Jsw.getComponent('custom-buttons-list').execGroupOperation({
                                    url: '<?php echo $this->url(['controller' => 'custom-buttons', 'action' => 'remove'], null, true); ?>',
                                    subtype: 'delete',
                                    mouseEvent: event,
                                    locale: {
                                        confirmOnGroupOperation: <?php echo $this->customButtonsList->jsLmsg('removeConfirmMessage'); ?>
                                    }
                                });
                            }
                        }
                    ],
                    columns: [
                        Jsw.list.COLUMN_SELECTION,
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerPublic'); ?>,
                            sortable: true,
                            headerCls: 'icon',
                            cls: 'icon',
                            dataIndex: 'publicState',
                            renderer: function (item) {
                                var publicStateInfo = publicStatesInfo[item.publicState];
                                return '<span class="tooltipData">' + publicStateInfo.description + '</span>' +
                                    '<a data-method="post" href="'
                                    + '<?php echo $this->url(['controller' => 'custom-buttons', 'action' => 'toggle']); ?>'
                                    + '/id/' + item.id + '"><img src="' + publicStateInfo.icon + '" alt="'
                                    + publicStateInfo.alt + '" /></a>';
                            }
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerLocation'); ?>,
                            sortable: true,
                            headerCls: 'icon',
                            cls: 'icon',
                            dataIndex: 'place',
                            renderer: function (item) {
                                return '<i class="icon"><img src="' + placeIcons[item.place].icon + '" /></i>' +
                                    '<span class="tooltipData">' + placeIcons[item.place].description + '</span>';
                            }
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerImage'); ?>,
                            sortable: true,
                            headerCls: 'icon',
                            cls: 'icon',
                            dataIndex: 'file',
                            renderer: function (item) {
                                return '<i class="icon"><img src="' + ((item.file)
                                            ? '/images/custom_buttons/' + item.file
                                            : '<?php echo $this->skinUrl('icons/16/plesk/custom-button.png'); ?>'
                                    ) + '" /></i>';
                            }
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerPriority'); ?>,
                            sortable: true,
                            headerCls: 'number',
                            cls: 'number',
                            dataIndex: 'sort_key'
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerLabel'); ?>,
                            sortable: true,
                            dataIndex: 'text',
                            cls: 'nowrap',
                            renderer: function (item) {
                                return '<a href="' +
                                    '<?php echo $this->url(['controller' => 'custom-buttons','action' => 'edit']); ?>'
                                    + '/id/' + item.id + '">' + item.text.escapeHTML() + '</a>';
                            }
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerUrl'); ?>,
                            sortable: true,
                            dataIndex: 'fullUrl'
                        },
                        {
                            header: <?php echo $this->customButtonsList->jsLmsg('headerDescription'); ?>,
                            sortable: true,
                            dataIndex: 'conhelp'
                        }
                    ]
                })
            ]
        });
    });
    //]]>
</script>
