{% if not inScript %}<script>{% endif %}
var collector = document.getElementById('collector');
// Eventi codici a barre
$(document).ready(function(){
if(collector.children.length == 0){
document.getElementById('buttonAdd').click();
}
document.getElementById('row_0').style.background = "rgba(248, 245, 48, 0.425)";
});
var index = 0;
function getRowId(index){
if(collector.children[index] != undefined)
return collector.children[index].getAttribute('data-rowId');
else
return false;
}
function actionAddRow(){ document.getElementById('buttonAdd').click(); }
function actionCodeProducer(){ document.getElementById('{{ formName }}_products_' + getRowId(index) + '_codeProducer').focus(); }
function actionCodeSupplier(){ document.getElementById('{{ formName }}_products_' + getRowId(index) + '_codeSupplier').focus(); }
function actionPrevRow(){
if(index > 0)
index--;
selectRow();
actionCodeSupplier();
};
function actionNextRow(){
index++;
if(getRowId(index) == false) actionAddRow();
selectRow();
actionCodeProducer();
};
function actionDeleteRow(){
if(collector.children.length > 1){
if(getRowId(index) !== false)
document.getElementById('span_delete_row_' + getRowId(index)).children[0].click();
if(index > 0)
actionPrevRow();
else{
index--;
actionNextRow();
}
}
}
function selectRow(){
for(k=0; k<collector.children.length; k++){
if(document.getElementById('row_' + getRowId(k)) != null)
document.getElementById('row_' + getRowId(k)).style.background = "#fff";
}
document.getElementById('row_' + getRowId(index)).style.background = "rgba(248, 245, 48, 0.425)";
}
function selectRowByIndex(subIndex){
index = subIndex;
selectRow();
}
function checkLastRowEmpty(){
var producerInputs = document.getElementsByClassName('input_code_producer');
var supplierInputs = document.getElementsByClassName('input_code_supplier');
if(producerInputs[producerInputs.length - 1].value == '' && supplierInputs[supplierInputs.length - 1].value == '')
return true;
else
return false;
}
function getLastRow(){
var rowsGun = document.getElementsByClassName('row_gun');
return rowsGun[rowsGun.length - 1].getAttribute('data-rowId');
}
function actionDeleteLastEmptyRow(){
document.getElementById('span_delete_row_' + getRowId(getLastRow())).children[0].click();
}
function selectField(subIndex, type){
selectRowByIndex(subIndex);
if(type == 'producer'){
document.getElementById('{{ formName }}_products_' + subIndex + '_codeProducer').focus();
document.getElementById('{{ formName }}_products_' + subIndex + '_codeProducer').select();
}
else{
document.getElementById('{{ formName }}_products_' + subIndex + '_codeSupplier').focus();
document.getElementById('{{ formName }}_products_' + subIndex + '_codeSupplier').select();
}
}
function updateDuplicateInputs(inputs, type){
for(i=0; i<inputs.length; i++){
if(inputs[i].value != ""){
duplicate = false;
for(j=0; j<inputs.length; j++){
if(j != i && inputs[i].value == inputs[j].value){
duplicate = true;
break;
}
}
if(duplicate)
setAlert(inputs, i, type);
else
resetAlert(inputs, i);
}
else
resetAlert(inputs, i);
}
}
function resetAlert(inputs, index){
inputs[index].style = 'border-color: #ced4da';
inputs[index].removeAttribute('data-bs-toggle');
inputs[index].removeAttribute('data-bs-original-title');
}
function setAlert(inputs, index, type){
inputs[index].style = 'border-color: #CB0C0F';
inputs[index].setAttribute('data-bs-toggle', 'tooltip');
if(type == "producer")
inputs[index].setAttribute('title', 'Matricola produttore già presente!');
else
inputs[index].setAttribute('title', 'Matricola fornitore già presente!');
}
{% block eventListener %}{% endblock %}
{% if not inScript %}</script>{% endif %}