<?php
// Copyright 1999-2012. Parallels IP Holdings 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: 'admin-plan-item-list',
                data: <?php echo Zend_Json::encode($this->planItemsList->fetchData()); ?>,
                dataUrl: '/plan-item/list-data',
                searchFilters: <?php echo Zend_Json::encode($this->planItemsList->getSearchFilterConfig()); ?>,
                operations: [
                    {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonAddCustomItem',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonAddNewCustomItemButton');?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonAddNewCustomItemButtonDescription'); ?>,
                        addCls: 'sb-add-new',
                        href: '/plan-item/create'
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonMakeVisible',
                        attrs: { 'data-method': 'post' },
                        title: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemVisible'); ?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemVisibleDescription'); ?>,
                        addCls: 'sb-make-visible',
                        handler: function() {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/make-visible',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonMakeInvisible',
                        attrs: { 'data-method': 'post' },
                        title: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemInvisible'); ?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonMakeItemInvisibleDescription'); ?>,
                        addCls: 'sb-make-invisible',
                        handler: function() {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/make-invisible',
                                skipConfirmation: true
                            });
                        }
                    }, {
                        componentType: 'Jsw.bar.Separator'
                    }, {
                        componentType: 'Jsw.SmallButton',
                        id: 'buttonRemoveCustomItem',
                        title: <?php echo $this->planItemsList->jsLmsg('buttonRemoveCustomItem');?>,
                        description: <?php echo $this->planItemsList->jsLmsg('buttonRemoveCustomItemDescription'); ?>,
                        addCls: 'sb-remove-selected',
                        handler: function(event) {
                            Jsw.getComponent('admin-plan-item-list').execGroupOperation({
                                url: '/plan-item/remove',
                                subtype: 'delete',
                                mouseEvent: event,
                                locale: {
                                    confirmOnGroupOperation: <?php echo $this->planItemsList->jsLmsg('confirmOnDeleteSupportButton'); ?>
                                }
                            });
                        }
                    }
                ],
                columns: [
                    Jsw.list.COLUMN_SELECTION,
                    {
                        header: <?php echo $this->planItemsList->jsLmsg('name');?>,
                        sortable: true,
                        dataIndex: 'description',
                        renderer: function(item, isDisabled) {

                            var status = (1 != item.visible)
                            ? ( '<span class="hint-attention ">' +
                                    <?php echo $this->planItemsList->jsLmsg('itemInvisible'); ?> +
                                '</span>')
                            : '';
                            var link = (item.editable
                                ? '<span class="b-indent-icon">' +
                                    (item.img
                                        ? '<span>' +
                                          '<img src="' + item.img + '?' + <?php echo $this->jsEscape(md5(time()));?>
                                          + '" alt="" title="" width="16" height="16">' +
                                          '</span>'
                                        : ''
                                         ) +
                                  '</span>' + ' ' +
                                  '<a href="' + Jsw.baseUrl + '/plan-item/edit/id/' + item.id + '">'
                                : '')
                                + item.description.escapeHTML()
                                + (item.editable ? '</a>' : '')
                                + status + '<br/>'
                                + '<span class="hint">' + item.hint.escapeHTML() + '</span>';

                            return link;
                        }
                    }, {
                        header: <?php echo $this->planItemsList->jsLmsg('numberOfSubscriptions');?>,
                        sortable: true,
                        dataIndex: 'numberOfSubscriptions',
                        renderer: function(item, isDisabled) {

                        	var link = '<a href="' + Jsw.baseUrl + '/subscription/list/?force-show-search=true&searchFilter[planItem][searchText]=' + item.id + '">'
                            + item.numberOfSubscriptions.escapeHTML() + '</a>';

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