Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function _ajax(a, url, acao) {
  2.     var dados = $("#form-pesq").serialize() + '&acao=' + acao;
  3.     return $.ajax({
  4.         type: "POST",
  5.         url: url,
  6.         data: dados,
  7.         cache: false,
  8.         success: function (resposta) {
  9.             $("#" + a).html(resposta);
  10.         },
  11. //        complete: function () {
  12. //            refreshMultiSelect(a);
  13. //        },
  14.         error: function () {
  15.             alert("Erro, tente novamente");
  16.         }
  17.     });
  18. }
  19. function refreshMultiSelect(tipos) {//a : nome da variavel, ex: tipo, cidade...
  20.     if (tipos == undefined) {
  21.         alert("Passe o ID do select");
  22.     }
  23.     var m = $("#" + tipos).next(".dropdown-multiselect");
  24.     if (m.length != 0) {
  25.         //info("refresh")
  26.         $("#" + tipos).multiselect('refresh');
  27.     } else {
  28.         $("#" + tipos).multiselect();
  29.     }
  30. }
  31. $(document).ready(function () {
  32.     //Radios e buttons
  33.     //$("#pesquisar,#limpar").button();
  34.     //$(".tipo_negoc,#qtd_dorm,#qtd_vaga").buttonset();
  35.     //Cidades  
  36.     //Tipo negociacao
  37.     //pré cria os multiselect's
  38.     $("#tipos").multiselect();
  39.     $("#cidade").multiselect();
  40.     $("#bairro").multiselect();
  41.  
  42.     $("#locacao,#venda").click(function () {
  43.  
  44.         //chama tipos
  45.         _ajax('tipos', "estrutura/tipo-imov-ajax.php", 'listar_tipo_imov')
  46.                 .complete(function () {
  47.                     //atualiza multiselect tipos
  48.                     refreshMultiSelect('tipos');
  49.                     //chama ajax cidades
  50.                     _ajax('cidades', "estrutura/cidades-ajax.php", 'listar_cidades')
  51.                             .complete(function () {
  52.                                 //atualiza multiselect cidades
  53.                                 refreshMultiSelect('cidades');
  54.                                 //chama ajax bairros
  55.                                 _ajax('bairro', "estrutura/cidades-ajax.php", 'listar_cidades')
  56.                                         .complete(function () {
  57.                                             //atualiza multiselect bairros
  58.                                             refreshMultiSelect('bairros');
  59.                                         });
  60.                             });
  61.                 });
  62.     });
  63.  
  64.     //Codigo imovel
  65.     $('#cod-imovel').each(function () {
  66.         var default_value = 'Código';
  67.         $(this).focus(function () {
  68.             if (this.value == default_value) {
  69.                 this.value = '';
  70.             }
  71.         });
  72.         $(this).blur(function () {
  73.             if (this.value == '') {
  74.                 this.value = default_value;
  75.             }
  76.         });
  77.     });
  78.  
  79.  
  80.     //Validacoes
  81.     $('.cod-imovel').click(function () {
  82.         $('#cod-imovel').val('').focus();
  83.     });
  84.  
  85.     $('.faixa1').click(function () {
  86.         $('#faixa1').val('').focus();
  87.     });
  88.     $('.faixa2').click(function () {
  89.         $('#faixa2').val('').focus();
  90.     });
  91.  
  92.     $("#faixa1,#faixa2").maskMoney({symbol: "", decimal: ",", thousands: "."});
  93.  
  94.     //Pesquisar listagem
  95.     $("#pesquisar").click(function () {
  96.  
  97.         setTimeout(function () {
  98.             var dados = $("#form-pesq").serialize() + '&acao=listar_imoveis';
  99.  
  100.             $.ajax({
  101.                 type: "POST",
  102.                 url: "estrutura/listagem-ajax.php",
  103.                 data: dados,
  104.                 cache: false,
  105.                 beforeSend: function () {
  106.                     //$("#listagem_ajax").html("Carregando ...");
  107.                 },
  108.                 success: function (resposta) {
  109.                     //alert(resposta);
  110.                     $("#listagem_ajax").html(resposta);
  111.  
  112.                     $("#destaques").html("");
  113.  
  114.                 },
  115.                 error: function () {
  116.                     alert("Erro, tente novamente");
  117.                 }
  118.             });
  119.         }, 200);
  120.     });
  121.  
  122.  
  123.     //Carregando
  124.     $(".loading").hide();
  125.     $(".loading").ajaxStart(function () {
  126.         $(this).show();
  127.     })
  128.     $(".loading").ajaxStop(function () {
  129.         setTimeout(function () {
  130.             $(".loading").hide();
  131.         }, 100);
  132.     })
  133.     $(".loading").ajaxError(function () {
  134.         alert("Atenção!\nPágina não encontrada...");
  135.     });
  136.  
  137.  
  138.     $('#limpar').click(function () {
  139.         $("#form-pesq")[0].reset();
  140.         $('#locacao').click();
  141.         ajax.abort();
  142.     });
  143.  
  144.     //Não tirar desta ordem e daqui
  145.     if ($('#form-pesq').length) {
  146.         $("#form-pesq")[0].reset();
  147.     }
  148.     //inicializa combos
  149.     $('#locacao').click();
  150.  
  151. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement