templates/components/js/city_js.html.twig line 1

Open in your IDE?
  1. <script>
  2.     {% if zipManage and app.session.get(sessionModalOpen) %}
  3.         $(document).ready(function(){
  4.             zipUpdateSelect{{ number }}(true);
  5.         });
  6.     {% endif %}
  7.     // COMUNE
  8.     function cityModal{{ number }}(){
  9.         {% if hasOtherCity %}
  10.             document.getElementById('{{ formName }}_select_zips').style.display = 'block';
  11.             document.getElementById('other_zip').style.display = 'none';
  12.         {% endif %}
  13.         {% if modalToClose != '' %}
  14.             $('#{{ modalToClose }}').modal('hide');
  15.         {% endif %}
  16.         $('#modalCity{{ number }}').modal({backdrop: 'static', keyboard: false}).modal('show');
  17.     }
  18.     function cityFilter{{ number }}(){
  19.         var name = document.getElementById("city_filter_val_{{ number }}").value;
  20.         $.post("{{ path ('cities_update') }}", { name:name }, function(response){
  21.             if(response.code == 200 && response.success){
  22.                 var tbody = document.getElementById("city_table_{{ number }}");
  23.                 tbody.innerHTML = "";
  24.                 var cities = JSON.parse(response.cities);
  25.                 if(cities.length == 0){
  26.                     
  27.                     var tr = document.createElement("tr");
  28.                     var tdAlert = document.createElement("td");
  29.                     var div1 = document.createElement("div");
  30.                     var div2 = document.createElement("div");
  31.                     div2.innerHTML = "<i class='icon-warning-sign'></i><strong>Attenzione!</strong> La ricerca non ha dato risultati; controlla il nome inserito!";
  32.                     div2.className = "sb-msg";
  33.                     div1.className = "style-msg alertmsg m_b_none";
  34.                     div1.appendChild(div2);
  35.                     tdAlert.colSpan = "3";
  36.                     tdAlert.appendChild(div1);
  37.                     tr.appendChild(tdAlert);
  38.                     tbody.appendChild(tr);
  39.                 }
  40.                 else{
  41.                     for(var i = 0; i < cities.length; i++){
  42.                         var tr = document.createElement("tr");
  43.                         var tdName = document.createElement("td");
  44.                         var tdSelect = document.createElement("td");
  45.                         
  46.                         tdName.innerHTML = cities[i]['name'] + ' (' + cities[i]['province'] + ')';
  47.                         
  48.                         var aSelect = document.createElement("a");
  49.                         aSelect.innerHTML = '<img class="icon_action icon_green" src="{{ asset (icon_select) }}" />';
  50.                         aSelect.href = 'javascript: citySelect{{ number }}(' + cities[i]['id'] + ', "' + cities[i]['name'] + ' (' + cities[i]['province'] + ')' + '")';
  51.                         tdSelect.className = "txt_a_c";
  52.                         tdSelect.appendChild(aSelect);
  53.                         
  54.                         tr.appendChild(tdName);
  55.                         tr.appendChild(tdSelect);
  56.                         tbody.appendChild(tr);
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         , "json");
  62.     }
  63.     function citySelect{{ number }}(id, name){
  64.         document.getElementById('{{ formName }}_cityId').value = id;
  65.         document.getElementById("{{ formName }}_cityName").value = name;
  66.         {% if zipManage %}
  67.             zipUpdateSelect{{ number }}(false);
  68.         {% endif %}
  69.         $('#modalCity{{ number }}').modal('hide');
  70.         {% if modalToClose != '' %}
  71.             $('#{{ modalToClose }}').modal({backdrop: 'static', keyboard: false}).modal('show');
  72.         {% endif %}
  73.     }
  74.     function cityDeselect{{ number }}(){
  75.         document.getElementById('{{ formName }}_cityId').value = null;
  76.         document.getElementById('{{ formName }}_cityName').value = '';
  77.         zipUpdateSelect{{ number }}(false);
  78.         $('#modalCity{{ number }}').modal('hide');
  79.         {% if modalToClose != '' %}
  80.             $('#{{ modalToClose }}').modal({backdrop: 'static', keyboard: false}).modal('show');
  81.         {% endif %}
  82.     }
  83.     
  84.     {% if hasOtherCity %}
  85.         function cityInsert{{ number }}(){
  86.             document.getElementById('{{ formName }}_otherCity').value = document.getElementById('other_city_{{ number }}').value;
  87.             document.getElementById('{{ formName }}_cityName').value = document.getElementById('other_city_{{ number }}').value;
  88.             document.getElementById('{{ formName }}_select_zips').style.display = 'none';
  89.             document.getElementById('other_zip').style.display = 'block';
  90.             $('#modalCity{{ number }}').modal('hide');
  91.             {% if modalToClose != '' %}
  92.                 $('#{{ modalToClose }}').modal({backdrop: 'static', keyboard: false}).modal('show');
  93.             {% endif %}
  94.         }
  95.     {% endif %}
  96.     function zipUpdateSelect{{ number }}(init){
  97.         var cityId = document.getElementById('{{ formName }}_cityId').value;
  98.         $.post("{{ path ('city_zips') }}", { cityId:cityId }, function(response){
  99.             if(response.code == 200 && response.success){
  100.                 
  101.                 var select = document.getElementById('{{ formName }}_select_zips');
  102.                 while(select.options.length){
  103.                     select.remove(0);
  104.                 }
  105.                 if(response.zips.includes(',')){
  106.                     // MULTI
  107.                     var zs = response.zips.split(',');
  108.                     for(var i=0; i < zs.length; i++){
  109.                         var array = zs[i].split('-');
  110.                         var opt = new Option(array[1], array[0]);
  111.                         select.options.add(opt);
  112.                     }
  113.                     if(init){
  114.                         var j = select.options.length;
  115.                         for(var k=0; k < j; k++){
  116.                             if(select.options[k].value == document.getElementById('{{ formName }}_zip').value){
  117.                                 select.selectedIndex = k;
  118.                                 break;
  119.                             }
  120.                         }
  121.                     }
  122.                     else{
  123.                         document.getElementById('{{ formName }}_zip').value = '';
  124.                     }
  125.                 }
  126.                 else{
  127.                     var array = response.zips.split('-');
  128.                     document.getElementById('{{ formName }}_zip').value = array[1];
  129.                     var opt = new Option(array[1], array[0]);
  130.                     select.options.add(opt);
  131.                 }
  132.                 select.removeAttribute('readonly');
  133.                 zipSet{{ number }}();
  134.             }
  135.         }
  136.         , "json");
  137.     }
  138.     function zipSet{{ number }}(){
  139.         document.getElementById('{{ formName }}_zip').value = document.getElementById('{{ formName }}_select_zips').value;
  140.     }
  141.     
  142.     function cityModalClose{{ number }}(){
  143.         $('#modalCity{{ number }}').modal('hide');
  144.         {% if modalToClose != '' %}
  145.             $('#{{ modalToClose }}').modal({backdrop: 'static', keyboard: false}).modal('show');
  146.         {% endif %}
  147.     }
  148. </script>