<?php
// Copyright 1999-2017. Parallels IP Holdings GmbH. All Rights Reserved.
?>
<script type="text/javascript">
//<![CDATA[

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

Smb.Views.Web.showHostingWarning = function(form) {
    if ($('hostingSettings-root') && ($('hosting').value == 'forwarding' || $('hosting').value == 'none')) {
        Jsw.messageBox.show({
            type: Jsw.messageBox.TYPE_YESNO,
            subtype: 'delete',
            isWebspace: <?php if ($this->isWebspace): ?>true<?php else: ?>false<?php endif ?>,
            text: <?php echo $this->jsEscape($this->form->lmsg('removeWebsiteHostingTitle')) ?>,
            description: <?php echo $this->jsEscape($this->form->lmsg('removeWebsiteHostingDescription')) ?>,
            successDescription: <?php echo $this->jsEscape($this->form->lmsg('removeWebsiteHostingDescriptionFolders')) ?>,
            failureDescription: <?php echo $this->jsEscape($this->form->lmsg('removeWebsiteHostingDescriptionAllFolders')) ?>,
            requestUrl: '/file-manager/list-data?currentDir=/',
            onYesClick: function() {
                Smb.Views.Web.showHostingWarning = function() {
                    return true;
                };
                Jsw.submit(form);
            },
            buttonTitles: {
                wait: <?php echo $this->jsLmsg('components.buttons.wait') ?>,
                yes: <?php echo $this->jsLmsg('components.buttons.yes') ?>,
                no: <?php echo $this->jsLmsg('components.buttons.no') ?>
            }
        });

        return false;
    }
    return true;
};

Jsw.onReady(function() {

    new Jsw.Panel({
        cls: 'tools-box',
        renderTo: 'main',
        renderMode: 'top',
        items: [{
            componentType: 'Jsw.Hint',
            hint: '<?php echo Plesk_Base_Utils_String::safeForJs($this->form->lmsg('formGeneralHint')); ?>'
        }]
    });

    // show/hide primitives
    function hideHosting() {
        $w('ipSelector-ipv4 ipSelector-ipv6 root userName password passwordConfirmation').each(function(elementSuffix) {
            if ($('hostingSettings-' + elementSuffix)) {
                $('hostingSettings-' + elementSuffix).disable();
            }
        });
        $('hostingSettings').hide();
    }
    function showHosting() {
        $w('ipSelector-ipv4 ipSelector-ipv6 root userName password passwordConfirmation').each(function(elementSuffix) {
            if ($('hostingSettings-' + elementSuffix)) {
                $('hostingSettings-' + elementSuffix).enable();
            }
        });
        $('hostingSettings').show();
    }
    function hideForwarding() {
        $w('ipSelector-ipv4 ipSelector-ipv6 forwardTo').each(function(elementSuffix) {
            if ($('forwardingSettings-' + elementSuffix)) {
                $('forwardingSettings-' + elementSuffix).disable();
            }
        });
        $('forwardingSettings').hide();
    }
    function showForwarding() {
        $w('ipSelector-ipv4 ipSelector-ipv6 forwardTo').each(function(elementSuffix) {
            if ($('forwardingSettings-' + elementSuffix)) {
                $('forwardingSettings-' + elementSuffix).enable();
            }
        });
        $('forwardingSettings').show();
    }

    // handlers
    function hostingActive() {
        hideForwarding();
        showHosting();
    }
    function forwardingActive() {
        hideHosting();
        showForwarding();
    }
    function noneActive() {
        hideHosting();
        hideForwarding();
    }

    function onHostingTypeChange() {
        switch ($('hosting').getValue()) {
            case 'hosting':
                hostingActive();
                break;
            case 'forwarding':
                forwardingActive();
                break;
            case 'none':
                noneActive();
                break;
        }
    }

    $('hosting').observe('change', onHostingTypeChange);
    onHostingTypeChange();
});

//]]>
</script>

<?php echo $this->form; ?>
