<?php
// Copyright 1999-2015. 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'); ?>,
            expandable: true
        });

        new Jsw.List({
            id: 'auto-update-settings-list',
            renderTo: 'main',
            data: <?php echo Zend_Json::encode($this->settingList->fetchData()); ?>,
            dataUrl: '/wordpress/auto-update-settings-data',
            searchFilters: <?php echo Zend_Json::encode($this->settingList->getSearchFilterConfig()); ?>,
            columns: [
                Jsw.list.COLUMN_SELECTION,
                {
                    header: <?php echo $this->settingList->jsLmsg('name');?>,
                    sortable: true,
                    dataIndex: 'name',
                    renderer: function(item) {
                        return '<div class=""><a href="' + Jsw.baseUrl + '/wordpress/detail/id/' + item.id + '">' + item.name.escapeHTML() + '</a></div>';
                    }
                }, {
                    header: <?php echo $this->settingList->jsLmsg('url');?>,
                    dataIndex: 'url',
                    renderer: function(item) {
                        return item.url ?
                            new Element('a', { href: item.url, target: '_blank' }).update(item.url.escapeHTML()).outerHTML :
                            '';
                    }
                }, {
                    header: <?php echo $this->settingList->jsLmsg('version');?>,
                    renderer: function(item) {
                        return item.version.escapeHTML();
                    }
                }, {
                    header: <?php echo $this->settingList->jsLmsg('autoUpdates');?>,
                    renderer: function(item) {
                        var status = 'on';
                        var statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/on.png') ?>';
                        var statusMsg = <?php echo $this->settingList->jsLmsg('autoUpdatesOn');?>;
                        var statusDescription = <?php echo $this->settingList->jsLmsg('autoUpdatesOnDesc');?>;
                        if (!item.autoUpdates) {
                            status = 'off';
                            statusIcon = '<?php echo $this->skinUrl('/icons/16/plesk/off.png') ?>';
                            statusMsg = <?php echo $this->settingList->jsLmsg('autoUpdatesOff');?>;
                            statusDescription = <?php echo $this->settingList->jsLmsg('autoUpdatesOffDesc');?>;
                        }

                        var link = '<div class="b-indent">'
                            + '<span class="b-indent-icon">'
                            + '<span class="tooltipData">' + statusDescription.escapeHTML() + '</span>'
                            + '<img src="' + statusIcon + '" alt="' + status + '" title="">'
                            + '</span> '
                            + '<nobr>' + statusMsg.escapeHTML() + '</nobr>'
                            + '</div>';

                        return link;
                    }
                }
            ],
            operations: [
                {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonEnable',
                    title: <?php echo $this->settingList->jsLmsg('buttonEnable') ?>,
                    description: <?php echo $this->settingList->jsLmsg('hintButtonEnable') ?>,
                    addCls: 'sb-activate',
                    handler: function(event) {
                        Jsw.getComponent('auto-update-settings-list').execGroupOperation({
                            url: Jsw.baseUrl + '/wordpress/enable-auto-updates/',
                            skipConfirmation: true
                        });
                    }
                }, {
                    componentType: 'Jsw.SmallButton',
                    id: 'buttonDisable',
                    title: <?php echo $this->settingList->jsLmsg('buttonDisable') ?>,
                    description: <?php echo $this->settingList->jsLmsg('hintButtonDisable') ?>,
                    addCls: 'sb-disable',
                    handler: function(event) {
                        Jsw.getComponent('auto-update-settings-list').execGroupOperation({
                            url: Jsw.baseUrl + '/wordpress/disable-auto-updates/',
                            skipConfirmation: true
                        });
                    }
                }
            ]
        });
    });
    //]]>
</script>
