pubs_bl22.js — 2 KB
File contents
var selectedId = '#pubs2020'; var min = 2008; var max = new Date().getFullYear(); var beamlineId = 'BL22'; var publicationsUrl = "https://public.cells.es/duo-services/publications/"; function changeSelect(){ var selectedYear = $('#year_dropdown option:selected').text(); var pubId = '#pubs' + selectedYear; $(this.selectedId).hide(); $(pubId).show(); this.selectedId = pubId; } function filterBeamlinePublications(data, bl){ filteredPubs = data.filter(function(pub){ return pub.blCode == bl }); return filteredPubs; } function convertJsonToHtml(publications){ var all_pubs_html = ''; var dropdown_html = '<select class="formTabs" id="year_dropdown" class="accordion-dropdpwn" onchange="changeSelect()">'; var iteration = 1; for(var year=this.max; year>=this.min; year--){ // Set dropdown option for current year var html_class = '' if(year === this.min){ html_class = ' firstFormTab selected'; }else if(year === this.max){ html_class = ' lastFormTab'; } // Set the html section for this year all_pubs_html += '<div class="accordion-group"><div class="accordion-body collapse" id="pubs' + year + '"'; if(year !== this.max){ all_pubs_html += style=' style="display: none;"'; } all_pubs_html += '>'; var year_pubs = publications.filter(function(pub){ return pub.year == year }); if(year_pubs.length){ dropdown_html += ' <option class="formTab' + html_class + '" value="#pubs' + year + '" data-parent="#accordion">' + year + '</option>'; } year_pubs.forEach(function(year_pub){ all_pubs_html += '<div class="accordion-inner"> <p><b>' + year_pub.authorsList + '</b>' + '<br><a class="external-link" href="' + year_pub.externalUrl + '" target="_blank" title=""><strong><i>' + year_pub.Title + '</i></strong></a>' + '<br>' + year_pub.blCode + ' - ' + year_pub.blName + '<br><em>' + year_pub.reference + '</em>' + '<br>doi: ' + year_pub.doi + '<br><br></p></div>'; }); all_pubs_html += '</div></div>'; iteration++; } dropdown_html += '</select>'; document.getElementById('loadingPublications').innerHTML = ''; document.getElementById('year_dropdown').innerHTML = dropdown_html; document.getElementById('accordion').innerHTML = all_pubs_html; } $.get( publicationsUrl, '', function(data) { filteredData = filterBeamlinePublications(data, beamlineId); convertJsonToHtml(filteredData); } );