return $q.when();
}
+ service.getRecentPatrons = function() {
+ // avoid getting stuck in a show-recent loop
+ service.showRecent = false;
+
+ if (service.maxRecentPatrons < 1) return $q.when();
+ var patrons =
+ egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
+
+ // Ensure the cached list is no bigger than the current config.
+ // This can happen if the setting changes while logged in.
+ patrons = patrons.slice(0, service.maxRecentPatrons);
+
+ // add home_ou to the list of fleshed fields for recent patrons
+ var fleshFields = egUser.defaultFleshFields.slice(0);
+ fleshFields.push('home_ou');
+
+ var deferred = $q.defer();
+ function getNext() {
+ if (patrons.length == 0) {
+ deferred.resolve();
+ return;
+ }
+ egUser.get(patrons[0], {useFields : fleshFields}).then(
+ function(usr) { // fetch first user
+ deferred.notify(usr);
+ patrons.splice(0, 1); // remove first user from list
+ getNext();
+ }
+ );
+ }
+
+ getNext();
+ return deferred.promise;
+ }
+
+ service.addRecentPatron = function(user_id) {
+ if (service.maxRecentPatrons < 1) return;
+
+ // no need to re-track same user
+ if (service.current && service.current.id() == user_id) return;
+
+ var patrons =
+ egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
+ patrons.splice(0, 0, user_id); // put this user at front
+ patrons.splice(service.maxRecentPatrons, 1); // remove excess
+
+ // remove any other occurrences of this user, which may have been
+ // added before the most recent user.
+ var idx = patrons.indexOf(user_id, 1);
+ if (idx > 0) patrons.splice(idx, 1);
+
+ egCore.hatch.setLoginSessionItem('eg.circ.recent_patrons', patrons);
+ }
+
// sets the primary display user, fetching data as necessary.
service.setPrimary = function(id, user, force) {
var user_id = id ? id : (user ? user.id() : null);
if (!user_id) return $q.reject();
- // when loading a new patron, update the last patron setting
- if (!service.current || service.current.id() != user_id)
- egCore.hatch.setLoginSessionItem('eg.circ.last_patron', user_id);
+ service.addRecentPatron(user_id);
// avoid running multiple retrievals for the same patron, which
// can happen during dbl-click by maintaining a single running
selectedItems : function() {return []}
}
+ // Max recents setting is loaded and scrubbed during egStartup.
+ // Copy it to a local variable here for ease of local access.
+ egCore.org.settings('ui.staff.max_recent_patrons').then(function(s) {
+ patronSvc.maxRecentPatrons = s['ui.staff.max_recent_patrons'];
+ });
+
+ // The first time we encounter the show-recent CGI param, put the
+ // service into show-recent mode. The first time recents are shown,
+ // the service is taken out of show-recent mode so the page does not
+ // get stuck in a show-recent loop.
+ if (patronSvc.showRecent === undefined
+ && Boolean($location.path().match(/search/))
+ && Boolean($location.search().show_recent)) {
+ patronSvc.showRecent = true;
+ }
+
// Handle URL-encoded searches
if ($location.search().search) {
console.log('URL search = ' + $location.search().search);
var propagate;
var propagate_inactive;
- if (patronSvc.lastSearch) {
+ if (patronSvc.lastSearch && !patronSvc.showRecent) {
propagate = patronSvc.lastSearch.search;
// home_ou needs to be treated specially
propagate.home_ou = {
provider.get = function(offset, count) {
var deferred = $q.defer();
+ if (patronSvc.showRecent) {
+ // avoid getting stuck in show-recent mode
+ return patronSvc.getRecentPatrons();
+ }
+
var fullSearch;
if (patronSvc.urlSearch) {
fullSearch = patronSvc.urlSearch;
var service = { promise : null }
- // Load date/time format settings on all pages. Add more .push(...)
- // calls to add more universal data-loading functions.
+ // Some org settings affect every page. Load them during startup.
+ // Other startup data loaders can be added by appending to egEnv.loaders.
// egEnv.loaders functions must return a promise.
egEnv.loaders.push(
function() {
return egOrg.settings([
'webstaff.format.dates',
'webstaff.format.date_and_time',
+ 'ui.staff.max_recent_patrons', // affects navbar
'lib.timezone'
]).then(
function(set) {
set['webstaff.format.dates'] || 'shortDate';
$rootScope.egDateAndTimeFormat =
set['webstaff.format.date_and_time'] || 'short';
+
+ // default to 1 for backwards compat.
+ if (set['ui.staff.max_recent_patrons'] === null)
+ set['ui.staff.max_recent_patrons'] = 1
}
);
}