diff --git a/sapl/painel/urls.py b/sapl/painel/urls.py index 66ef92ac1..0a8888624 100644 --- a/sapl/painel/urls.py +++ b/sapl/painel/urls.py @@ -3,7 +3,7 @@ from django.conf.urls import url from .apps import AppConfig from .views import (cronometro_painel, get_dados_painel, painel_mensagem_view, painel_parlamentar_view, painel_view, painel_votacao_view, - votante_view) + switch_painel, votante_view) app_name = AppConfig.name @@ -14,6 +14,8 @@ urlpatterns = [ url(r'^painel/mensagem$', painel_mensagem_view, name="painel_mensagem"), url(r'^painel/parlamentar$', painel_parlamentar_view, name='painel_parlamentar'), + url(r'^painel/switch-painel$', switch_painel, + name="switch_painel"), url(r'^painel/votacao$', painel_votacao_view, name='painel_votacao'), url(r'^painel/cronometro$', cronometro_painel, name='cronometro_painel'), # url(r'^painel/cronometro$', include(CronometroPainelCrud.get_urls())), @@ -21,3 +23,4 @@ urlpatterns = [ url(r'^voto-individual/$', votante_view, name='voto_individual'), ] + diff --git a/sapl/painel/views.py b/sapl/painel/views.py index e4c616512..a7919c510 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -1,3 +1,4 @@ +import json from django.contrib import messages from django.contrib.auth.decorators import user_passes_test @@ -223,6 +224,20 @@ def painel_view(request, pk): return render(request, 'painel/index.html', context) +@user_passes_test(check_permission) +def switch_painel(request): + sessao = SessaoPlenaria.objects.get(id=request.POST['pk_sessao']) + switch = json.loads(request.POST['aberto']) + + if switch: + sessao.painel_aberto = True + else: + sessao.painel_aberto = False + + sessao.save() + return JsonResponse({}) + + @user_passes_test(check_permission) def painel_mensagem_view(request): return render(request, 'painel/mensagem.html') diff --git a/sapl/sessao/migrations/0015_sessaoplenaria_painel_aberto.py b/sapl/sessao/migrations/0015_sessaoplenaria_painel_aberto.py new file mode 100644 index 000000000..73f7b1cc2 --- /dev/null +++ b/sapl/sessao/migrations/0015_sessaoplenaria_painel_aberto.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2017-09-21 17:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0014_auto_20170905_1617'), + ] + + operations = [ + migrations.AddField( + model_name='sessaoplenaria', + name='painel_aberto', + field=models.BooleanField(default=False, verbose_name='Painel está aberto?'), + ), + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index a874fb5f4..b5d31fff7 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -111,6 +111,7 @@ class SessaoPlenaria(models.Model): # TODO analyze querying all hosted databases ! cod_andamento_sessao = models.PositiveIntegerField(blank=True, null=True) + painel_aberto = models.BooleanField(blank=True, default=False, verbose_name=_('Painel está aberto?')) tipo = models.ForeignKey(TipoSessaoPlenaria, on_delete=models.PROTECT, verbose_name=_('Tipo')) diff --git a/sapl/sessao/tests/test_sessao.py b/sapl/sessao/tests/test_sessao.py index ed28bf6ef..b0258312c 100644 --- a/sapl/sessao/tests/test_sessao.py +++ b/sapl/sessao/tests/test_sessao.py @@ -37,7 +37,8 @@ def test_sessao_plenaria_form_valido(): 'tipo': str(tipo.pk), 'sessao_legislativa': str(sessao.pk), 'data_inicio': '10/11/2017', - 'hora_inicio': '10:10' + 'hora_inicio': '10:10', + 'painel_aberto': False }) assert form.is_valid() diff --git a/sapl/sessao/tests/test_sessao_view.py b/sapl/sessao/tests/test_sessao_view.py index 50a94d970..f771074ee 100644 --- a/sapl/sessao/tests/test_sessao_view.py +++ b/sapl/sessao/tests/test_sessao_view.py @@ -19,7 +19,8 @@ def test_incluir_sessao_plenaria_submit(admin_client): 'tipo': str(tipo.pk), 'sessao_legislativa': str(sessao.pk), 'data_inicio': '10/11/2017', - 'hora_inicio': '10:10' + 'hora_inicio': '10:10', + 'painel_aberto': False }, follow=True) assert response.status_code == 200 diff --git a/sapl/templates/sessao/painel.html b/sapl/templates/sessao/painel.html index 5cd84ec32..9719c18f2 100644 --- a/sapl/templates/sessao/painel.html +++ b/sapl/templates/sessao/painel.html @@ -14,6 +14,8 @@
Iniciar painel completo
+
+

@@ -257,6 +259,29 @@ $(function() { }); }); + +function switch_painel(aberto) { + var pk_sessao = {{root_pk}}; + var botao_abrir = document.getElementById('id_abrir_painel'); + var botao_fechar = document.getElementById('id_fechar_painel'); + + + $.ajax({ + data: {pk_sessao: pk_sessao, aberto: aberto}, + type: 'POST', + url: "{% url 'sapl.painel:switch_painel' %}", + headers: {'X-CSRFToken': getCookie('csrftoken')}, + }); + + if (aberto) { + botao_abrir.style.display = 'none'; + botao_fechar.style.display = 'block'; + } else { + botao_abrir.style.display = 'block'; + botao_fechar.style.display = 'none'; + } +} + {% endblock %}