Last active
June 13, 2024 10:30
-
-
Save timhodson/cfc22d17548a8539bf9bb0808e55868d to your computer and use it in GitHub Desktop.
Primo VE - Talis Aspire Customisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Insert this code into the primo VE customisation folder `js/custom.js` anywhere after the line that reads: | |
// var app = angular.module('viewCustom', ['angularLoad']); | |
// and before the line that reads: | |
// })(); | |
// this code can coexist wth other customisations that you may have for other products. | |
// === begin Talis Aspire Code === | |
// Configuration | |
window.talis_aspire = { | |
/* === You have to set these up! === */ | |
base_url: 'https://mytenancy.rl.talis.com/', // Your Readinglists tenancy base url with a trailing slash | |
mms_id_institution_code: 1234, // The last four digits of your MMS_IDs | |
/* === customise the related lists === */ | |
related_lists_display_label: 'Cited on reading lists:', // Text to display to users | |
/* === customise the boommark this button === */ | |
display_bookmark_this_button: true, // set to false to hide the button | |
bookmark_this_title_attribute: 'bookmark this item to reading lists', // tooltip for the bookmark this button | |
bookmark_this_button_text: 'Send To Reading Lists', // Clickable text for the bookmark this button | |
/* === Don't need to change anything below this comment. === */ | |
// A helper function to loop through all the values to check for the local MMSID | |
checkMMSIDcontainsInstitutionCode: function (mms_id) { | |
// Does it match the format for our local MMSID? | |
// the last four digits reflect your local values | |
var mmsidCheck = new RegExp('^99[0-9]*' + talis_aspire.mms_id_institution_code + '$'); | |
if (mmsidCheck.test(mms_id) == true){ | |
return mms_id; | |
} | |
} | |
} | |
// Whitelisting for Talis Aspire API Requests | |
app.constant('AspireTrustBaseUrl', talis_aspire.base_url).config(['$sceDelegateProvider', 'AspireTrustBaseUrl', function ($sceDelegateProvider, AspireTrustBaseUrl) { | |
var urlWhitelist = $sceDelegateProvider.resourceUrlWhitelist(); | |
urlWhitelist.push(AspireTrustBaseUrl + '**'); | |
$sceDelegateProvider.resourceUrlWhitelist(urlWhitelist); | |
}]); | |
// End of whitelisting | |
// Show bookmark this button | |
// prmBriefResultAfter - After the Title and Author display at the top of the page | |
// prmBriefResultContainerAfter - After all the availability stuff | |
// prmActionContainerAfter - After the 'send to' buttons | |
app.component('prmActionContainerAfter',{ | |
bindings: { parentCtrl: '<' }, | |
controller: 'DisplayBookMarkThisController', | |
template: '<div style="text-align: center;"><button style="display: inline-block; padding: 5px; margin: 5px auto;" ng-click="bookmarkThisClick(mmsid.url)" ng-repeat="mmsid in bookmarkable_mmsids" title="{{mmsid.title}}" class="button"><span>{{mmsid.action_text}}</span></button></div>' | |
}); | |
app.controller('DisplayBookMarkThisController', function ($scope) { | |
if (talis_aspire.display_bookmark_this_button == true) { | |
var mms_id_arr = []; | |
// Loop through all MMS_IDs using our function above. | |
// The last MMSID found that matches will be the one used. | |
$scope.$parent.$ctrl.item.pnx.display.mms.forEach( function (mmsID){ | |
let result = talis_aspire.checkMMSIDcontainsInstitutionCode(mmsID); | |
mms_id_arr.push(result); | |
}); | |
var bookmarkable_mmsids = []; | |
mms_id_arr.forEach(function (theMMSID){ | |
var url = talis_aspire.base_url + 'ui/forms/bookmarklet.html?bibid=' + theMMSID; | |
var title = talis_aspire.bookmark_this_title_attribute | |
var action_text = talis_aspire.bookmark_this_button_text | |
bookmarkable_mmsids.push({url:url, title:title, action_text:action_text}); | |
}); | |
$scope.bookmarkable_mmsids = bookmarkable_mmsids; | |
$scope.bookmarkThisClick = function(url){ | |
window.location.href = url; | |
}; | |
} | |
}); | |
// Show reading lists this item appears on | |
app.component('prmServiceDetailsAfter', { | |
bindings: { parentCtrl: '<' }, | |
controller: 'DisplayAspireListsController', | |
template: '<div ng-show="listsFound != null"><span class="bold text">'+talis_aspire.related_lists_display_label+'</span><ul><li ng-repeat="(url,listname) in listsFound"><a href="{{url}}">{{listname}} </a></li></ul></div>' | |
}); | |
app.controller('DisplayAspireListsController', function ($scope, $http) { | |
// Declare a global variable to hold the MMSID when it comes from the function | |
var mms_id_arr = []; | |
// Loop through all MMS_IDs using our function above. | |
// The last MMSID found that matches will be the one used. | |
$scope.$parent.$ctrl.item.pnx.display.mms.forEach( function (mmsID){ | |
let result = talis_aspire.checkMMSIDcontainsInstitutionCode(mmsID); | |
mms_id_arr.push(result); | |
}); | |
mms_id_arr.forEach(function(theMMSID){ | |
if (typeof(theMMSID) !== 'undefined') { | |
var url = talis_aspire.base_url + 'lcn/' + theMMSID + '/lists.json'; | |
// Make the call to Aspire | |
$http.jsonp(url,{jsonpCallbackParam: 'cb'}) | |
.then(function handleSuccess(response) { | |
$scope.listsFound = response.data; | |
}); | |
} | |
}); | |
}); | |
// === End Talis Aspire Code === |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment