results.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // Oggetto che raccoglie le info necessarie per la pagina
  2. pageInfo = {};
  3. // Inizializzazione della pagina
  4. initPage();
  5. // Def. funzione di inizializzazione
  6. async function initPage(){
  7. pageInfo = await getPageInfo();
  8. updatePage();
  9. }
  10. // Esegue le queries, restituisce un oggetto con tutte le info per completare la pagina
  11. async function getPageInfo(){
  12. var out = {};
  13. try{
  14. out.query = await doJsonQuery(queryLettere, true);
  15. } catch(err){
  16. console.log(err);
  17. }
  18. console.log('out', out)
  19. return out;
  20. }
  21. // Aggiorna la pagina usando l'oggetto-info passato come parametro
  22. function updatePage(){
  23. if(pageInfo.query) {
  24. for (var i=0; i<pageInfo.query.length; i++) {
  25. if(pageInfo.query[i].hasOwnProperty('uri_document')) {
  26. alert("Here");
  27. uri_document = pageInfo.query.uri_document.value;
  28. }
  29. var l = pageInfo.query[i].uri_document.value;
  30. }
  31. var uri_document = "";
  32. var doc = "";
  33. var time_span_from = "";
  34. var time_span_to = "";
  35. var uri_place_from = "";
  36. var place_from = "";
  37. var uri_place_to = "";
  38. var place_to = "";
  39. var EventsTable = "";
  40. if(pageInfo.query.hasOwnProperty('document')) {
  41. doc = pageInfo.query.document.value;
  42. }
  43. if(pageInfo.query.hasOwnProperty('time_span_from')) {
  44. time_span_from = pageInfo.query.time_span_from.value;
  45. }
  46. if(pageInfo.query.hasOwnProperty('time_span_to')) {
  47. time_span_to = pageInfo.query.time_span_to.value;
  48. }
  49. if(pageInfo.query.hasOwnProperty('uri_place_from')) {
  50. uri_place_from = pageInfo.query.uri_place_from.value;
  51. }
  52. if(pageInfo.query.hasOwnProperty('place_from')) {
  53. place_from = pageInfo.query.place_from.value;
  54. }
  55. if(pageInfo.query.hasOwnProperty('uri_place_to')) {
  56. uri_place_to = pageInfo.query.uri_place_to.value;
  57. }
  58. if(pageInfo.query.hasOwnProperty('place_to')) {
  59. place_to = pageInfo.query.place_to.value;
  60. }
  61. EventsTable += '<div class="row">' +
  62. '<div class="col-2">' + doc + '</div>' +
  63. '<div class="col-2">' + time_span_from + '</div>' +
  64. '<div class="col-2">' + time_span_to + '</div>' +
  65. '<div class="col-2">' + place_from + '</div>' +
  66. '<div class="col-4">' + place_to + '</div>' +
  67. '</div>';
  68. document.getElementById("results_table").innerHTML = EventsTable;
  69. }
  70. /*if(pageInfo.query1){
  71. document.getElementById("mittente_id").innerHTML = pageInfo.query1.mittente.value;
  72. //document.getElementById("mittente_btn").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query1.mittente.value));
  73. }
  74. if(pageInfo.query1){
  75. document.getElementById("destinatario_id").innerHTML = pageInfo.query1.destinatario.value;
  76. //document.getElementById("destinatario_btn").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query1.destinatario.value));
  77. }
  78. if(pageInfo.query1){
  79. document.getElementById("imageASPO").innerHTML = createEmbed(pageInfo.query1.subject.value);
  80. }
  81. if(pageInfo.query1){
  82. document.getElementById("luogo_partenza_id").innerHTML = pageInfo.query1.luogo_partenza.value;
  83. document.getElementById("luogo_partenza_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoPartenza.value));
  84. }
  85. if(pageInfo.query1){
  86. document.getElementById("luogo_arrivo_id").innerHTML = pageInfo.query1.luogo_arrivo.value;
  87. document.getElementById("luogo_arrivo_btn").innerHTML = createButton("fa fa-map", "Vedi mappa", "schedaMappa('LUOGO')".replace("LUOGO", pageInfo.query1.uriLuogoArrivo.value));
  88. }
  89. if(pageInfo.query1) document.getElementById("data_partenza_id").innerHTML = pageInfo.query1.data_partenza.value;
  90. if(pageInfo.query1) document.getElementById("data_arrivo_id").innerHTML = pageInfo.query1.data_arrivo.value;
  91. if(pageInfo.descrizione) document.getElementById("descrizione_id").innerHTML = pageInfo.descrizione.descrizione.value;
  92. if(pageInfo.areaLinguistica) document.getElementById("lingua_id").innerHTML = pageInfo.areaLinguistica.lingua.value;
  93. if(pageInfo.areaLinguistica) document.getElementById("area_linguistica_id").innerHTML = pageInfo.areaLinguistica.area_linguistica.value;
  94. if(pageInfo.sigla) document.getElementById("sigla_OVI").innerHTML = pageInfo.sigla.sigla_OVI.value;
  95. if(pageInfo.segnatura){
  96. document.getElementById("segnatura_id").innerHTML = pageInfo.segnatura.segnatura_OVI.value;
  97. document.getElementById("segnatura_btn").innerHTML = createButton("fa fa-link", "Link ASPO", "schedaASPO('SEGN')".replace("SEGN", thisUrlParams.link));
  98. }
  99. if(pageInfo.edizione){
  100. document.getElementById("edizione_id").innerHTML = pageInfo.edizione.edizione.value;
  101. document.getElementById("edizione_btn").innerHTML = createButton("fa fa-comments", "Cita Edizione", "schedaEdizione('EDIZ')".replace("EDIZ", pageInfo.edizione.edizione.value));
  102. }
  103. if(pageInfo.testo) document.getElementById("trascrizione_id").innerHTML = pageInfo.testo.testo_lemmatizzato.value;
  104. //
  105. if(pageInfo.antroponimi && pageInfo.antroponimi.length){
  106. const listaAntroponimi = pageInfo.antroponimi.map(elem => elem.antroponimo.value);
  107. document.getElementById("antroponimi").innerHTML = formatListAsLi(listaAntroponimi);
  108. }
  109. if(pageInfo.toponimi && pageInfo.toponimi.length){
  110. const listaToponimi = pageInfo.toponimi.map(elem => elem.toponimo.value);
  111. document.getElementById("toponimi").innerHTML = formatListAsLi(listaToponimi);
  112. }
  113. if(pageInfo.query2) {
  114. if(pageInfo.query2.hasOwnProperty('mittente')) document.getElementById("mittente_id_ASPO").innerHTML = pageInfo.query2.mittente.value;
  115. if(pageInfo.query2.hasOwnProperty('uriSender')) document.getElementById("mittente_btn_ASPO").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query2.uriSender.value));
  116. if(pageInfo.query2.hasOwnProperty('destinatario')) document.getElementById("destinatario_id_ASPO").innerHTML = pageInfo.query2.destinatario.value;
  117. if(pageInfo.query2.hasOwnProperty('uriReceiver')) document.getElementById("destinatario_btn_ASPO").innerHTML = createButton("fa fa-user", "Scheda persona", "schedaPersona('PERS')".replace("PERS", pageInfo.query2.uriReceiver.value));
  118. if(pageInfo.query2.hasOwnProperty('placeSend')) document.getElementById("luogo_partenza_id_ASPO").innerHTML = pageInfo.query2.placeSend.value;
  119. if(pageInfo.query2.hasOwnProperty('placeReceive')) document.getElementById("luogo_arrivo_id_ASPO").innerHTML = pageInfo.query2.placeReceive.value;
  120. if(pageInfo.query2.hasOwnProperty('timeSpanSend')) document.getElementById("data_partenza_id_ASPO").innerHTML = pageInfo.query2.timeSpanSend.value;
  121. if(pageInfo.query2.hasOwnProperty('timeSpanReceive')) document.getElementById("data_arrivo_id_ASPO").innerHTML = pageInfo.query2.timeSpanReceive.value;
  122. if(pageInfo.query2.hasOwnProperty('material')) document.getElementById("consistenzaASPO").innerHTML = pageInfo.query2.material.value;
  123. if(pageInfo.query2.hasOwnProperty('dimension')) document.getElementById("dimensioneASPO").innerHTML = pageInfo.query2.dimension.value;
  124. if(pageInfo.query2.hasOwnProperty('identifier')) document.getElementById("segnatura_id_ASPO").innerHTML = pageInfo.query2.identifier.value;
  125. if(pageInfo.query2.hasOwnProperty('currentLocation')) document.getElementById("ownerASPO").innerHTML = pageInfo.query2.currentLocation.value;
  126. }
  127. if(pageInfo.sigla){
  128. document.getElementById("evt_button").innerHTML = createButtonEVT(pageInfo.sigla.sigla_OVI.value);
  129. }*/
  130. }
  131. // Mini-utility per formattare liste
  132. function formatListAsLi(thisList){
  133. toRet = "";
  134. thisList.forEach(value => toRet += "<li>" + value + "</li>");
  135. return toRet;
  136. }
  137. // Buttons
  138. function createButton(buttonClass, text, onClickFunction){
  139. htmlCode = '\
  140. <button class="btn btn-default" type="button" onclick="<FUNCTION>">\
  141. <i class="<CLASS>" aria-hidden="true">\
  142. <p class="btn-text"><TEXT></p>\
  143. </i>\
  144. </button>\
  145. '.replace("<CLASS>", buttonClass).replace("<TEXT>", text).replace("<FUNCTION>", onClickFunction);
  146. return htmlCode;
  147. }
  148. function createButtonEVT(sigla){
  149. htmlCode = '\
  150. <button type="button" class="btn btn-secondary" onclick="loadPageEVT(\'<SIGLA>\')">\
  151. Button EVT</button>\
  152. '.replace("<SIGLA>", sigla);
  153. return htmlCode;
  154. }
  155. //<button type="button" class="btn btn-secondary" onclick="loadPageLOD()">Button LOD</button>
  156. function loadPageEVT(sigla)
  157. {
  158. window.location="http://restore.ovi.cnr.it/mockup/evt/#/imageText?p=" + sigla + "_01&el=diplomatic";
  159. }
  160. function createEmbed(link) {
  161. image = link.replace("scheda", "imageView") + "/#main";
  162. htmlCode = '\
  163. <embed id="imageEmb" src="<LINK>"> \
  164. '.replace("<LINK", image);
  165. return htmlCode;
  166. }
  167. function schedaPersona(info){
  168. window.open("Persona.html?link="+info);
  169. }
  170. function schedaMappa(info){
  171. window.open("Luogo.html?link="+info);
  172. }
  173. function schedaASPO(info){
  174. window.open(info);
  175. }
  176. function schedaEdizione(info){
  177. $("#myModal").empty();
  178. $("#myModal").css("display", "block");
  179. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  180. info + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  181. }
  182. function show_OVI(){
  183. document.getElementById("OVI_info").style.display = "block";
  184. document.getElementById("ASPO_info").style.display = "none";
  185. }
  186. function show_ASPO(){
  187. document.getElementById("OVI_info").style.display = "none";
  188. document.getElementById("ASPO_info").style.display = "block";
  189. }
  190. $(document).on("click", ".close", function (ev) {
  191. var link = this.id;
  192. //alert(nome_autore);
  193. //$('#myModal').text("");
  194. $("#myModal").css("display", "none");
  195. });
  196. $(document).on("click", ".hyp", function (ev) {
  197. var baseurl = window.location.origin+window.location.pathname;
  198. let slash = baseurl.lastIndexOf("/");
  199. var type = $(this).val() + '.html';
  200. var link = this.id;
  201. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  202. var link = this.id;
  203. $("#myModal").empty();
  204. $("#myModal").css("display", "block");
  205. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  206. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  207. });
  208. $(document).on("click", ".cit", function (ev) {
  209. var author ="RESTORE. smart access to digital heritage and memory"
  210. var year = new Date().getFullYear()
  211. var today = new Date();
  212. var dd = String(today.getDate()).padStart(2, '0');
  213. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  214. var yyyy = today.getFullYear();
  215. today = dd + '/' + mm + '/' + yyyy;
  216. var baseurl = window.location.origin+window.location.pathname;
  217. let slash = baseurl.lastIndexOf("/");
  218. var type = $(this).val() + '.html';
  219. var link = this.id;
  220. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  221. //alert(nome_autore);
  222. //$('#myModal').text("");
  223. $("#myModal").empty();
  224. $("#myModal").css("display", "block");
  225. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  226. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  227. });
  228. function copyToClipboard(text) {
  229. var sampleTextarea = document.createElement("textarea");
  230. document.body.appendChild(sampleTextarea);
  231. sampleTextarea.value = text; //save main text in it
  232. sampleTextarea.select(); //select textarea contenrs
  233. document.execCommand("copy");
  234. document.body.removeChild(sampleTextarea);
  235. }
  236. function myFunction(){
  237. var copy = document.getElementById("myInput");
  238. copyText = copy.textContent;
  239. copyToClipboard(copyText);
  240. //copyToClipboard(copyText.value);
  241. }