');
+*/
+ var cantiche=["Inferno", "Purgatorio","Paradiso"];
+ var romani = ["I","II","III","IV","V","VI","VII","VIII","IX","X",
+ "XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX",
+ "XXI","XXII","XXIII","XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX",
+ "XXXI","XXXII","XXXIII","XXXIV"];
+ var lisidArray = lisid.split('_')
+/*
+ closeButton.appendTo(buttons);
+ rigaNota.append('
' + cantiche[lisidArray[0]-1] + ", Canto " + romani[lisidArray[1]-1] + ", Verso " + lisidArray[2] + " ");
+ rigaNota.appendTo(commentHeader);
+ buttons.appendTo(commentHeader);
+ commentHeader.appendTo(structGroupCard);
+ structCard.appendTo(structGroupCard);
+ $('#displayinfo').empty();
+ structGroupCard.appendTo($('#displayinfo'));
+*/
+ $('#structHead0').text(cantiche[lisidArray[0]-1] + ", Canto " + romani[lisidArray[1]-1] + ", Verso " + lisidArray[2]);
+ $('#structGroupCard0').attr('style', "display: flex;");
+ $('#infoCard0').attr('style', "display: none;");
+ };
+
+ emptyStructCard = function(){
+ //$('#displayinfo').empty();
+ //$('#displayinfo').append($(emptyInfo))
+ $('#infoCard0').attr('style', "display: flex;");
+ $('#structGroupCard0').attr('style', "display: none;");
+ };
+
+
+ // Funzione di creazione del tab delle clausole grammaticali
+ function addGramCla(sortableId,active,tabID,toExpand){
+ if (active > 0) {
+ var checkInsert = ' checked="checked"';
+ } else {
+ var checkInsert = '';
+ };
+ var claText = "Categoria grammaticale:
";
+ addLIitem(sortableId,tabID,claText,checkInsert,toExpand);
+ var claClone = document.getElementById("tipogrammaticaleN").cloneNode(true);
+ claClone.setAttribute("id","cla" + tabID);
+ claClone.setAttribute("data-claActive", active);
+ claClone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
+ claClone.setAttribute("style", "");
+ $('#claBody' + tabID).append(claClone);
+ // se non cambio l'id della select react non rileva l'evento onchange:
+ $('#cla' + tabID + " #grammtypesN").attr("id","grammtypes" + tabID);
+ $('#cla' + tabID + " #lemma_formaN").attr("id","lemma_forma" + tabID);
+ $('#cla' + tabID + " #queryTextN").attr("id","queryText" + tabID);
+ $('#cla' + tabID + " #opzioni_testoN").attr("id","opzioni_testo" + tabID);
+ $('#cla' + tabID + " #contextDivN").attr("id","contextDiv" + tabID);
+ addClaContext(tabID);
+ }
+
+ // Funzione di creazione delle subclausole grammaticali basate sul valore scelto
+ function addCatgramSubcla(tabPaneId,selectedValue){
+ var dettagliBox = $("#" + tabPaneId + " .dettaglifiltri");
+ dettagliBox.html("");
+ if (Object.keys(categorie).includes(selectedValue)) {
+ var filtro = categorie[selectedValue]
+ var keys = Object.keys(categorieJson[filtro])
+ for (var key in keys) {
+ var vals = categorieJson[filtro][keys[key]]
+ switch (vals.length) {
+ case 2:
+ var element = $('
');
+ element.attr('class', 'd-flex flex-sm-nowrap pr-0 py-0 mb-1 form-group form-control-sm border justify-content-between bg-light');
+ var rbfieldset = $('
');
+ var flexdiv1 = $('
');
+ var flexdiv2 = $('
');
+ var input1 = $('
');
+ var input2 = $('
');
+ var label1 = $('
');
+ var label2 = $('
');
+
+ rbfieldset.attr('id', tabPaneId + keys[key].replace(/\s/g, ''));
+ rbfieldset.attr('class', 'custom-control-inline monMe');
+ flexdiv1.attr('class', 'custom-control custom-radio custom-control-inline m-0 mr-2 pb-0');
+ flexdiv1.attr('style', 'padding-top: 2px!important;');
+ flexdiv2.attr('class', 'custom-control custom-radio custom-control-inline m-0 pb-0');
+ flexdiv2.attr('style', 'padding-top: 2px!important;');
+ input1.attr('class', 'custom-control-input');
+ input2.attr('class', 'custom-control-input');
+ input1.attr('type', 'radio');
+ input2.attr('type', 'radio');
+ input1.attr('id', tabPaneId + vals[0].replace(/\s/g, ''));
+ input2.attr('id', tabPaneId + vals[1].replace(/\s/g, ''));
+ input1.attr('value', vals[0]);
+ input2.attr('value', vals[1]);
+ input1.attr('name', tabPaneId + keys[key]);
+ input2.attr('name', tabPaneId + keys[key]);
+ label1.attr('class', 'custom-control-label form-control-sm custom-control-inline m-0 pl-0 text-muted curPoint');
+ label1.attr('style', 'padding-top: 2px!important;');
+ label2.attr('class', 'custom-control-label form-control-sm custom-control-inline m-0 pl-0 text-muted curPoint');
+ label2.attr('style', 'padding-top: 2px!important;');
+ label1.attr('for', tabPaneId + vals[0].replace(/\s/g, ''));
+ label2.attr('for', tabPaneId + vals[1].replace(/\s/g, ''));
+ label1.append(vals[0]);
+ label2.append(vals[1]);
+
+ input1.appendTo(flexdiv1);
+ input2.appendTo(flexdiv2);
+ label1.appendTo(flexdiv1);
+ label2.appendTo(flexdiv2);
+ flexdiv1.appendTo(rbfieldset);
+ flexdiv2.appendTo(rbfieldset);
+ rbfieldset.appendTo(element);
+ var iconR = $(iconReset);
+ iconR.appendTo(element);
+ element.appendTo(dettagliBox);
+ break;
+ case 1:
+ var element = $('
');
+ //element.attr('class', ' d-flex flex-sm-nowrap pr-2 py-1 mb-1 form-group form-control bg-light');
+ element.attr('class', 'd-flex flex-sm-nowrap form-group form-control-sm border px-2 mb-1 pt-1 pb-0 bg-light');
+ var rbfieldset = $('
');
+ flexdiv1 = $('
');
+ input1 = $('
');
+ label1 = $('
');
+ rbfieldset.attr('id', tabPaneId + keys[key].replace(/\s/g, ''));
+ rbfieldset.attr('class', 'custom-control-inline monMe align-items-center');
+ flexdiv1.attr('class', 'custom-control custom-checkbox custom-control-inline');
+ flexdiv1.attr('style', 'padding-top: 1px!important;');
+ input1.attr('class', 'custom-control-input align-self-center');
+ input1.attr('type', 'checkbox');
+ input1.attr('id', tabPaneId + vals[0].replace(/\s/g, ''));
+ input1.attr('value', vals[0]);
+ input1.attr('name', keys[key]);
+ label1.attr('class', 'custom-control-label form-control-sm custom-control-inline p-0 text-muted curPoint align-self-start');
+ label1.attr('style', 'padding-top: 2px!important;');
+ label1.attr('for', tabPaneId + vals[0].replace(/\s/g, ''));
+ label1.append(vals[0]);
+
+ input1.appendTo(flexdiv1);
+ label1.appendTo(flexdiv1);
+ flexdiv1.appendTo(rbfieldset);
+ rbfieldset.appendTo(element);
+ element.appendTo(dettagliBox);
+ break;
+ default:
+ var element = $('
');
+ element.attr('class', ' form-group p-0 pb-1 m-0');
+ //var select = $('
');
+ var select = $('
');
+ select.attr('id', tabPaneId + keys[key].replace(/\s/g, ''));
+ select.attr('title', keys[key]);
+ select.attr('name', keys[key]);
+ for (var val in vals) {
+ var seloption = $('
');
+ seloption.attr('value', vals[val]);
+ seloption.append(vals[val]);
+ seloption.appendTo(select);
+ }
+ select.appendTo(element);
+ element.appendTo(dettagliBox);
+ }
+ }
+ }
+ if (element) {
+ element.attr('style', "display: block;");
+ element.appendTo(dettagliBox);
+ };
+ }
+
+ // Funzione di creazione del tab delle clausole sintattiche
+ function addSyntCla(sortableId,active,tabID,toExpand){
+ if (active > 0) {
+ var checkInsert = ' checked="checked"';
+ } else {
+ var checkInsert = '';
+ };
+ var claText = "Tipo sintattico:
";
+ addLIitem(sortableId,tabID,claText,checkInsert,toExpand);
+ var claClone = document.getElementById("tiposintatticoN").cloneNode(true);
+ claClone.setAttribute("id","cla" + tabID);
+ claClone.setAttribute("data-claActive",active);
+ claClone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
+ claClone.setAttribute("style", "");
+ $('#claBody' + tabID).append(claClone);
+ $('#cla' + tabID + " #lemma_formaN").attr("id","lemma_forma" + tabID);
+ $('#cla' + tabID + " #queryTextN").attr("id","queryText" + tabID);
+ $('#cla' + tabID + " #opzioni_testoN").attr("id","opzioni_testo" + tabID);
+ $('#cla' + tabID + " #contextDivN").attr("id","contextDiv" + tabID);
+ addClaContext(tabID);
+ }
+
+ // Funzione di creazione del tab delle clausole metafore
+ function addMetaCla(sortableId,active,tabID,toExpand){
+ var checkInsert = ' disabled';
+ //if (active > 0) {
+ // var checkInsert = '" checked="checked"';
+ //} else {
+ // var checkInsert = '"';
+ //};
+ var claText = "Clausola Metafore - non ancora implementata";
+ addLIitem(sortableId,tabID,claText,checkInsert,toExpand);
+ var claClone = document.getElementById("tipometaforaN").cloneNode(true);
+ claClone.setAttribute("id","cla" + tabID);
+ claClone.setAttribute("data-claActive",active);
+ claClone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
+ claClone.setAttribute("style", "");
+ $('#claBody' + tabID).append(claClone);
+ }
+
+ // Funzione di creazione della parte di definizione del contesto delle clausole
+ function addClaContext(tabID){
+ var contClone = document.getElementById("contextTable-xX0").cloneNode(true);
+ contClone.setAttribute("class","row no-gutters px-2 pt-0 pb-2 bg-lida11");
+ contClone = contClone.outerHTML.replace(/xX0/g, "xX" + tabID);
+ contClone = contClone.replace(/-secondary/g, "-success");
+ contClone = contClone.replace(/sel-canto/g, "sel-canto suxess");
+ $("#contextDiv" + tabID).append($(contClone)[0]);
+ resetContext(tabID);
+ $("#selectable-xX" + tabID).selectable({
+ filter: ".sel-canto",
+ selected: function(event, ui) {
+ window["context" + tabID][ui.selected.id.substring(0,1)][ui.selected.id.substring(2)] = 1;
+ var tmpFocusBtn = "#plusBtn" + ui.selected.id.substring(0,1) + "-xX" + tabID;
+ $(tmpFocusBtn).focus();
+ }
+ });
+ };
+
+ // Funzione di creazione del LI delle condizioni logiche
+ function addLogicCond(sortableId,condtype){
+ condListLen++;
+ var cloneLI = document.getElementById("condxX4Xx").cloneNode(true);
+ cloneLI.removeAttribute("style");
+ cloneLI = cloneLI.outerHTML.replace(/xX4Xx/g, condListLen)
+ cloneLI = cloneLI.replace(/xX5Xx/g, condtype)
+ if (condtype == "AND") {
+ cloneLI = cloneLI.replace(/xX6Xx/g, "lida12")
+ } else {
+ cloneLI = cloneLI.replace(/xX6Xx/g, "lida13")
+ }
+ if ($("#li-cla0")[0]) {
+ $("#li-cla0")[0].remove();
+ };
+ $(sortableId).append($(cloneLI)[0]);
+ $("#andOrSelect-" + condListLen).val(condtype);
+ $("#sortable" + condListLen).sortable();
+ $("#sortable" + condListLen).sortable( "option", "appendTo", document.body );
+ $("#sortable" + condListLen).sortable({
+ items: "> li",
+ handle: ".handle",
+ opacity: 0.6,
+ cursor: 'move',
+ update: function() {refreshSortables();}
+ });
+ refreshConnectWith();
+ }
+
+ // Funzione di creazione del LI di una clausola nella lista sortable
+ function addLIitem(sortableId,tabID,claText,checkInsert,toExpand){
+ claListLen++;
+ var cloneLI = document.getElementById("li-claxX1Xx").cloneNode(true);
+ cloneLI.setAttribute("style", "opacity: 0.1;");
+ cloneLI = cloneLI.outerHTML.replace(/xX1Xx/g, tabID)
+ cloneLI = cloneLI.replace(/xX2Xx/g, claText)
+ cloneLI = cloneLI.replace(/xX3Xx"/g, tabID + '" ' + checkInsert)
+ if (checkInsert == ' disabled') {
+ cloneLI = cloneLI.replace(/claCollBtn/g, "claCollBtn " + checkInsert);
+ };
+ $(sortableId).append($(cloneLI)[0]);
+ if (toExpand == 1){
+ $("#claCollapse" + tabID).focus();
+ $("#claCollapse" + tabID).trigger("click");
+ }
+ $("#li-cla" + tabID).fadeTo(1000,1);
+ };
+
+ // Funzione di refresh della lista clausole nella tab principale e del json della query
+ function refreshClaList(){
+ var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value;
+ var qText = $("form #queryText")[0].value;
+ var optText = $("form #opzioni_testo")[0].value;
+ if (qText == "") { //disattivo clausola 0 se il testo e' vuoto
+ var claActive = 0
+ } else {
+ var claActive = 1
+ };
+ queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "opzioni_testo": "' + optText + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
+ queryJson.Clausola0.contesto = JSON.stringify(window.context0);
+ queryJson.unitaRicerca = $("#unitaRicerca")[0].options[$("#unitaRicerca")[0].selectedIndex].value;
+ var tabsContent = $("#sortable0").find(".claLI");
+ if ($(tabsContent).length) {
+ if ($("#li-cla0")[0]) {
+ $("#li-cla0")[0].remove();
+ };
+ $(tabsContent).each(function(){
+ var claIdNum = $(this).attr('id').substr(6);
+ updateClaListItem(claIdNum, "#sortable0");
+ });
+ } else {
+ if (claListLen == 0 && condListLen == 0) {
+ $('#sortable0').html(emptyClaList);
+ queryJson.EsprLogica = "";
+ queryJson.LogicaGui = "";
+ }
+ tabID = 0;
+ };
+ if ($('#sortable0').children("li").length <= 1) {
+ $("#cla-defaultCond").remove();
+ } else {
+ if ($('#cla-defaultCond').length == 0) {
+ $("#cla-list-row").prepend($(defaultCond));
+ }
+ };
+ }
+
+ // Funzione di creazione del LI nella lista delle clausole nel tab principale, aggiunta della clausola nel JSON
+ function updateClaListItem(claIdNum, sortableId){
+ var claText = '';
+ var termText = '';
+ var checkInsert = '';
+ var claId = "cla" + claIdNum;
+ var claListItemId = "li-cla" + claIdNum;
+ var claType = $("#" + claId).attr('data-claType');
+ var claActive = $("#" + claId).attr('data-claActive');
+ if (claActive > 0) {
+ checkInsert = ' checked="checked"';
+ };
+ switch (claType) {
+ case "Grammaticale":
+ var l_f = $("form #lemma_forma" + claIdNum)[0].options[$("form #lemma_forma" + claIdNum)[0].selectedIndex].value;
+ var l_f_t = $("form #lemma_forma" + claIdNum)[0].options[$("form #lemma_forma" + claIdNum)[0].selectedIndex].text;
+ var qText = $("form #queryText" + claIdNum)[0].value;
+ var optText = $("form #opzioni_testo" + claIdNum)[0].value;
+ var optText_t = $("form #opzioni_testo" + claIdNum)[0].options[$("form #opzioni_testo" + claIdNum)[0].selectedIndex].text;
+ if (qText != "") {
+ termText = l_f_t + '
' + qText + ' ' + optText_t + '.
';
+ };
+ var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "opzioni_testo": "' + optText + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"';
+ var gramSelect = $("#" + claId).find(".catgram");
+ var contextText = $("#contextText-xX" + claIdNum).text();
+ claText = termText + "Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text;
+ jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"';
+ var claSubParList = $("#" + claId).children(".dettaglifiltri").find("select, fieldset");
+ claSubParList.each(function(){
+ var claSubParType = $(this)[0].type;
+ if (claSubParType == "fieldset" && $(this).find(":checked").length) {
+ var claSubParName = $(this).find(":checked")[0].name;
+ if (claSubParName.startsWith(claId)) {
+ claSubParName = claSubParName.replace(claId,'');
+ }
+ claText = claText + "; " + $(this).find(":checked")[0].defaultValue;
+ jsonTextToParse = jsonTextToParse + ', "' + claSubParName + '": "' + $(this).find(":checked")[0].value + '"';
+ };
+ if (claSubParType == "select-one" && $(this)[0].selectedIndex != 0) {
+ claText = claText + "; " + $(this)[0].options[$(this)[0].selectedIndex].text;
+ jsonTextToParse = jsonTextToParse + ', "' + $(this)[0].name + '": "' + $(this)[0].options[$(this)[0].selectedIndex].value + '"';
+ };
+ });
+ claText = claText + '.
Contesto: ' + contextText;
+ break;
+ case "Sintattico":
+ var l_f = $("form #lemma_forma" + claIdNum)[0].options[$("form #lemma_forma" + claIdNum)[0].selectedIndex].value;
+ var l_f_t = $("form #lemma_forma" + claIdNum)[0].options[$("form #lemma_forma" + claIdNum)[0].selectedIndex].text;
+ var qText = $("form #queryText" + claIdNum)[0].value;
+ var optText = $("form #opzioni_testo" + claIdNum)[0].value;
+ var optText_t = $("form #opzioni_testo" + claIdNum)[0].options[$("form #opzioni_testo" + claIdNum)[0].selectedIndex].text;
+ if (qText != "") {
+ termText = l_f_t + '
' + qText + ' ' + optText_t + '.
';
+ };
+ var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "opzioni_testo": "' + optText + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"';
+ var syntSelect = $("#" + claId).find("#synttypes");
+ var funcSelect = $("#" + claId).find("#syntfunc");
+ var contextText = $("#contextText-xX" + claIdNum).text();
+ claText = termText + "Tipo sintattico: " + syntSelect[0].options[syntSelect[0].selectedIndex].text + ';
Livello di subordinazione: ' + funcSelect[0].options[funcSelect[0].selectedIndex].text + '.
Contesto: ' + contextText;
+ jsonTextToParse = jsonTextToParse + ', "' + syntSelect.attr('name') + '": "' + syntSelect[0].options[syntSelect[0].selectedIndex].value + '", "' + funcSelect.attr('name') + '": "' + funcSelect[0].options[funcSelect[0].selectedIndex].value + '"';
+ break;
+ default:
+ claText = $("#" + claListItemId + " .clatext").text();
+ checkInsert = ' disabled';
+ var jsonTextToParse = '{"queryText": "", "lemma_forma": "", "opzioni_testo": "", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"';
+ };
+ if ($("#" + claListItemId)[0]) {
+ $("#" + claListItemId + " .clatext").replaceWith('
' + claText + ' ');
+ } else {
+ addLIitem(sortableId,claIdNum,claText,checkInsert,0);
+ };
+ queryJson["Clausola" + claIdNum] = JSON.parse(jsonTextToParse + '}');
+ queryJson["Clausola" + claIdNum].contesto = JSON.stringify(window["context" + claIdNum]);
+ };
+
+ // Funzione di refresh dei placeholders e attivazione/disattivazione bottoni nelle liste sortable
+ function refreshSortables(){
+ $("#sortable0").children(".claLI").each(function() {
+ if ($(this).find("input")[0].checked){
+ $(this).find('.clatext').css({ opacity: 1 });
+ };
+ if ($(this).find("input")[0].checked == false){
+ $(this).find('.clatext').css({ opacity: 0.6 });
+ };
+ });
+ $("#cla-TabContent .ui-sortable:not(:first)").each(function() {
+ var sortableID = $(this)[0].id;
+ var placeholderID = "#placeholderSort" + sortableID.slice(-1);
+ var iconBtn = $(this).find(".iconClClass")[0];
+ var iconDiv = $(iconBtn).parent()[0];
+ var activeUL = $(this).children("li").children("ul").length;
+ var activeLI = 0;
+ var inactiveLI = 0;
+ var condLIplaceholder = "";
+ $(this).children("li .claLI").each(function() {
+ if ($(this).find("input")[0].checked){
+ activeLI++;
+ $(this).find('.clatext').css({ opacity: 1 });
+ };
+ if ($(this).find("input")[0].checked == false){
+ inactiveLI++;
+ $(this).find('.clatext').css({ opacity: 0.6 });
+ };
+ });
+ switch (activeLI + activeUL) {
+ case 0:
+ if ($(placeholderID).length) {
+
+ $(placeholderID).fadeOut(300, function(){
+ if (inactiveLI > 0){
+ $(placeholderID).text(condLIplaceholderText2d);
+ } else {
+ $(placeholderID).text(condLIplaceholderText2);
+ };
+ $(placeholderID).fadeTo(100, 0.9).fadeTo(300, 0.6);
+ });
+
+ } else {
+ if (inactiveLI > 0){
+ condLIplaceholder = condLIplaceholderPart1 + sortableID.slice(-1) + condLIplaceholderPart2 + condLIplaceholderText2d + '';
+ } else {
+ condLIplaceholder = condLIplaceholderPart1 + sortableID.slice(-1) + condLIplaceholderPart2 + condLIplaceholderText2 + '';
+ }
+ //$("#" + sortableID).append(condLIplaceholder).hide().fadeIn(300);
+ $("#" + sortableID).append(function(){
+ return $(condLIplaceholder).hide();
+ });
+ $(placeholderID).fadeTo(100, 0.9).fadeTo(300, 0.6);
+
+ };
+ if (inactiveLI == 0){
+ $(iconBtn).attr("class","btn btn-sm btn-outline-success iconClClass removeCond text-success border rounded px-1 pb-0");
+ $(iconBtn).prop("disabled", false);
+ $(iconDiv).attr("class","col-md-auto p-0 mr-2 mt-0 text-right text-success");
+ };
+ break;
+ case 1:
+ if ($(placeholderID).length) {
+ $(placeholderID).fadeOut(300, function(){
+ if (inactiveLI > 0){
+ $(placeholderID).text(condLIplaceholderText1d);
+ } else {
+ $(placeholderID).text(condLIplaceholderText1);
+ };
+ $(placeholderID).fadeTo(100, 0.9).fadeTo(300, 0.6);
+ });
+ } else {
+ if (inactiveLI > 0){
+ condLIplaceholder = condLIplaceholderPart1 + sortableID.slice(-1) + condLIplaceholderPart2 + condLIplaceholderText1d + '';
+ } else {
+ condLIplaceholder = condLIplaceholderPart1 + sortableID.slice(-1) + condLIplaceholderPart2 + condLIplaceholderText1 + '';
+ }
+ //$("#" + sortableID).append(condLIplaceholder).hide().fadeIn(300);
+ $("#" + sortableID).append(function(){
+ return $(condLIplaceholder).hide();
+ });
+ $(placeholderID).fadeTo(100, 0.9).fadeTo(300, 0.6);
+ };
+ $(iconBtn).attr("class","btn btn-sm iconClClass NOremoveCond text-muted border rounded px-1 pb-0");
+ $(iconBtn).prop("disabled", true);
+ $(iconDiv).attr("class","col-md-auto p-0 mr-2 mt-0 text-right text-muted");
+ break;
+ case 2:
+ if ($(placeholderID).length) {
+ $(placeholderID).fadeOut(300, function(){
+ $(placeholderID).remove();
+ });
+ //$(placeholderID).remove();
+ };
+ $(iconBtn).attr("class","btn btn-sm iconClClass NOremoveCond text-muted border rounded px-1 pb-0");
+ $(iconBtn).prop("disabled", true);
+ $(iconDiv).attr("class","col-md-auto p-0 mr-2 mt-0 text-right text-muted");
+ break;
+ default:
+ if ($(placeholderID).length) {
+ $(placeholderID).fadeOut(300, function(){
+ $(placeholderID).remove();
+ });
+ //$(placeholderID).remove();
+ };
+ };
+ });
+ logicExprString = parseCond("#sortable0", "AND", 0);
+ guiLogicString = parseCond("#sortable0", "AND", 1);
+ queryJson.EsprLogica = logicExprString.split(' ');
+ queryJson.LogicaGui = guiLogicString.split(' ');
+ };
+
+ // Funzione di refresh dei collegamenti tra elementi sortable
+ function refreshConnectWith(){
+ for (var i=0; i <= condListLen; i++) {
+ var cw = "";
+ for (var j=0; j <= condListLen; j++) {
+ if (i != j) {
+ cw = cw + "#sortable" + j + ", ";
+ };
+ $( "#sortable" + i ).sortable( "option", "connectWith", cw.slice(0, -2) );
+ };
+ };
+ };
+
+ // Funzione usata da resizable
+ function setWidthInPercent(element) {
+ var percentageWidth = (element.width() / element.parent().width()) * 100;
+ element.width(percentageWidth + '%');
+ };
+
+
+ // Funzione di parsing delle clausole e delle condizioni logiche
+ function parseCond(sortableList, condType, forGui){
+ var condText = "";
+ var items = $(sortableList).children("li");
+ var itemsText = [];
+ $(items).each(function() {
+ if ($(this).hasClass("condLI-AND")) {
+ var andID = "#" + $(this).children("ul").attr("id");
+ var andText = parseCond(andID, "AND", forGui);
+ if (andText.length){
+ itemsText.push(andText);
+ };
+ };
+ if ($(this).hasClass("condLI-OR")) {
+ var orID = "#" + $(this).children("ul").attr("id");
+ var orText = parseCond(orID, "OR", forGui);
+ if (orText.length){
+ itemsText.push(orText);
+ };
+ };
+ if ($(this).hasClass("claLI")) {
+ var claNum = "Clausola" + $(this)[0].id.substr(6);
+ if (forGui || ($(this).find("input")[0].checked == true)){
+ itemsText.push(claNum);
+ };
+ };
+ });
+ var iTlen = itemsText.length;
+ switch (iTlen) {
+ case 0:
+ break;
+ case 1:
+ if (forGui) {
+ condText = "( " + condType + " " + itemsText[0] + " )";
+ } else {
+ condText += itemsText[0];
+ }
+ break;
+ default:
+ condText = "( " + condType + " ";
+ for (let i = 0; i < iTlen; i++) {
+ condText += itemsText[i] + " ";
+ }
+ condText += ")";
+ };
+ return condText;
+ };
+
+ function hideContextCanti(claIdNum) {
+ $('#selectable-xX' + claIdNum + " .ui-selected").each(function() {
+ $(this).attr('style', "display: none;");
+ $(this).removeClass( "ui-selected" )
+ });
+ };
+
+ function makeUpGui(queryJson) {
+ // 1. verifica json legit --> TO DO
+ // -------------------
+ // Pulizia ricerca avanzata:
+ resetAdvGui();
+ // Imposta checkbox: .attr("checked", true)
+ if (queryJson["QueryAvanzata"] == 1) {
+ $("#cla-Advanced").attr('style', "display: block;");
+ $("#searchToggle").prop("checked", true);
+ } else {
+ $("#cla-Advanced").attr('style', "display: none;");
+ $("#searchToggle").prop("checked", false);
+ };
+ // Rigenerazione Clausola0:
+ if (queryJson["Clausola0"].Attiva) {
+ $("#queryText").val(queryJson["Clausola0"].queryText);
+ $("#opzioni_testo").val(queryJson["Clausola0"].opzioni_testo);
+ var qText = queryJson["Clausola0"].queryText;
+ if (qText !== null && qText !== '') {qText = ' "' + qText + '"';}
+ setLemmaForma(qText,queryJson["Clausola0"].lemma_forma);
+ resetContext(0);
+ window.context0 = JSON.parse(queryJson.Clausola0.contesto);
+ parseContext(0);
+ };
+ $("#unitaRicerca").val(queryJson.unitaRicerca);
+ // Generazione lista clausole e condizioni con elementi padre:
+ guiLogicString = queryJson.LogicaGui;
+ var clau2Make = "";
+ var claParent = []; // array di coppie [elemento, elemento padre]
+ var treeLevel = []; // pila di elementi padre
+ var condNum = 0;
+ for (var i=0; i < guiLogicString.length; i++) {
+ switch (guiLogicString[i]) {
+ case "(":
+ break;
+ case ")":
+ treeLevel.pop();
+ break;
+ case "OR":
+ claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
+ treeLevel.push("#sortable" + ++condNum);
+ break;
+ case "AND":
+ if (i > 1) {
+ claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
+ treeLevel.push("#sortable" + ++condNum);
+ } else {
+ treeLevel.push("#sortable0");
+ };
+ break;
+ default:
+ claParent.push([guiLogicString[i].replace("Clausola", ""), treeLevel[treeLevel.length - 1]]);
+ };
+ };
+ $(claParent).each(function(){
+ var itm = $(this)[0]
+ if ($(this)[0] == "OR" || $(this)[0] == "AND") {
+ addLogicCond($(this)[1],$(this)[0]);
+ }
+ if (itm != "OR" && itm != "AND") {
+ clau2Make = queryJson["Clausola" + itm].TipoClausola;
+ active = queryJson["Clausola" + itm].Attiva
+ tabID++;
+ switch (clau2Make) {
+ case "Grammaticale":
+ selectedValue = queryJson["Clausola" + itm].typeGramm0;
+ addGramCla($(this)[1],active,tabID,0);
+ $("#lemma_forma" + tabID).val(queryJson["Clausola" + itm].lemma_forma);
+ $("#queryText" + tabID).val(queryJson["Clausola" + itm].queryText);
+ $("#opzioni_testo" + tabID).val(queryJson["Clausola" + itm].opzioni_testo);
+ if (selectedValue != "all") {
+ $("#grammtypes" + tabID).val(selectedValue);
+ addCatgramSubcla("cla" + tabID, selectedValue);
+ var ks = Object.keys(queryJson["Clausola" + itm]);
+ for (var j = 6; j < ks.length - 1; j++) {
+ var melID = "cla" + tabID + ks[j];
+ var melement = document.getElementById(melID);
+ switch (melement.type) {
+ case "fieldset":
+ var sval = queryJson["Clausola" + itm][ks[j]]
+ $("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked", true);
+ break;
+ case "select-one":
+ melement.value = ([queryJson["Clausola" + itm][ks[j]]])
+ break;
+ default:
+ };
+ };
+ };
+ window["context" + tabID] = JSON.parse(queryJson["Clausola" + itm].contesto);
+ parseContext(tabID);
+ break;
+ case "Sintattico":
+ addSyntCla($(this)[1],active,tabID,0);
+ $("#lemma_forma" + tabID).val(queryJson["Clausola" + itm].lemma_forma);
+ $("#queryText" + tabID).val(queryJson["Clausola" + itm].queryText);
+ $("#opzioni_testo" + tabID).val(queryJson["Clausola" + itm].opzioni_testo);
+ if (queryJson["Clausola" + itm].typeSyntax0 != ".+") {
+ $("#cla" + tabID + " #synttypes").val(queryJson["Clausola" + itm].typeSyntax0);
+ }
+ if (queryJson["Clausola" + itm].functionSyntax != ".+") {
+ $("#cla" + tabID + " #syntfunc").val(queryJson["Clausola" + itm].functionSyntax);
+ }
+ window["context" + tabID] = JSON.parse(queryJson["Clausola" + itm].contesto);
+ parseContext(tabID);
+ break;
+ case "Metafora":
+ addMetaCla($(this)[1],active,tabID,0);
+ break;
+ default:
+ };
+ };
+ });
+ refreshClaList();
+ refreshSortables();
+ };
+
+ function resetSimpleGui() {
+ $('#queryText').val("");
+ setLemmaForma("","forma");
+ $('#opzioni_testo').val("parola");
+ resetContext(0);
+ };
+
+ function setLemmaForma(qText,newSelection) {
+ var newOptions = {['La forma' + qText]: 'forma', ['Il lemma' + qText]: 'lemma', ['Il testo' + qText]: 'testo'};
+ $("#lemma_forma").empty();
+ $.each(newOptions, function(key,value) {
+ $("#lemma_forma").append($("
").attr("value", value).text(key));
+ });
+ $("#lemma_forma").val(newSelection);
+ };
+
+ function resetContext(claIdNum) {
+ $('#selectable-xX' + claIdNum + " .ui-selectee").each(function() {
+ $(this).attr('style', "line-height: 1.2em");
+ });
+ $('#selectable-xX' + claIdNum + " .ui-selected").removeClass( "ui-selected" )
+ $('#selectable-xX' + claIdNum + ' .sel-canti-intro').each(function() {
+ $(this).text("Seleziona i canti:")
+ });;
+ $("#contextText-xX" + claIdNum).html("Tutta l'opera.");
+ window["context" + claIdNum] = JSON.parse(JSON.stringify(contextEmpty));
+ $('#selectable-xX' + claIdNum + " .show").removeClass("show");
+ };
+
+ function resetAdvGui() {
+ var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)");
+ if ($(tabsContent).length) {
+ var claIdNum = '';
+ $(tabsContent).each(function(){
+ claIdNum = $(this)[0].id.substring(3);
+ delete window["context" + claIdNum];
+ $(this).remove();
+ });
+ };
+ claListLen = 0;
+ condListLen = 0;
+ tabID = 0;
+ $('#sortable0').html(emptyClaList);
+ };
+
+ function parseContext(claIdNum) {
+ var context = window["context" + claIdNum];
+ var contextStringParts = ["","",""];
+ var contextString = [];
+ var rangeHolderS = 0;
+ var rangeHolderE = -1;
+ var lastElem = "";
+ var totCan = 0;
+ for (var i=0; i < 3; i++) {
+ for (var j=0; j <= context[i].length; j++) {
+ if (context[i][j] == 1) {
+ if (j == (rangeHolderE+1)) {
+ rangeHolderE++;
+ } else {
+ rangeHolderS = j;
+ rangeHolderE = j;
+ };
+ totCan++;
+ } else {
+ if (rangeHolderE >= 0) {
+ if ( rangeHolderS == rangeHolderE) {
+ lastElem = (rangeHolderE+1);
+ } else {
+ lastElem = (rangeHolderS+1) + "-" + (rangeHolderE+1);
+ };
+ rangeHolderE = -1;
+ };
+ };
+ if (lastElem != "") {
+ if (contextStringParts[i] == "") {
+ contextStringParts[i] = " " + canticheList[i] + " [" + lastElem;
+ } else {
+ contextStringParts[i] = contextStringParts[i] + "," + lastElem;
+ };
+ lastElem = "";
+ };
+ };
+ rangeHolderS = 0;
+ rangeHolderE = -1;
+ if (contextStringParts[i] != "") {
+ contextStringParts[i] = contextStringParts[i] + "]"
+ contextString.push(contextStringParts[i]);
+ }
+ };
+ if ((contextString.toString() != "") && (totCan < 100)) {
+ $("#contextText-xX" + claIdNum).html(contextString.toString()+".");
+ } else {
+ resetContext(claIdNum)
+ }
+ };
+
+ function managePage() {
+ if (currPage == 0){
+ numeroPagine = Math.ceil(numeroContesti/nRisultatiPerPag);
+ $("#paginaLista option").remove();
+ for (let i = 1; i <= numeroPagine; i++) {
+ $('#paginaLista').append(`
${i+'/'+numeroPagine} `);
+ };
+ $("#pagPrecedente").addClass("disabled");
+ if (numeroPagine > 1) {
+ $("#pagSuccessiva").removeClass("disabled")
+ } else {
+ $("#pagSuccessiva").addClass("disabled")
+ };
+ currPage = 1;
+ } else {
+ if ((currPage == 1) && (currPage == numeroPagine)) {
+ $("#pagPrecedente").addClass("disabled")
+ $("#pagSuccessiva").addClass("disabled")
+ } else {
+ if (currPage == 1) {
+ $("#pagPrecedente").addClass("disabled")
+ $("#pagSuccessiva").removeClass("disabled")
+ } else {
+ if (currPage == numeroPagine) {
+ $("#pagPrecedente").removeClass("disabled")
+ $("#pagSuccessiva").addClass("disabled")
+ } else {
+ $("#pagPrecedente").removeClass("disabled")
+ $("#pagSuccessiva").removeClass("disabled")
+ }
+ }
+ };
+ };
+ $.manageResultList((currPage-1)*nRisultatiPerPag, nRisultatiPerPag);
+ if (latestPhraseId != "") {
+ document.getElementById(latestPhraseId).scrollIntoView({
+ behavior: "smooth",
+ });
+ latestPhraseId = "";
+ }
+ };
+
+ function incSize(currentSize, incr, min, max) {
+ fSize = Math.max((parseFloat(currentSize) + incr) % max, min);
+ return (fSize) + 'px';
+ };
+
+ function setStyle(newStyle, fadeDuration = 700) {
+ if (newStyle != currStyle) {
+ var bgImgEl = document.createElement("IMG");
+ bgImgEl.id = "bgImg";
+ currStyle = newStyle;
+ switch (newStyle) {
+ case "style1":
+ $("body").fadeOut(fadeDuration, function() {
+ bgImgEl.src = bgImgUrl1;
+ $("#style1-Boot").prop('disabled', false);
+ $("#style1-Custom").prop('disabled', false);
+ $("#style2-Boot").prop('disabled', true);
+ $("#style2-Custom").prop('disabled', true);
+ $("body").fadeIn(fadeDuration);
+ });
+ break;
+ case "style2":
+ $("body").fadeOut(fadeDuration, function() {
+ bgImgEl.src = bgImgUrl2;
+ $("#style2-Boot").prop('disabled', false);
+ $("#style2-Custom").prop('disabled', false);
+ $("#style1-Boot").prop('disabled', true);
+ $("#style1-Custom").prop('disabled', true);
+ $("body").fadeIn(fadeDuration);
+ });
+ break;
+ default:
+ };
+ $('#bgImg').replaceWith(bgImgEl);
+ drawMinimap(currentMinimap, false, 0);
+ Cookies.set('LiDa_style', newStyle); };
+ };
+
+
+});
+
+$(window).on('load', function() {
+ var cantoHeightToSet = $("body")[0].clientHeight*cssCantoHeight;
+ var maxCantoHeightToSet = $("body")[0].clientHeight*cssTableMainHeight-110; // 63 padding top + 47 margine bottom
+ $(visCantoClass).css("max-height", maxCantoHeightToSet);
+ $(visCantoClass).css("height", cantoHeightToSet);
+ $(displayCantoId).css("max-height", maxCantoHeightToSet);
+ $(displayCantoId).css("height", cantoHeightToSet);
+ var bgImgEl = document.createElement("IMG");
+ bgImgEl.id = "bgImg";
+ switch (currStyle) {
+ case "style1":
+ bgImgEl.src = bgImgUrl1;
+ break;
+ case "style2":
+ bgImgEl.src = bgImgUrl2;
+ break;
+ default:
+ };
+ $('#bgImg').replaceWith(bgImgEl);
+});
+