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

Open in your IDE?
  1. {% if not inScript %}<script>{% endif %}
  2.     var collector = document.getElementById('collector');
  3.     // Eventi codici a barre
  4.     $(document).ready(function(){
  5.         if(collector.children.length == 0){
  6.             document.getElementById('buttonAdd').click();
  7.         }
  8.         document.getElementById('row_0').style.background = "rgba(248, 245, 48, 0.425)";
  9.     });
  10.     
  11.     var index = 0;
  12.     function getRowId(index){
  13.         if(collector.children[index] != undefined)
  14.             return collector.children[index].getAttribute('data-rowId');
  15.         else
  16.             return false;
  17.     }
  18.     function actionAddRow(){ document.getElementById('buttonAdd').click(); }
  19.     function actionCodeProducer(){ document.getElementById('{{ formName }}_products_' + getRowId(index) + '_codeProducer').focus(); }
  20.     function actionCodeSupplier(){ document.getElementById('{{ formName }}_products_' + getRowId(index) + '_codeSupplier').focus(); }
  21.     function actionPrevRow(){
  22.         if(index > 0)
  23.             index--;
  24.         selectRow();
  25.         actionCodeSupplier();
  26.     };
  27.     function actionNextRow(){
  28.         index++;
  29.         if(getRowId(index) == false) actionAddRow();
  30.         selectRow();
  31.         actionCodeProducer();
  32.     };
  33.     function actionDeleteRow(){
  34.         if(collector.children.length > 1){
  35.             if(getRowId(index) !== false)
  36.                 document.getElementById('span_delete_row_' + getRowId(index)).children[0].click();
  37.             if(index > 0)
  38.                 actionPrevRow();
  39.             else{
  40.                 index--;
  41.                 actionNextRow();
  42.             }
  43.         }
  44.     }
  45.     
  46.     function selectRow(){
  47.         for(k=0; k<collector.children.length; k++){
  48.             if(document.getElementById('row_' + getRowId(k)) != null)
  49.                 document.getElementById('row_' + getRowId(k)).style.background = "#fff";
  50.         }
  51.         document.getElementById('row_' + getRowId(index)).style.background = "rgba(248, 245, 48, 0.425)";
  52.     }
  53.     
  54.     function selectRowByIndex(subIndex){
  55.         index = subIndex;
  56.         selectRow();
  57.     }
  58.     function checkLastRowEmpty(){
  59.         var producerInputs = document.getElementsByClassName('input_code_producer');
  60.         var supplierInputs = document.getElementsByClassName('input_code_supplier');
  61.         if(producerInputs[producerInputs.length - 1].value == '' && supplierInputs[supplierInputs.length - 1].value == '')
  62.             return true;
  63.         else
  64.             return false;
  65.     }
  66.     function getLastRow(){
  67.         var rowsGun = document.getElementsByClassName('row_gun');
  68.         return rowsGun[rowsGun.length - 1].getAttribute('data-rowId');
  69.     }
  70.     function actionDeleteLastEmptyRow(){
  71.         document.getElementById('span_delete_row_' + getRowId(getLastRow())).children[0].click();
  72.     }
  73.     function selectField(subIndex, type){
  74.         selectRowByIndex(subIndex);
  75.         if(type == 'producer'){
  76.             document.getElementById('{{ formName }}_products_' + subIndex + '_codeProducer').focus();
  77.             document.getElementById('{{ formName }}_products_' + subIndex + '_codeProducer').select();
  78.         }
  79.         else{
  80.             document.getElementById('{{ formName }}_products_' + subIndex + '_codeSupplier').focus();
  81.             document.getElementById('{{ formName }}_products_' + subIndex + '_codeSupplier').select();
  82.         }
  83.     }
  84.     function updateDuplicateInputs(inputs, type){
  85.         for(i=0; i<inputs.length; i++){
  86.             if(inputs[i].value != ""){
  87.                 duplicate = false;
  88.                 for(j=0; j<inputs.length; j++){
  89.                     if(j != i && inputs[i].value == inputs[j].value){
  90.                         duplicate = true;
  91.                         break;
  92.                     }
  93.                 }
  94.                 if(duplicate)
  95.                     setAlert(inputs, i, type);
  96.                 else
  97.                     resetAlert(inputs, i);
  98.             }
  99.             else
  100.                 resetAlert(inputs, i);
  101.         }
  102.     }
  103.     
  104.     function resetAlert(inputs, index){
  105.         inputs[index].style = 'border-color: #ced4da';
  106.         inputs[index].removeAttribute('data-bs-toggle');
  107.         inputs[index].removeAttribute('data-bs-original-title');
  108.     }
  109.     function setAlert(inputs, index, type){
  110.         inputs[index].style = 'border-color: #CB0C0F';
  111.         inputs[index].setAttribute('data-bs-toggle', 'tooltip');
  112.         if(type == "producer")
  113.             inputs[index].setAttribute('title', 'Matricola produttore già presente!');
  114.         else
  115.             inputs[index].setAttribute('title', 'Matricola fornitore già presente!');
  116.     }
  117.     {% block eventListener %}{% endblock %}
  118. {% if not inScript %}</script>{% endif %}