<?php
// Copyright 1999-2022. Plesk International GmbH. All rights reserved.
?>
<table cellspacing="0" width="100%" class="form-table form-limits"><tbody>
    <tr id="<?php echo $this->elementId; ?>-row" class="form-row">
        <td class="field-name">
            <label for="<?php echo $this->elementId; ?>-value">
                <?php echo $this->elementPart($this->element->getElement('hardDiskQuotaValue'))->label(); ?>
            </label>
        </td>
        <td class="field-value">
            <div class="nowrap">
                <?php echo $this->elementPart($this->element->getElement('hardDiskQuotaValue'))->content(); ?>
                <?php echo $this->lmsg('smb.components.forms.web-user.megabytes'); ?>
            </div>
            <?php echo $this->element->getElement('hardDiskQuota'); ?>
            <span class="field-errors" style="display: none;"></span>
        </td>
        <td class="nowrap">
            <?php echo $this->elementPart($this->element->getElement('hardDiskQuotaUnlimited'))->content(); ?>
            <?php echo $this->elementPart($this->element->getElement('hardDiskQuotaUnlimited'))->label() . $this->explanation; ?>
        </td>
    </tr>
</tbody></table>

<script type="text/javascript">
    //<![CDATA[
    Jsw.onReady(function () {
        var updateElementValueFunction = function (event) {
            var elementId = <?php echo $this->jsEscape($this->elementId); ?>;
            if (document.getElementById(elementId + '-unlimited') && document.getElementById(elementId + '-unlimited').checked) {
                document.getElementById(elementId + '-value').disabled = true;
                document.getElementById(elementId).value = -1;
            } else {
                document.getElementById(elementId + '-value').disabled = false;
                if (event && event.target.id === elementId + '-unlimited') {
                    try {
                        document.getElementById(elementId + '-value').focus();
                    } catch (e) {}
                }
                var value = document.getElementById(elementId + '-value').value;
                if (!/^\d+$/.test(value)) {
                    document.getElementById(elementId).value = value;
                } else {
                    document.getElementById(elementId).value = value;
                }
            }
        }

        document.getElementById('<?php echo $this->elementId; ?>-value').addEventListener('change', updateElementValueFunction);
        if (document.getElementById('<?php echo $this->elementId; ?>-unlimited')) {
            document.getElementById('<?php echo $this->elementId; ?>-unlimited').addEventListener('click', updateElementValueFunction);
        }
        updateElementValueFunction();
    });
    //]]>
</script>
