Advertisement
yesamarcos

Código

Dec 1st, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             $(function($) {$('.dropdown-toggle').dropdown('toggle');});
  2.             $('#ajax_local, #ajax_servico, #ajax_persquisador').multiselect({
  3.                 /**/
  4.                 includeSelectAllOption: true,
  5.                 nSelectedText: 'selecionados ..',
  6.                 nonSelectedText:'Nenhum selecionado ..',
  7.                 allSelectedText: 'Todos selecionados ..',
  8.                 selectAllText: 'Selecionar todos ..',
  9.                 numberDisplayed: 1,        
  10.             });
  11.             // ...
  12.             $('#ajax_empresa').multiselect({
  13.                 /**/
  14.                 includeSelectAllOption: true,
  15.                 nSelectedText: 'selecionados ..',
  16.                 nonSelectedText:'Nenhum selecionado ..',
  17.                 allSelectedText: 'Todos selecionados ..',
  18.                 selectAllText: 'Selecionar todos ..',
  19.                 numberDisplayed: 1,
  20.                 onDropdownHide: function(option, checked){
  21.                     // ...
  22.                     MultiselectSet($("#ajax_persquisador"));
  23.                     MultiselectSet($("#ajax_servico"));
  24.                     MultiselectSet($("#ajax_local"));
  25.                     // ...
  26.                     var empresas = [];
  27.                     $("#ajax_empresa option:selected").each(function(){
  28.                         var empresa = $(this).val();
  29.                         empresas.push(empresa);
  30.                     });
  31.                     // Se empresa vazia ...
  32.                     if(empresas.length == 0){
  33.                         $("#ajax_local, #ajax_servico, #ajax_persquisador").multiselect('destroy');
  34.                         $.ajax({
  35.                             url: '/ajaxrequests/reset',
  36.                             type: 'POST'
  37.                         });
  38.                     }                      
  39.                     // ...
  40.                     $.ajax({
  41.                         url: '/ajaxrequests/requestlocals',
  42.                         type: 'POST', dataType: 'json',
  43.                         data: {empresas:empresas},
  44.                         success: function(retorno){
  45.                             var locals = retorno.locals;
  46.                             var checks = retorno.check;
  47.                             //console.log(retorno);
  48.                             $('#ajax_local').html("");
  49.                             $.each(locals, function(valor, chave){
  50.                                 $('#ajax_local').append($('<option>', {
  51.                                     value: valor,
  52.                                     text : chave,
  53.                                     checked: checks[valor],
  54.                                     selected: checks[valor]
  55.                                 }));
  56.                             });
  57.                             $("#ajax_local").multiselect('destroy');
  58.                             MultiselectSet($("#ajax_local"));
  59.                         }
  60.                     });
  61.                     // ...
  62.                     $.ajax({
  63.                         url: '/ajaxrequests/requestpesquisadores',
  64.                         type: 'POST', dataType: 'json',
  65.                         data: {empresas:empresas},
  66.                         success: function(retorno){
  67.                             var pesqs = retorno.pesquisadores;
  68.                             var checks = retorno.check;
  69.                             //console.log(retorno);                    
  70.                             $('#ajax_persquisador').html("");
  71.                             $.each(pesqs, function(valor, chave){
  72.                                 $('#ajax_persquisador').append($('<option>', {
  73.                                     value: valor,
  74.                                     text : chave,
  75.                                     checked: checks[valor],
  76.                                     selected: checks[valor]
  77.                                 }));
  78.                             });
  79.                             $("#ajax_persquisador").multiselect('destroy');
  80.                             MultiselectSet($("#ajax_persquisador"));
  81.                         }
  82.                     });
  83.                     // ...
  84.                     $.ajax({
  85.                         url: '/ajaxrequests/requestservicos',
  86.                         type: 'POST', dataType: 'json',
  87.                         data: {empresas:empresas},
  88.                         success: function(retorno){
  89.                             var servs = retorno.servicos; // [10, 12, 14, 20, 21, 23, 25, 29, 32, 33, 38, 45]
  90.                             var checks = retorno.check; // [10, 12, 14, 20, 21, 23, 25]
  91.                             console.log(retorno);
  92.                             $('#ajax_servico').html("");
  93.                             $.each(servs, function(valor, chave){
  94.                                
  95.                                 $('#ajax_servico').append($('<option>', {
  96.                                     value: valor,
  97.                                     text : chave,
  98.                                     checked: checks[valor],
  99.                                     selected: checks[valor]
  100.                                 }));
  101.                             });
  102.                             $("#ajax_servico").multiselect('destroy');
  103.                             MultiselectSet($("#ajax_servico"));
  104.                         }
  105.                     });
  106.                 }
  107.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement