<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<script type="text/javascript">
//<![CDATA[

Jsw.namespace('Smb.Views.Web');

Smb.Views.Web.deleteMobileSiteConfirmation = function(deleteUrl) {
    Jsw.messageBox.show({
        'type': Jsw.messageBox.TYPE_YESNO,
        'subtype': 'delete',
        'text': <?php echo $this->mobileSitesList->jsLmsg('confirmDeleteTitle') ?>,
        'description': <?php echo $this->mobileSitesList->jsLmsg('confirmDeleteDescription') ?>,
        'onYesClick': function() { Jsw.redirectPost(deleteUrl); },
        'buttonTitles': {
            'yes': <?php echo $this->jsLmsg('components.buttons.yes') ?>,
            'no': <?php echo $this->jsLmsg('components.buttons.no') ?>
        }
    });
};

Jsw.onReady(function() {

    new Jsw.Hint({
        renderTo: 'main',
        hint: <?php echo $this->jsLmsg('areaDescription'); ?>
    });

    new Jsw.List({
        renderTo: 'main',
        id: 'sites-list',
        data: <?php echo Zend_Json::encode($this->mobileSitesList->fetchData()); ?>,
        dataUrl: '/smb/web/mobile-sites-list-data',
        columns: [{
            header: <?php echo $this->mobileSitesList->jsLmsg('website'); ?>,
            sortable: true,
            dataIndex: 'displayName'
        }, {
            header: <?php echo $this->mobileSitesList->jsLmsg('mobileSite'); ?>,
            sortable: true,
            dataIndex: 'mobileSiteName',
            renderer: function (item) {
                return item.mobileSiteName != '' ? Jsw.escapeHtml(item.mobileSiteName) : '-';
            },
        }, {
            header: '',
            cls: 'nowrap action-btns-set',
            renderer: function (item) {
                var actions = [];

                if (item.mobileSiteName != '') {
                    actions.push(
                        '<a class="s-btn" href="' + Jsw.prepareUrl(item.launchUrl) + '" target="_blank">' +
                            '<i class="icon-manage"></i> ' +
                            <?php echo $this->mobileSitesList->jsLmsg('launchEditor'); ?> +
                        '</a>'
                    );

                    actions.push(
                        '<a class="s-btn" href="javascript:Smb.Views.Web.deleteMobileSiteConfirmation(\'' + item.deleteUrl + '\');">' +
                            '<i class="icon-delete"></i> ' +
                            <?php echo $this->mobileSitesList->jsLmsg('delete'); ?> +
                        '</a>'
                    );
                <?php if ($this->allowCreateMobileSite): ?>
                } else {
                    actions.push(
                        '<a class="s-btn" href="' + Jsw.prepareUrl(item.createUrl) + '">' +
                         '<i class="icon-mobile"></i> ' +
                            <?php echo $this->mobileSitesList->jsLmsg('createSite'); ?> +
                        '</a>'
                    );
                <?php endif; ?>
                }

                return actions.join(' ');
            }
        }]
    });

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