<!DOCTYPE html>
    <html lang="en">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <meta charset="utf-8">
    <title>Welcome to Official Counters</title>
    </head>
    <body id="body" style="background-color: #f3fafd;">
        <nav class="navbar navbar-default" style="background-color: #C9E9F6;">
            <div class="container-fluid">
              <!-- Brand and toggle get grouped for better mobile display -->
              <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                  <span class="sr-only">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">P. D. E. A.'s College Of Engineering Online Counter System</a>
              </div>
              <!-- Collect the nav links, forms, and other content for toggling -->
              <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                  <li class="active"><a href="/principal_request/" style="background-color: #87ceeb;">Principal's Request<span class="sr-only">(current)</span></a></li>

                  <li><a href="#">Notice board</a></li>
                  <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Forms available for now.<span class="caret"></span></a>
                    <ul class="dropdown-menu">
                      <li><a href="#">Admission form</a></li>
                      <li><a href="#">Scholarship form</a></li>
                      <li><a href="#">NSS form</a></li>
                      <li role="separator" class="divider"></li>
                      <li><a href="#">not included then click here...</a></li>
                    </ul>
                  </li>
                </ul>
                <div class="navbar-form navbar-right">
                  <div class="form-group">
                    <input type="text" class="form-control" placeholder="Token" id="token0">
                  </div>
                  <button type="submit" class="btn btn-default" onclick="check_status();">Check</button>
                </div>
                
              </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
          </nav>
         
          <ol class="breadcrumb" style="background-color: #87ceeb;">
            <li><h1 >Counters</h1></li>
          </ol>
          <div>
          <ul class="list-group">
            {% for counter in counters %}
            <li class="list-group-item"><button type="button" class="list-group-item" onclick="window.open('/counter/?counter={{ counter.counter.Counter }}&x=yes');">{{ counter.counter.Counter_Title }}<span class="badge">{{ counter.crowd }}</span></button></li>
            {% endfor %}
          <!--  <li class="list-group-item"><button type="button" class="list-group-item">Cras justo odio<span class="badge">9</span></button></li>
            <li class="list-group-item"><button type="button" class="list-group-item">Cras justo odio<span class="badge">9</span></button></li>-->
            </ul>
        </div>
            <nav class="navbar navbar-dark navbar-fixed-bottom bg-primary" style="background-color: #87ceeb;"><table><tr><td><button onclick="check_token();" class="btn btn-primary">Enter Token</button></td></tr></table></nav>
    <script>
     function AjaxCall(token,x=""){
      $.ajax({
        type:'GET',
            url: "{% url 'counter' %}",
            data: {
                'token': token,
                'x':x
              },
              success:function(data){
                
                if(data["Status"]=="Fail")
                {
                  alert("Token not present at all.");
                }
             
              else if (data["Status"]=="Success"){
              if(x==''){
               let opened = window.open("/counter/?counter="+data["counter"]+"&token="+data["token"]+"&x=no","_blank");
              }
              else{
                let atr=["token","subject","status","DOA"];
                c = "";
                for(i in atr){
                  c+=atr[i]+": "+data[atr[i]]+"  ";
                }
                alert(c);
              }
              }
            
           
              },
              error:function(){
                alert("Something went wrong.");
              }

      });
      }
     function check_token(){
      let token0 = prompt("Enter token number:","");
        if(token0!=null)
        { 
          
          AjaxCall(token0);
        //  decision="timer";
        }
     }
     function check_status(){
        let x = document.getElementById("token0").value;
        if(x!=""){
          AjaxCall(x,'check');
        }
        else{
          alert("Enter token number");
        }

     }
    </script>
          </body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
    </html>
<!-- SLIM JQuery gives prob -->