<!-- this is an HTML file rather than JavaScript static file because context variables need to be passed to it -->
{% if view.poll_interval_seconds %}
    <script type="text/javascript">
        var checkIfReady = function() {
            var args = { 
                type: "GET",
                cache: false,
                url: "{{ view.poll_url }}",
                complete: redirectToSequenceView,
            }
            $.ajax(args);
        }

        var redirectToSequenceView = function(res, status) {

            if (status == "success") {
                var response = res.responseText;
                if (response == "1") {
                    window.location.href = '{{ view.redirect_url }}';
                }

            } else{
                $(".error-notice").show();
            }
        }

        var SECOND = 1000;
        var intervalId = window.setInterval(checkIfReady, {{ view.poll_interval_seconds }} * SECOND);
        // after 60 minutes, stop polling
        setTimeout(function( ) { clearInterval( intervalId ); }, 60 * 60 * SECOND   );
    </script>
{% endif %}
