1"use strict"; 2import { RepoRubrica } from "../repository/repo_rubrica.js"; 3import { RepoStruttura } from "../repository/repo_struttura.js"; 4import { OnlyJsTree } from "/cdn/onlyjstree/0.2.2/dist/js/onlyJsTree.js"; 5 6function FormRicercaStrutturaPresenter(util, defaultPresenter, formRicercaPresenter, langSelector) { 7 var repoRubrica = new RepoRubrica(util); 8 var repoStruttura = new RepoStruttura(util); 9 var common_util = util; 10 var onlyJsTree; 11 var options; 12 var strutture = []; 13 14 15 function creaSchedaContattoStruttura(item, bShowLinkPesonaleAfferente, bShowSottoStrutture, bShowBriciolePane) { 16 if (bShowLinkPesonaleAfferente == null) bShowLinkPesonaleAfferente = true; 17 if (item.livello<=2) 18 bShowLinkPesonaleAfferente=false; 19 if (bShowSottoStrutture == null) bShowSottoStrutture = true; 20 if (bShowBriciolePane == null) bShowBriciolePane = true; 21 if (item.descrizione) { 22 var el = document.createElement("div"); 23 el.classList.add("card-wrapper", "card-space"); 24 var cardbg = document.createElement("div"); 25 cardbg.classList.add("card", "card-bg"); 26 var cardbody = document.createElement("div"); 27 cardbody.classList.add("card-body"); 28 var emailUgov = null; 29 if (item.emailUgov) { 30 if (!item.emailRubrica || (item.emailRubrica && item.emailRubrica != item.emailUgov)) { 31 emailUgov = item.emailUgov; 32 } 33 } 34 var responsabile = ''; 35 if (item.cognomeResponsabile && item.nomeResponsabile && item.descrizionePosizione) 36 responsabile += '<br>' + getBloccoResponsabile(item); 37 var link_pa = ""; 38 var briciole=`<h3 class="card-title h5 text-primary">${item.descrizione}</h3>`; 39 if (bShowBriciolePane){ 40 briciole=`<h3 class="card-title h5 text-primary">${getBriciolePaneStruttura(item)}</h3>`; 41 } 42 if (bShowLinkPesonaleAfferente) 43 link_pa = `<a class="link-personale-afferente" data-id="${item.id}" href="#"> 44 <span class="text" data-translate="personale_afferente_struttura">${langSelector.getTranslatedText("rubr.personale_afferente_struttura")}</span> 45 </a> `; 46 cardbody.innerHTML = ` 47 ${briciole} 48 <ul> 49 ${item.tel1 ? '<li><a href="tel:' + item.tel1 + '">' + item.tel1 + '</a></li>' : ''} 50 ${item.tel2 ? '<li><a href="tel:' + item.tel2 + '">' + item.tel2 + '</a></li>' : ''} 51 ${item.email1 ? '<li><a href="mailto:' + item.email1 + '">' + item.email1 + '</a></li>' : ''} 52 ${item.email2 ? '<li><a href="mailto:' + item.email2 + '">' + item.email2 + '</a></li>' : ''} 53 ${item.pec ? '<li><a href="mailto:' + item.pec + '">' + item.pec + '</a></li>' : ''} 54 </ul> 55 ${responsabile} 56 ${link_pa} 57 `; 58 if (bShowSottoStrutture) { 59 var sottostrutture = document.createElement("div"); 60 if (item.childs.length > 0) 61 sottostrutture.innerHTML = `<br><span translate="lista_servizi_uffici">${langSelector.getTranslatedText("rubr.lista_servizi_uffici")} </span>`; 62 for (var s of item.childs) { 63 sottostrutture.appendChild(creaSchedaContattoStruttura(s, true, false, false)); 64 } 65 cardbody.appendChild(sottostrutture); 66 } 67 cardbg.appendChild(cardbody); 68 el.appendChild(cardbg); 69 return el; 70 } 71 else { 72 return null; 73 } 74 } 75 76 function getBriciolePaneStruttura(struttura) { 77 var bIsFirst = true; 78 var divdropdown = document.createElement('div'); 79 divdropdown.classList.add("dropdown", "dropup", "text-left"); 80 var ul = document.createElement('ul'); 81 ul.classList.add("link-list"); 82 var spacer = ""; 83 for (var s of struttura.parents) { 84 var li = document.createElement("li"); 85 if (bIsFirst) 86 bIsFirst = false;
87 else { 88 li.innerHTML = `<a class="dropdown-item btn list-item briciola-struttura text-start" role="button" data-id="${s.idStruttura}">${spacer}<svg class="icon"><use href="${bootstrap_univpm_urls.sprites}#it-chevron-right"></use></svg>${s.descrizione}</a>`; 89 ul.appendChild(li); 90 spacer += " "; 91 } 92 } 93 divdropdown.innerHTML = ` 94 <a class="d-block list-item btn btn-dropdown dropdown-toggle text-start" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-id="${struttura.idStruttura}"> 95 ${struttura.descrizione} 96 <svg class="icon-expand icon icon-sm icon-primary"><use href="${bootstrap_univpm_urls.sprites}#it-expand"></use></svg> 97 </a> 98 <div class="dropdown-menu" aria-labelledby="dropdownMenuDropup"> 99 <div class="link-list-wrapper"> 100 ${ul.outerHTML} 101 </div> 102 </div> 103 `; 104 return divdropdown.outerHTML; 105 } 106 107 108 function getBloccoResponsabile(struttura) { 109 return ` 110 <p class="card-subtitle h6">${defaultPresenter.getDescrizionePosizione(struttura.descrizionePosizione)}:</p> 111 <p class="card-subtitle h6"> 112 <a class="link-responsabile" data-id="${struttura.id}" data-cognome="${struttura.cognomeResponsabile}" data-nome="${struttura.nomeResponsabile}" href="#"> 113 <span class="text">${struttura.cognomeResponsabile} ${struttura.nomeResponsabile}</span> 114 </a> 115 </p>`; 116 } 117 118 119 120 function loadAlberoStrutture(data) { 121 data = normalizzaAlbero(data); 122 onlyJsTree = new OnlyJsTree(options.alberoID, data, 123 { 124 "data_type": 1, 125 //"data_root": "290002", 126 "data_root": "170001", 127 "click_handler": function (node) { 128 mostraRisultati(node); 129 }, 130 "max_visibile_deep_level": 3, 131 "search_icon": `${bootstrap_univpm_urls.sprites}#it-search`, 132 "item_icon_path_childs": `${bootstrap_univpm_urls.sprites}#it-expand`, 133 "item_icon_path_current": `${bootstrap_univpm_urls.sprites}#it-chevron-right`, 134 "item_icon_path_tree": `${bootstrap_univpm_urls.sprites}#it-share`, 135 default_language: langSelector.getLanguage(), 136 languages: { 137 it: { 138 search_text: "Cerca struttura", 139 search_in_tree_text: "Mostra nell'organigramma", 140 }, 141 en: { 142 search_text: "Search faculty/department", 143 search_in_tree_text: "Show in the organisational chart", 144 } 145 } 146 }); 147 } 148 149 function mostraRisultati(data) { 150 var div = document.querySelector(options.divRisultatiID); 151 defaultPresenter.scrollTo(options.divRisultatiID) 152 div.innerHTML = ''; 153 div.appendChild(creaSchedaContattoStruttura(data, true, true, false)); 154 } 155 156 function normalizzaAlbero(strutture) { 157 var tree = []; 158 var t = {}; 159 t.id = "170001"; 160 t.parent_id = "#"; 161 t.label = "Univpm"; 162 tree.push(t); 163 var i = 0; 164 for (var a of strutture) { 165 t = {}; 166 t.id = a.idStruttura; 167 t.parent_id = a.idStrutturaPadre; 168 t.label = a.descrizione; 169 t.livello = a.livello; 170 t.order = 100; 171 if (a.descrizioneTipo == langSelector.getTranslatedText("rubr.servizio")) { 172 t.order = 10; 173 } 174 else if (a.descrizioneTipo == langSelector.getTranslatedText("rubr.area")) { 175 t.order = 20; 176 } 177 else if (a.descrizioneTipo == langSelector.getTranslatedText("rubr.ufficio")) { 178 t.order = 30; 179 } 180 t = { ...a, ...t } 181 tree.push(t); 182 } 183 return tree; 184 } 185 186 this.getNodeById = function (item_id) { 187 return onlyJsTree.getNodeById(item_id); 188 } 189
190 this.getSchedaContattoStruttura = function (item, bShowLinkPesonaleAfferente) { 191 return creaSchedaContattoStruttura(item, bShowLinkPesonaleAfferente, true, true); 192 } 193 194 this.init = function (opt) { 195 defaultPresenter.startLoader(); 196 options = opt; 197 var div_risultati = document.querySelector(options.divRisultatiID); 198 199 div_risultati.addEventListener('show.bs.collapse', (event) => { 200 event.preventDefault(); 201 var btn = document.querySelector(`button[data-bs-target="#${event.target.id}"]`); 202 btn.innerHTML = `<svg class="icon"> 203 <use href="${bootstrap_univpm_urls.sprites}#it-collapse"></use> 204 </svg>`; 205 }); 206 207 div_risultati.addEventListener('hide.bs.collapse', (event) => { 208 event.preventDefault(); 209 var btn = document.querySelector(`button[data-bs-target="#${event.target.id}"]`); 210 btn.innerHTML = `<svg class="icon"> 211 <use href="${bootstrap_univpm_urls.sprites}#it-expand"></use> 212 </svg>`; 213 }); 214 215 langSelector.setPostLoadAction(function () { 216 onlyJsTree.changeLanguage(langSelector.getLanguage()); 217 }); 218 219 common_util.on(document, 'click', ".link-personale-afferente", (event) => { 220 event.preventDefault(); 221 var item_id = event.target.closest("a").getAttribute("data-id"); 222 defaultPresenter.switchTab(defaultPresenter.TAB_RICERCA_PERSONE); 223 formRicercaPresenter.cerca("", "", item_id, false); 224 //formRicercaPresenter.impostaCampiRicerca("", "", item_id); 225 }); 226 227 common_util.on(document, 'click', ".link-responsabile", (event) => { 228 event.preventDefault(); 229 var item_id = event.target.closest("a").getAttribute("data-id"); 230 var cognome = event.target.closest("a").getAttribute("data-cognome"); 231 var nome = event.target.closest("a").getAttribute("data-nome"); 232 defaultPresenter.switchTab(defaultPresenter.TAB_RICERCA_PERSONE); 233 formRicercaPresenter.cerca(cognome, nome, item_id); 234 //formRicercaPresenter.impostaCampiRicerca(cognome, nome, item_id); 235 }); 236 237 common_util.on(document, 'click', ".briciola-struttura", (event) => { 238 event.preventDefault(); 239 var item_id = event.target.closest("a").getAttribute("data-id"); 240 var node = onlyJsTree.getNodeById(item_id); 241 //formRicercaPresenter.impostaCampiRicerca('', '', item_id); 242 formRicercaPresenter.cerca(null, null, item_id); 243 mostraRisultati(node); 244 }); 245 246 defaultPresenter.stopLoader(); 247 }; 248 249 this.caricaAlberoStrutture = function (data) { 250 defaultPresenter.startLoader(); 251 loadAlberoStrutture(data); 252 defaultPresenter.stopLoader(); 253 } 254} 255 256 257export { FormRicercaStrutturaPresenter }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.