{% extends "sessao/sessaoplenaria_detail.html" %}
{% load i18n %}
{% load staticfiles %}

{% block detail_content %}
	<audio type="hidden" id="audio" src="{% static 'audio/ring.mp3' %}"> </audio>

  <div class="row">
    <!--<div class="col-md-6"><a href="{% url 'painel_principal' object.pk %}" class="btn btn-primary btn-sm active">Iniciar painel presidente</a></div> -->
    <div class="col-md-6"><a href="{% url 'painel_principal' object.pk %}" class="btn btn-primary btn-sm active">Iniciar painel completo</a></div>
    <!--<div class="col-md-6"><a href="{% url 'painel_mensagem' %}" class="btn btn-primary btn-sm active">Iniciar painel mensagem</a></div>
    <div class="col-md-6"><a href="{% url 'painel_parlamentares' %}" class="btn btn-primary btn-sm active">Iniciar painel parlamentares</a></div>
    <div class="col-md-6"><a href="{% url 'painel_votacao' %}" class="btn btn-primary btn-sm active">Iniciar painel votação</a></div> -->
    <div class="col-md-6"><a href="{% url 'painel_controlador' %}" class="btn btn-primary btn-sm active">Controlador Painel</a></div>
  </div>
	<br />
	<h1>Operação do Painel Eletrônico</h1>
	<h2><span id="relogio"></span></h2>
	<br />
  <div class="row">
    <div class="col-md-12"><h3>Cronômetro do Discurso</h3></div>
  </div>

  <div class="row">
    <div class="col-xs-2"><input size="2" id="discurso" name="discurso" value="" readyonly="true" class="form-control"></div>
  </div>
	<br />

  <div class="row">
    <div class="col-md-6"><button type="button" id="discursoStart" class="btn btn-success">Iniciar</button></div>
    <div class="col-md-6"><button type="button" id="discursoReset" class="btn btn-success">Reiniciar</button></div>
  </div>

	<br /><br >
  <div class="row">
    <div class="col-md-12"><h3>Cronômetro do Aparte</h3></div>
  </div>

  <div class="row">
    <div class="col-xs-2"><input size="2" id="aparte" name="aparte" value="" readyonly="true" class="form-control"></div>
  </div>
	<br />

  <div class="row">
    <div class="col-md-6"><button type="button" id="aparteStart" class="btn btn-success">Iniciar</button></div>
    <div class="col-md-6"><button type="button" id="aparteReset" class="btn btn-success" class="btn btn-success">Reiniciar</button></div>
  </div>

	<br /><br >
  <div class="row">
    <div class="col-md-12"><h3>Cronômetro da Questão de Ordem </h3></div>
  </div>

  <div class="row">
    <div class="col-xs-2"><input size="2" id="ordem" name="ordem" value="" readyonly="true" class="form-control"></div>
  </div>
	<br />

  <div class="row">
    <div class="col-md-6"><button type="button" id="ordemStart" class="btn btn-success">Iniciar</button></div>
    <div class="col-md-6"><button type="button" id="ordemReset" class="btn btn-success">Reiniciar</button></div>
  </div>

{% endblock detail_content %}

{% block extra_js %}
<script language="JavaScript">
$(function() {

	function checkTime(i) {
		if (i<10) {i = "0" + i};
			return i;
	}

	function startTime() {
		var today=new Date();
	 	var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		m = checkTime(m);
		s = checkTime(s);
		$("#relogio").text(h+":"+m+":"+s)
		var t = setTimeout(function(){
		    startTime()
		},500);
	}

	startTime();

	var audioAlertFinish = document.getElementById("audio");

	$('#discurso').prop('disabled', true);
	$('#aparte').prop('disabled', true);
	$('#ordem').prop('disabled', true);

    $('#discurso').runner({
        autostart: false,
        countdown: true,
        startAt: 60 * 5 * 1000,
        stopAt: 0,
        milliseconds: false
	}).on('runnerFinish', function(eventObject, info){
		audioAlertFinish.play();
	});

    $('#discursoStart').click(function() {

		if ($('#discursoStart').text() == 'Iniciar'){

			$.get('/painel/cronometro', { tipo: 'discurso', action: 'start' } );

			$('#discursoReset').hide();
			$('#discurso').runner('start');
			$('#discursoStart').text('Parar');
			$('#aparteStart').prop('disabled', true);
			$('#aparteReset').prop('disabled', true);
			$('#ordemStart').prop('disabled', true);
			$('#ordemReset').prop('disabled', true);

		} else {

			$.get('/painel/cronometro', { tipo: 'discurso', action: 'stop' } );

			$('#discursoReset').show();
			$('#discurso').runner('stop');
			$('#discursoStart').text('Iniciar');
			$('#aparteStart').prop('disabled', false);
			$('#aparteReset').prop('disabled', false);
			$('#ordemStart').prop('disabled', false);
			$('#ordemReset').prop('disabled', false);
		}
    });

    $('#discursoReset').click(function() {

		$.get('/painel/cronometro', { tipo: 'discurso', action: 'reset' } );

        $('#discurso').runner('stop');
        $('#discurso').runner('reset');
    });

    $('#aparte').runner({
        autostart: false,
        countdown: true,
        startAt: 60 * 3 * 1000,
        stopAt: 0,
        milliseconds: false
	}).on('runnerFinish', function(eventObject, info){
		audioAlertFinish.play();
	});

	$('#aparteStart').click(function(){
		if ($('#aparteStart').text() == 'Iniciar') {

			$.get('/painel/cronometro', { tipo: 'aparte', action: 'start' } );

			$('#aparteReset').hide();
	        $('#aparte').runner('start');
			$('#aparteStart').text('Parar');
			$('#discursoStart').prop('disabled', true);
			$('#discursoReset').prop('disabled', true);
			$('#ordemStart').prop('disabled', true);
			$('#ordemReset').prop('disabled', true);

		} else {

			$.get('/painel/cronometro', { tipo: 'aparte', action: 'stop' } );

			$('#aparteReset').show();
			$('#aparte').runner('stop');
			$('#aparteStart').text('Iniciar');
			$('#discursoStart').prop('disabled', false);
			$('#discursoReset').prop('disabled', false);
			$('#ordemStart').prop('disabled', false);
			$('#ordemReset').prop('disabled', false);
		}
    });

    $('#aparteReset').click(function() {

		$.get('/painel/cronometro', { tipo: 'aparte', action: 'reset' } );

        $('#aparte').runner('stop');
        $('#aparte').runner('reset');
    });

    $('#ordem').runner({
        autostart: false,
        countdown: true,
        startAt: 60 * 2 * 1000,
        stopAt: 0,
        milliseconds: false
	}).on('runnerFinish', function(eventObject, info){
		audioAlertFinish.play();
	});

    $('#ordemStart').click(function() {
		if ($('#ordemStart').text() == 'Iniciar') {

			$.get('/painel/cronometro', { tipo: 'ordem', action: 'start' } );

			$('#ordemReset').hide();
	        $('#ordem').runner('start');
			$('#ordemStart').text('Parar');
			$('#discursoStart').prop('disabled', true);
			$('#discursoReset').prop('disabled', true);
			$('#aparteStart').prop('disabled', true);
			$('#aparteReset').prop('disabled', true);

		} else {

			$.get('/painel/cronometro', { tipo: 'ordem', action: 'stop' } );

			$('#ordemReset').show();
	        $('#ordem').runner('stop');
			$('#ordemStart').text('Iniciar');
			$('#discursoStart').prop('disabled', false);
			$('#discursoReset').prop('disabled', false);
			$('#aparteStart').prop('disabled', false);
			$('#aparteReset').prop('disabled', false);
		}
    });

    $('#ordemReset').click(function() {

		$.get('/painel/cronometro', { tipo: 'ordem', action: 'reset' } );

        $('#ordem').runner('stop');
        $('#ordem').runner('reset');
    });

});
</script>

{% endblock %}