<?php
/**
 * @version 7.6
 */
echo $this->script()->displayHeaderCode(); ?>

<?php foreach ((array)$this->messages as $message) { ?>
    <div class="alert alert-dismissable <?php echo $message['class']; ?>">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        <?php if (is_array($message['msg'])) { ?>
            <?php foreach ((array)$message['msg'] as $msg) { ?>
                <div><?php echo $this->_($msg); ?></div>
            <?php } ?>
        <?php
        } else {
            ?>
            <?php echo $this->_($message['msg']); ?>
        <?php } ?>
    </div>
<?php } ?>

<form data-async method="<?php echo $this->form->getMethod(); ?>" action="<?php echo $this->form->getAction(); ?>"
      class="form-horizontal">
    <?php echo $this->form->hiddenElements; ?>
    <?php foreach ($this->form->getElements() as $element) { ?>
        <?php if (!$element->isHidden()) { ?>
            <?php echo $this->partial('partials/form-element.phtml', array('element' => $element)); ?>
        <?php } ?>
    <?php } ?>
</form>

<!-- included jquery because this is a bootbox popup -->
<script src="<?php echo $this->baseUrl; ?>/js/jquery.min.js"></script>
<script src="<?php echo $this->baseUrl; ?>/js/bootstrap.min.js"></script>
<?php echo $this->script()->displayBodyCode(); ?>
<script type="text/javascript">
    $(document).ready(function () {
        // submit modal forms in the modal box, and replace the current html with the response html
        $('form[data-async]').find('[type=submit]').on('click', function (e) {
            e.preventDefault();

            $(this).attr('disabled', true).val('Please wait..');

            var form = $(this).closest('form');
            var target = form.attr('data-target');

            $.ajax({
                type: form.attr('method'),
                url: form.attr('action'),
                data: form.serialize(),

                success: function (data) {
                    $('.bootbox-body').html(data);
                }
            });
        });
    });
</script>
