resolve : resolver
});
- $routeProvider.when('/circ/patron/recent', {
- templateUrl: './circ/patron/t_search',
- controller: 'PatronSearchCtrl',
- resolve : resolver
- });
-
// the following require a patron ID
$routeProvider.when('/circ/patron/:id/alerts', {
return $q.when();
}
+ // Set the show-recent flag true only once, then set it to
+ // false the first time it's used.
+ service.showRecentPatrons = function() {
+ if (service.showRecent === undefined
+ && Boolean($location.path().match(/search/))
+ && Boolean($location.search().show_recent))
+ service.showRecent = true;
+
+ return service.showRecent;
+ }
+
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') || [];
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 user_id
+ var idx = patrons.indexOf(user_id, 1);
+ if (idx > 0) patrons.splice(idx, 1);
+
egCore.hatch.setLoginSessionItem('eg.circ.recent_patrons', patrons);
}
home_ou : egCore.org.tree()
};
- $scope.showRecentPatrons =
- Boolean($location.path().match(/patron\/recent/));
-
// last used patron search form element
var lastFormElement;
var propagate;
var propagate_inactive;
- if (patronSvc.lastSearch && !$scope.showRecentPatrons) {
+ if (patronSvc.lastSearch && !patronSvc.showRecentPatrons()) {
propagate = patronSvc.lastSearch.search;
// home_ou needs to be treated specially
propagate.home_ou = {
provider.get = function(offset, count) {
var deferred = $q.defer();
- if ($scope.showRecentPatrons)
+ if (patronSvc.showRecentPatrons()) {
+ // avoid getting stuck in show-recent mode
return patronSvc.getRecentPatrons();
+ }
var fullSearch;
if (patronSvc.urlSearch) {
['$scope','$location','egCore',
function($scope , $location , egCore) {
- var id = egCore.hatch.getLoginSessionItem('eg.circ.last_patron');
- if (id) return $location.path('/circ/patron/' + id + '/checkout');
+ var ids = egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
+ if (ids.length)
+ return $location.path('/circ/patron/' + ids[0] + '/checkout');
$scope.no_last = true;
}])