Created
October 3, 2015 15:08
-
-
Save fchevitarese/b7e11eefc49420018118 to your computer and use it in GitHub Desktop.
alteration.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
function getCookie(name) | |
{ | |
var cookieValue = null; | |
if (document.cookie && document.cookie != '') { | |
var cookies = document.cookie.split(';'); | |
for (var i = 0; i < cookies.length; i++) { | |
var cookie = jQuery.trim(cookies[i]); | |
// Does this cookie string begin with the name we want? | |
if (cookie.substring(0, name.length + 1) == (name + '=')) { | |
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | |
break; | |
} | |
} | |
} | |
return cookieValue; | |
} | |
$.ajaxSetup({ | |
beforeSend: function(xhr, settings) { | |
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { | |
// Only send the token to relative URLs i.e. locally. | |
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); | |
} | |
} | |
}); | |
$('#pedido_tab').css('display','none'); | |
$('#pagamento_tab').css('display','none'); | |
// $('#filtro_cpf').css('display','none'); | |
$('#filtro_pedido').css('display','none'); | |
$('#esconder').css('display','none'); | |
$('#cpf_ok').css('display','none'); | |
$('#cpf_negativado').css('display','none'); | |
$('#cliente_tab').click(function(){ | |
$('#filtro_pedido').css('display','none'); | |
$('#filtro_cpf').fadeIn(1000) | |
$('#filtro_cpf').css('display','block'); | |
}); | |
$('#pedido_tab').click(function(){ | |
$('#produto_tile').css('display','none'); | |
$('#filtro_cpf').css('display','none'); | |
$('#filtro_pedido').fadeIn(1000); | |
$('#filtro_pedido').css('display','block'); | |
}); | |
$('#pagamento_tab').click(function(){ | |
$('#filtro_cpf').css('display','none'); | |
$('#filtro_pedido').css('display','none'); | |
}); | |
$('#cod_produto').keyup('change', function(){ | |
$.ajax({ | |
type:"GET", | |
data: {"cod_produto": $('#cod_produto').val()}, | |
url:"/ecommerce/validate/", | |
success:function(data){ | |
var produto = []; | |
produto.push(data.nome); | |
produto.push(data.codigo); | |
produto.push(data.descricao); | |
produto.push(data.preco); | |
produto.push(data.estoque); | |
produto.push(data.categoria); | |
$('#nome').val(produto.nome) | |
$('#codigo').val(produto.codigo) | |
$('#descricao').val(produto.descricao) | |
$('#preco').val(produto.preco) | |
$('#estoque').val(produto.estoque) | |
$('#prod_nome').text(produto.nome); | |
$('#prod_codigo').text(produto.codigo) | |
$('#prod_preco').text(produto.preco) | |
$('#prod_estoque').text(produto.estoque) | |
$('#prod_categoria').text(produto.categoria) | |
$('#produto_tile').fadeIn(1000); | |
$('#produto_tile').css('display','block'); | |
qtd_produtos = 0; | |
$('#inserir').click('change',function(){ | |
var quant = $('#quant').val() | |
var total = produto.preco * quant | |
var dados = "<tr>"+ | |
"<td name='id_codigo" + qtd_produtos + "''><b>" + produto.codigo + "</b></td>"+ | |
"<td name='id_nome'" + qtd_produtos + ">" + produto.nome +" </td>"+ | |
"<td>" + produto.descricao +" </td>"+ | |
"<td name='id_quant'" + qtd_produtos + ">" + quant + "</td>"+ | |
"<td>" + produto.preco +" </td>"+ | |
"<td class='text-right pr10'>" + total +" </td>"+ | |
"</tr>" | |
$('#tabela_pedido').append(dados); | |
qtd_produtos++; | |
$('#enviar').click(function(){ | |
$.ajax({ | |
type:"POST", | |
data: {'id_nome': data.nome, 'id_codigo': data.codigo, 'id_quant': quant}, | |
url:"/ecommerce/pedidos/", | |
}); | |
}); | |
}); | |
} | |
}); | |
}); | |
$('#cpf').keyup('change',function(){ | |
if($('#cpf').val().length <= 10){ | |
$('#esconder, #cpf_ok, #cpf_negativado').fadeOut(1000); | |
$('#esconder, #cpf_ok, #cpf_negativado').css('display','none'); | |
}; | |
if($('#cpf').val().length == 11){ | |
$.ajax({ | |
type:"GET", | |
data: {"cpf" : $('#cpf').val()}, | |
url:"/ecommerce/validate/", | |
success:function(data){ | |
if(data == "False"){ | |
$('#cpf_ok, #pedido_tab, #pagamento_tab, #esconder').css('display','none'); | |
$('#cpf_negativado').css('display','block'); | |
$('#cliente').attr('disabled', ''); | |
$('#cpf').css( | |
{color: '#E63F24', 'font-weight' : 'bold'} | |
); | |
$('#cpf').addClass('has-error'); | |
$(function(){ | |
new PNotify({ | |
title: 'ATENÇÃO', | |
text: 'O CPF é inválido', | |
type: 'error' | |
}); | |
}); | |
} else { | |
$('#pedido_tab, #pagamento_tab,#cpf_ok, #esconder').fadeIn(1000); | |
$('#pedido_tab, #pagamento_tab, #cpf_ok, #esconder').css('display','block'); | |
$('#cpf_negativado').css('display','none'); | |
$('#cliente').removeAttr('disabled', ''); | |
$('#cpf').removeClass('has-error'); | |
$('#cpf').addClass('has-success'); | |
$('#cpf').css( | |
{color: '#5BC24C', 'font-weight' : 'bold'} | |
); | |
$.each(data, function(k, v) { | |
$('#nome').val(data.nome) | |
$('#email').val(data.email) | |
$('#tel_fixo').val(data.tel_fixo) | |
$('#tel_movel').val(data.tel_movel) | |
$('#endereco').val(data.endereco) | |
$('#numero').val(data.numero) | |
$('#complemento').val(data.complemento) | |
$('#bairro').val(data.bairro) | |
$('#cidade').val(data.cidade) | |
$('#estado').val(data.estado) | |
$('#cep').val(data.cep) | |
$('#invoice_nome').text(data.nome) | |
$('#invoice_endereco').text(data.endereco) | |
$('#invoice_numero').text(data.numero) | |
$('#invoice_cidade').text(data.cidade) | |
$('#invoice_estado').text(data.estado) | |
$('#invoice_cep').text(data.cep) | |
$('#invoice_tel_fixo').text(data.tel_fixo) | |
$('#invoice_entrega_nome').text(data.nome) | |
$('#invoice_entrega_endereco').text(data.endereco) | |
$('#invoice_entrega_numero').text(data.numero) | |
$('#invoice_entrega_cidade').text(data.cidade) | |
$('#invoice_entrega_estado').text(data.estado) | |
$('#invoice_entrega_cep').text(data.cep) | |
$('#invoice_entrega_tel_fixo').text(data.tel_fixo) | |
if(data.unico == true){ | |
$('#cep_unico').fadeIn('slow', function(){ | |
$('#cep_unico').css('display','block'); | |
}); | |
} | |
}) | |
} | |
} | |
}) | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment