<?php
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.
?>
<?php echo $this->form ?>
<?php echo $this->partial('database/_form/db-server.phtml', null, $this); ?>
<script type="text/javascript">
//<![CDATA[
Jsw.namespace('Smb.Views.Database');
Smb.Views.Database.dbUserPresubmitHandler = function(form) {
    if (
        document.getElementById('dbPrivileges-globalAccessStateChanged') &&
        'true' === document.getElementById('dbPrivileges-globalAccessStateChanged').value &&
        document.querySelectorAll('input[id^="dbPrivileges-globalAccess-"]:checked').length > 0
    ) {
        Jsw.messageBox.show({
            type: Jsw.messageBox.TYPE_YESNO,
            buttonTitles: {
                yes: <?php echo $this->jsLmsg('confirmationYes'); ?>,
                no: <?php echo $this->jsLmsg('confirmationNo'); ?>,
                wait: <?php echo $this->jsLmsg('confirmationWait'); ?>
            },
            text: <?php echo $this->jsLmsg('confirmText'); ?>,
            subtype: 'toggle',
            onYesClick: function () {
                document.getElementById('dbPrivileges-globalAccessStateChanged').value = 'false';
                Jsw.submit(document.getElementById(form._applyTargetId));
            }
        });
        return false;
    }
    return true;
};

Jsw.onReady(function () {
    document.querySelectorAll('input[id^="dbPrivileges-globalAccess-"]').forEach(function (checkbox) {
        checkbox.addEventListener('change', function () {
            document.getElementById('dbPrivileges-globalAccessStateChanged').value = 'true';
        });
    });

    if (document.getElementById('dbPrivileges')) {
        document.getElementById('dbPrivileges').classList.add('b-collapsible');
        new Jsw.Panel({
            title: <?php echo $this->jsLmsg('showPrivileges'); ?>,
            hideContentTitle: <?php echo $this->jsLmsg('hidePrivileges'); ?>,
            applyTo: 'dbPrivileges'
        });
    }
});
//]]>
</script>

