diff --git a/primo-explore/custom/41SLSP_EPF-test/js/fullview/almaviewit.component.js b/primo-explore/custom/41SLSP_EPF-test/js/fullview/almaviewit.component.js index c8e4b93..0c03288 100644 --- a/primo-explore/custom/41SLSP_EPF-test/js/fullview/almaviewit.component.js +++ b/primo-explore/custom/41SLSP_EPF-test/js/fullview/almaviewit.component.js @@ -1,77 +1,87 @@ "use strict"; /* - OBJECTIF: Ajouter le lien vers SWITCH edu-ID. - REMARQUES: contient juste les liens vers SWITCH edu-ID et vers - l'application de changement des code-barres. + OBJECTIF: Ajouter un lien pour rapporter les problèmes d'accès aux + ressources électroniques. Un message d'avertissement s'affiche quand la + la personne n'est pas sur le réseau EPFL */ module.exports = { bindings: {parentCtrl: '<'}, controllerAs: 'ctrl', controller: ['$filter', 'userService', function($filter, userService) { var vm = this; vm.feedbackLink = ''; vm.is_epfl_IP = false; + vm.no_report_link = false; + // not for open access if (vm.parentCtrl.item.pnx.addata.openaccess && vm.parentCtrl.item.pnx.addata.openaccess[0] === 'true') { - vm.nolink = true; + vm.no_report_link = true; } // not for cdi open access if (vm.parentCtrl.item.pnx.addata.oa && vm.parentCtrl.item.pnx.addata.oa[0] === 'free_for_read') { - vm.nolink = true; + vm.no_report_link = true; } - if (!vm.nolink){ + if (!vm.no_report_link){ + + /* Obtient l'adresse ip depuis un service se trouvant dans le + module \js\slsp\epfl_custom_slsp.js */ var userIP = userService.getIP(); - const regex = /128\.17([89])\.(\d{3})\./; - const found = userIP.match(regex); - if (found && (found[1] == '8' || parseInt(found[2])>=128)) { - vm.is_epfl_IP = true; + // Vérification du range EPFL + if (userIP) { + const regex = /128\.17([89])\.(\d{3})\./; + const found = userIP.match(regex); + if (found && (found[1] == '8' || parseInt(found[2])>=128)) { + vm.is_epfl_IP = true; + } } - vm.nolink = false; + // Récupération des métadonnées de la ressource var mmsId = vm.parentCtrl.item.pnx.control.recordid[0]; var title = ''; if (vm.parentCtrl.item.pnx.display.title && vm.parentCtrl.item.pnx.display.title.length > 0) { title = vm.parentCtrl.item.pnx.display.title[0]; } var creationdate = ''; if (vm.parentCtrl.item.pnx.display.creationdate && vm.parentCtrl.item.pnx.display.creationdate.length > 0) { creationdate = vm.parentCtrl.item.pnx.display.creationdate[0]; } var creator = ''; if (vm.parentCtrl.item.pnx.display.creator && vm.parentCtrl.item.pnx.display.creator.length > 0) { creator = vm.parentCtrl.item.pnx.display.creator.join(', '); } var type = ''; if (vm.parentCtrl.item.pnx.display.type && vm.parentCtrl.item.pnx.display.type.length > 0) { type = vm.parentCtrl.item.pnx.display.type[0]; } var identifier = ''; if (vm.parentCtrl.item.pnx.display.identifier && vm.parentCtrl.item.pnx.display.identifier.length > 0) { var ident = vm.parentCtrl.item.pnx.display.identifier[0]; if (ident.indexOf('ISBN') > -1) { identifier = vm.parentCtrl.item.pnx.display.identifier.join(', ').replace(/<\/b>/g, '').replace(//g, ''); } else if (ident.indexOf('ISSN') > -1) { identifier = vm.parentCtrl.item.pnx.display.identifier.join(', ').replace(/<\/b>/g, '').replace(//g, ''); } else if (ident.indexOf('ISBN') > -1) { identifier = 'ISBN: ' + ident.substring(ident.indexOf('$$V') + 3); } else if (ident.indexOf('ISSN') > -1) { identifier = 'ISSN: ' + ident.substring(ident.indexOf('$$V') + 3); } } var userAgent = navigator.userAgent; + // Création de l'objet du message var subject = mmsId + ' - "' + title + '"'; - var body = '** Attached Metadata **\nTitle: ' + title + '\nAuthor: ' + creator + '\nYear: ' + creationdate + '\nType: ' + type + '\nDocId: ' + mmsId + '\nIdentifier: ' + identifier + '\nUSER_AGENT: ' + userAgent + '\nUserIP: ' + userIP + '\nRange EPFL: ' + vm.is_epfl_IP + '\n****\n\n' + $filter('customTranslate')('feedbackLinkMSG') + '\n'; + // Création du corps du message + var body = '** Attached Metadata **\nTitle: ' + title + '\nAuthor: ' + creator + '\nYear: ' + creationdate + '\nType: ' + type + '\nDocId: ' + mmsId + '\nIdentifier: ' + identifier + '\nUser_agent: ' + userAgent + '\nUserIP: ' + userIP + '\nRange EPFL: ' + vm.is_epfl_IP + '\n****\n\n' + $filter('customTranslate')('feedbackLinkMSG') + '\n'; vm.feedbackLink = 'mailto:edoc@epfl.ch' + '?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body) + '&Content-Type=text/html'; } }], - template: `