<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2022 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<script type="text/javascript">
//<![CDATA[
    /**
     * Post form data and process response via AJAX.
     *
     * @return void
     */
    varienForm.prototype.getFilter = function()
    {
        if ($('entity') && $F('entity')) {
            var url = "<?= $this->getUrl('*/*/getFilter') ?>";
            url += ((url.slice(-1) != '/') ? '/' : '') + 'entity/' + $F('entity');

            new Ajax.Request(url, {
                method:      'post',
                //parameters:  $(this.formId).serialize(),
                evalScripts: true,
                onComplete:  function(transport) {
                    var responseText = transport.responseText.replace(/>\s+</g, '><');
                    $('export_filter_grid_container').update(responseText);
                    $('export_filter_container').show();
                }
            });
        } else {
            $('export_filter_container').hide();
        }
    };

    /**
     * Continue export process after filter settings.
     *
     * return void
     */
    function getFile()
    {
        if ($('entity') && $('file_format')) {
            var form      = $('export_filter_form');
            var oldAction = form.action;
            form.action   = oldAction + ((oldAction.slice(-1) != '/') ? '/' : '') + 'entity/' + $F('entity') + '/file_format/' + $F('file_format');
            form.submit();
            form.action   = oldAction;
        } else {
            alert('<?= Mage::helper('core')->jsQuoteEscape($this->__('Invalid data')) ?>');
        }
    }
//]]>
</script>
