{% extends "template/template.html" %}
{% block content %}

<FORM ACTION="" METHOD="POST">
    <TABLE BORDER="0">
        <TR>
            <TH>Peering Point</TH>
            <TH>Query Type</TH>
            <TH>Query</TH>
            <TH></TH>
        </TR>
        <TR>
            <TD>{{form.peering_point}}</TD>
            <TD>{{form.query_type}}</TD>
            <TD>{{form.query}}</TD>
            <TD><INPUT TYPE="submit" VALUE="Query" /></TD>
        </TR>
        <TR>
            <TD>{{form.peering_point.errors}}</TD>
            <TD>{{form.query_type.errors}}</TD>
            <TD>{{form.query.errors}}</TD>
        </TR>
    </TABLE>
</FORM>

{% if task_id %}
<PRE>
<CODE id="out">
</CODE>
</PRE>

<script type="text/javascript" src="/static/js/dojo/dojo.js" ></script>
    
<script type="text/javascript">
    var process_data = function(data) {
        node=dojo.byId("out");
        if(data.status=="n") {
            node.innerHTML="Running...";
            window.setTimeout("get_result()",3000);
        }
        if(data.status=="p") {
            node.innerHTML="Processing..."+data.out;
            window.setTimeout("get_result()",3000);
        }
        if(data.status=="f") {
            node.innerHTML="Failed..."+data.out;
        }
        if(data.status=="c") {
            node.innerHTML=data.out;
        }
    }
    
    var error_report = function(error,args) {
        node=dojo.byId("out");
        node.innerHTML="ERROR:\n";
    }
    
    var get_result = function() {
        dojo.xhrGet({
            url: "{{task_id}}/",
            handleAs: "json",
            load: process_data,
            error: error_report,
        }
        );
    }
    dojo.addOnLoad(get_result);
</script>
{% endif %}
{%endblock%}