From cb5aab9ea0e9524c5bbc287b3758c1865d246560 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 27 Apr 2016 12:54:03 -0300 Subject: [PATCH] Ao recarregar a tela da pesquisa traz nome do autor. --- protocoloadm/urls.py | 7 +++++-- protocoloadm/views.py | 17 +++++++++++++++++ static/js/app.js | 13 +++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index e69decff5..9022e4358 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -22,7 +22,8 @@ from protocoloadm.views import (AnularProtocoloAdmView, TramitacaoAdmDeleteView, TramitacaoAdmEditView, TramitacaoAdmIncluirView, TramitacaoAdministrativoCrud, - TramitacaoAdmView, pesquisa_autores) + TramitacaoAdmView, get_nome_autor, + pesquisa_autores) from .apps import AppConfig @@ -97,5 +98,7 @@ urlpatterns = [ url(r'^proposicao/(?P\d+)/proposicao', ProposicaoDetailView.as_view(), name='proposicao_view'), url(r'^proposicao/pesquisar_autor', - pesquisa_autores, name='pesquisar_autor') + pesquisa_autores, name='pesquisar_autor'), + url(r'^proposicao/get_nome_autor', + get_nome_autor, name='get_nome_autor') ] diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 980b7cdbe..851cf76f9 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -2,6 +2,7 @@ import json from datetime import date, datetime from braces.views import FormValidMessageMixin +from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db.models import Q, Max from django.http import HttpResponse, HttpResponseRedirect @@ -634,6 +635,22 @@ class TramitacaoAdmDeleteView(DetailView): 'tramitacoes': tramitacoes}) +def get_nome_autor(request): + nome_autor = '' + if request.method == 'GET': + id = request.GET.get('id', '') + try: + autor = Autor.objects.get(pk=id) + if autor.parlamentar: + nome_autor = autor.parlamentar.nome_parlamentar + elif autor.comissao: + nome_autor = autor.comissao.nome + except ObjectDoesNotExist: + pass + return HttpResponse("{\"nome\":\"" + nome_autor + "\"}", + content_type="application/json; charset=utf-8") + + def pesquisa_autores(request): q = '' if request.method == 'GET': diff --git a/static/js/app.js b/static/js/app.js index 4523eeb52..a9cc8f684 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -59,7 +59,7 @@ function autorModal() { } }); - $( "#button-id-limpar" ).click(function() { + $("#button-id-limpar").click(function() { $("#nome_autor").text(''); $("#id_autor").val(''); }); @@ -71,7 +71,7 @@ function autorModal() { $("#selecionar").attr("hidden", "hidden"); }); - $( "#pesquisar" ).click(function() { + $("#pesquisar").click(function() { var query = $("#q").val() $.get("/proposicao/pesquisar_autor?q="+ query, function( @@ -121,6 +121,15 @@ function autorModal() { }); }); }); + + if ($("#id_autor").length > 0) { // se campo existir + if ($("#id_autor").val() != "") { // e não for vazio + var id = $("#id_autor").val(); + $.get("/proposicao/get_nome_autor?id=" + id, function(data, status){ + $("#nome_autor").text(data.nome); + }); + } + } } $(document).ready(function(){