/** * */ $(document).ready(function() { $( "#sortable1" ).sortable(); // Evento: click sull'area di anvigazione delle tab $('#tab-list').on('click', refreshClaList); // Evento: click sull'icona check dentro il tab della clausola $('#cla-TabContent').on('click', '.return2Query', function() { var tabFirst = $('#tab-list a:first'); refreshClaList(); tabFirst.tab('show'); }); // Evento: click sull'icona rimuovi dentro il tab della clausola $('#cla-TabContent').on('click', '.removeClaInTab', function() { var tabIDVal = "#" + $(this).parent('div').parent().attr('id'); removedTabOrder = $(tabIDVal).attr('data-claOrder'); var liID = tabIDVal +"-tab"; claListLen--; $(liID).parent().remove(); $(tabIDVal).remove(); var tabFirst = $('#tab-list a:first'); refreshTabList(); refreshClaList(); tabFirst.tab('show'); }); // Evento: click sull'icona rimuovi dentro la lista delle clausole $('#cla-TabContent').on('click', '.removeClaInList', function() { var tabIDHandle = $(this).closest('li').attr('id'); var tabIDVal = "#" + tabIDHandle.substring(2); removedTabOrder = $(tabIDVal).attr('data-claOrder'); var liID = tabIDVal + "-tab"; claListLen--; $(liID).parent().remove(); $(tabIDVal).remove(); var tabFirst = $('#tab-list a:first'); refreshTabList(); refreshClaList(); tabFirst.tab('show'); }); // Evento: click sull'icona modifica dentro la lista delle clausole $('#cla-TabContent').on('click', '.editCla', function() { var tabIDHandle = $(this).closest('li').attr('id'); var liID = "#" + tabIDHandle.substring(2) + "-tab"; var tabTarget = $('#tab-list ' + liID); tabTarget.tab('show'); }); // Evento: click sulla lista di clausole nel dropbox "Aggiungi clausola di tipo:" $('.btn-group a').on('click', function() { var addClaN = $(this).attr('id'); switch (addClaN) { case "Grammaticale": tabID++; var clone = document.getElementById("tipogrammaticaleN").cloneNode(true); clone.setAttribute("id","cla" + tabID); clone.setAttribute("data-claOrder",claListLen); clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); clone.removeAttribute("style"); $('#cla-TabContent').append(clone); // se non cambio l'id della select react non rileva l'evento onchange: $('#cla' + tabID + " #grammtypes").attr("id","grammtypes" + tabID); claListLen++; $('#tab-list').append($('')); $('#cla' + tabID + '-tab').tab('show'); break; case "Sintattico": tabID++; var clone = document.getElementById("tiposintatticoN").cloneNode(true); clone.setAttribute("id","cla" + tabID); clone.setAttribute("data-claOrder",claListLen); clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); clone.removeAttribute("style"); $('#cla-TabContent').append(clone); claListLen++; $('#tab-list').append($('')); $('#cla' + tabID + '-tab').tab('show'); break; case "Metafore": tabID++; $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Metafore - non ancora implementata
')); claListLen++; $('#tab-list').append($('')); $('#cla' + tabID + '-tab').tab('show'); break; case "Dialoghi": tabID++; $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Dialoghi - non ancora implementata
')); claListLen++; $('#tab-list').append($('')); $('#cla' + tabID + '-tab').tab('show'); break; case "Struttura": tabID++; $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Struttura testo - non ancora implementata
')); claListLen++; $('#tab-list').append($('')); $('#cla' + tabID + '-tab').tab('show'); break; default: }; }); // Evento: clausola spostata nella lista $('#sortable1').sortable({ opacity: 0.6, cursor: 'move', update: function(event, ui) { var orderLI = $(this).sortable('toArray'); $.each(orderLI, function(index, tabIDHandle){ tabIDSet = "#" + tabIDHandle.substring(2); $(tabIDSet).attr("data-claOrder", index); }); } }); // Evento: click sul checkbox di attivazione delle clausole $('#cla-TabContent').on('click', '.claAct', function() { var tabIDHandle = $(this).closest('li').attr('id'); var tabIDVal = "#" + tabIDHandle.substring(2); if ($(this).prop('checked')) { $(tabIDVal).attr("data-claActive", 1); $(this).closest('li').find('.clatext').fadeTo( "slow", 1 ); } else { $(tabIDVal).attr("data-claActive", 0); $(this).closest('li').find('.clatext').fadeTo( "slow", 0.6 ); } }); // Evento: click sull'icona di refresh dei radio button $('#cla-TabContent').on('click', '.radioRefresh', function() { fSet = $(this).siblings('fieldset'); if (fSet.find(":checked").length) { radioChecked = fSet.find(":checked")[0]; radioChecked.checked = false; }; }); // Evento: SCELTA CATEGORIA GRAMMATICALE $('#cla-TabContent').on('change', 'select.catgram', function(e) { e.preventDefault(); var tabPaneId = ($(this).closest('.tab-pane').attr("id")); var dettagliBox = $(this).parent().parent().siblings(".dettaglifiltri"); dettagliBox.html(""); containerid = 'dettaglio_' + $(this).parent().parent().parent().attr("id") if (Object.keys(categorie).includes($(this).val())) { var filtro = categorie[$(this).val()] var keys = Object.keys(categorieJson[filtro]) for (key in keys) { var vals = categorieJson[filtro][keys[key]] switch (vals.length) { case 2: var element = $('
'); element.attr('class', ' d-flex flex-nowrap pr-2 mb-1 col-8 form-group form-control justify-content-between'); var rbfieldset = $('
'), flexdiv1 = $('
'), flexdiv2 = $('
'), input1 = $(''), input2 = $(''), label1 = $('
'; // Variabili funzionali var tabID = 0; var claListLen = 0; var removedTabOrder = -1; // Funzione di refresh della lista delle tab delle clausole function refreshTabList(){ var tabs=$("#tab-list li:not(:first)"); var len=0; $(tabs).each(function(){ len++; var claType = $(this).find('a').attr("data-claType"); switch (claType) { case "Grammaticale": textClassType = "text-lida8"; break; case "Sintattico": textClassType = "text-lida9"; break; case "Metafore": textClassType = "text-lida3"; break; case "Dialoghi": textClassType = "text-lida4"; break; case "Struttura": textClassType = "text-lida5"; break; default: textClassType = "text-lida8"; }; $(this).find('a').html('' + iconFilter + '  ' + len + ': ' + claType + '  '); $(this).find('a').attr("data-claType", claType) }); } // Funzione di refresh della lista clausole nella tab query function refreshClaList(){ var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)"); var clausoleText = ""; var len=0; if ($(tabsC).length) { var LItextArray = new Array($(tabsC).length); $(tabsC).each(function(){ len++; checkInsert = '"'; tabIDHandle = "H-" + $(this).attr('id'); claType = $(this).attr('data-claType'); claOrder = $(this).attr('data-claOrder'); claActive = $(this).attr('data-claActive'); if (claActive > 0) { checkInsert = '" checked="checked"'; }; // se una clausola è stata rimossa aggiorno il 'data-claOrder' di quelle successive nella lista, // altrimenti l'array ha elementi undefined: if (removedTabOrder > -1 && claOrder > removedTabOrder) { claOrder--; $(this).attr('data-claOrder',claOrder); }; switch (claType) { case "Grammaticale": graSelect = $(this).find(".catgram"); graText = graSelect[0].options[graSelect[0].selectedIndex].text; claText = len + ". Categoria grammaticale: " + graText + '
'; claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); claSubParList.each(function(){ claSubParType = $(this)[0].type; if (claSubParType == "fieldset" && $(this).find(":checked").length) { //claSubParValue = $(this).find(":checked")[0].value; claSubParId = $(this).find(":checked")[0].id; claSubParText = $(this).find("[for='" + claSubParId + "']")[0].innerText; claText = claText + claSubParText + "; "; }; if (claSubParType == "select-one") { //claSubParValue = $(this)[0].value; claSubParText = $(this)[0].options[$(this)[0].selectedIndex].text; //claText = claText + $(this)[0].title + ": " + claSubParText + "; " claText = claText + claSubParText + "; " }; }); break; case "Sintattico": syntSelect = $(this).find("#synttypes"); syntText = syntSelect[0].options[syntSelect[0].selectedIndex].text; funcSelect = $(this).find("#syntfunc"); funcText = funcSelect[0].options[funcSelect[0].selectedIndex].text; claText = len + ". Tipo sintattico: " + syntText + ';
Livello di subordinazione: ' + funcText break; default: claText = len + ". " + $(this).text(); checkInsert = '" disabled'; }; LItextArray[claOrder] = LIpart1 + tabIDHandle + LIpart2 + claText + LIpart3 + len + checkInsert + LIpart4 + len + LIpart5; }); $.each(LItextArray, function(index, LItext){ clausoleText = clausoleText + LItextArray[index]; }); } else { clausoleText = emptyClaList; tabID = 0; claListLen = 0; }; $('#sortable1').html(clausoleText); $('#sortable1 li').each(function(){ if (! $(this).find(".claAct").prop('checked')) { $(this).find('.clatext').css({ opacity: 0.6 }); }; }); removedTabOrder = -1; } function cloneClaSint(clone,tabID){ var original = document.getElementById("tiposintatticoX"); clone = original.cloneNode(true); clone.setAttribute("id","tiposintattico" + tabID); } });