mirror of https://github.com/interlegis/sapl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.6 KiB
109 lines
3.6 KiB
{% extends "crud/form.html" %}
|
|
{% load i18n %}
|
|
{% load crispy_forms_tags %}
|
|
{% load common_tags %}
|
|
|
|
{% block extra_js %}
|
|
<script language="Javascript">
|
|
function recuperar_numero_ano() {
|
|
var tipo = $("#id_tipo").val()
|
|
var ano = $("#id_ano").val()
|
|
|
|
if (tipo && ano){
|
|
$.get("/materia/recuperar-materia", { tipo: tipo, ano: ano },
|
|
function (data, status) {
|
|
$("#id_numero").val(data.numero);
|
|
$("#id_ano").val(data.ano);
|
|
console.log(data);
|
|
});
|
|
}
|
|
}
|
|
$("#id_tipo, #id_ano").change(recuperar_numero_ano);
|
|
|
|
function compare(a, b) {
|
|
if (a.text < b.text)
|
|
return -1;
|
|
if (a.text > b.text)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
var modal_estilos = 'display: block;'
|
|
+'width: 85%; max-width: 600px;'
|
|
+'background: #fff; padding: 15px;'
|
|
+'border-radius: 5px;'
|
|
+'-webkit-box-shadow: 0px 6px 14px -2px rgba(0,0,0,0.75);'
|
|
+'-moz-box-shadow: 0px 6px 14px -2px rgba(0,0,0,0.75);'
|
|
+'box-shadow: 0px 6px 14px -2px rgba(0,0,0,0.75);'
|
|
+'position: fixed;'
|
|
+'top: 50%; left: 50%;'
|
|
+'transform: translate(-50%,-50%);'
|
|
+'z-index: 99999999; text-align: center';
|
|
|
|
var fundo_modal_estilos = 'top: 0; right: 0;'
|
|
+'bottom: 0; left: 0; position: fixed;'
|
|
+'background-color: rgba(0, 0, 0, 0.6); z-index: 99999999;'
|
|
+'display: none;';
|
|
|
|
var meu_modal = '<div id="fundo_modal" style="'+fundo_modal_estilos+'">'
|
|
+'<div id="meu_modal" style="'+modal_estilos+'">'
|
|
+'<h2>Atenção! Ano de apresentação e ano da matéria são diferentes.</h2><br />'
|
|
+'<button id="close_model_btn" type="button" class="btn btn-warning" data-dismiss="modal">'
|
|
+'Compreendo e quero continuar</button>'
|
|
+'</div></div>';
|
|
|
|
function verifica_ano() {
|
|
let ano = $("select#id_ano.select").val();
|
|
let data_apresentacao = $("input#id_data_apresentacao.dateinput").val();
|
|
let ano_apresentacao = data_apresentacao.substr(data_apresentacao.length - 4);
|
|
|
|
if (ano && ano_apresentacao && ano_apresentacao != ano){
|
|
$('#fundo_modal').fadeIn();
|
|
}
|
|
}
|
|
|
|
$(document).ready( function() {
|
|
$("#id_tipo_autor, #id_data_apresentacao").change( function() {
|
|
var tipo_selecionado = $("#id_tipo_autor").val();
|
|
var autor_selecionado = $("#id_autor").val();
|
|
|
|
$("#id_autor option").remove()
|
|
|
|
if (tipo_selecionado !== undefined && tipo_selecionado !== null){
|
|
var json_data = {
|
|
tipo : tipo_selecionado,
|
|
data_relativa : $("#id_data_apresentacao").val()
|
|
}
|
|
$.getJSON("/api/autor/possiveis", json_data, function(data) {
|
|
if (data) {
|
|
var results = data.sort(compare);
|
|
if (results.length > 1) {
|
|
$("#id_autor").append("<option>-----</option>");
|
|
}
|
|
$.each(results, function(idx, obj) {
|
|
$("#id_autor")
|
|
.append($("<option></option>")
|
|
.attr("value", obj.value)
|
|
.text(obj.text));
|
|
});
|
|
$("#id_autor").val(autor_selecionado);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
$("#id_tipo_autor").trigger('change');
|
|
|
|
$("body").append(meu_modal);
|
|
|
|
$("#fundo_modal, #close_model_btn").click( function() { $("#fundo_modal").hide(); });
|
|
$("#meu_modal").click( function(e) { e.stopPropagation(); });
|
|
|
|
$("select#id_ano.select.form-control").change( function() {
|
|
verifica_ano();
|
|
});
|
|
$("input#id_data_apresentacao.dateinput.form-control").change( function() {
|
|
verifica_ano();
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|
|
|