service.holds = [];
service.hold_ids = [];
service.checkout_overrides = {};
+ service.hasAlerts = false;
service.alertsShown = false;
+ service.patronExpired = false;
+ service.patronExpiresSoon = false;
}
service.resetPatronLists(); // initialize
service.setDefault = function(id, user, force) {
if (user) {
if (!force && service.current &&
- service.current.id() == user.id()) return;
+ service.current.id() == user.id())
+ return $q.when();
service.resetPatronLists();
service.current = user;
service.localFlesh(user);
- service.fetchUserStats();
- return $q.when();
+ return service.fetchUserStats();
} else if (id) {
if (!force && service.current && service.current.id() == id)
function(user) {
service.current = user;
service.localFlesh(user);
- service.fetchUserStats();
+ return service.fetchUserStats();
},
function(err) {
console.error(
);
}
+ // resolves to true if the patron account has expired or will
+ // expire soon, based on YAOUS circ.patron_expires_soon_warning
+ service.testExpire = function() {
+
+ var expire = Date.parse(service.current.expire_date());
+ if (expire < new Date()) {
+ return $q.when(service.patronExpired = true);
+ }
+
+ // account not yet expired, see if it will expire soon
+ return egCore.org.settings('circ.patron_expires_soon_warning')
+ .then(function(set) {
+
+ var soon = set['circ.patron_expires_soon_warning'];
+ if (Number(soon)) {
+ var preExpire = new Date();
+ preExpire.setDate(preExpire.getDate() + Number(soon));
+ if (expire < preExpire)
+ return service.patronExpiresSoon = true;
+ }
+
+ return false;
+ });
+ }
+
+ // resolves to true if there is any aspect of the patron account
+ // which should produce a message in the alerts panel
+ service.checkAlerts = function() {
+ var deferred = $q.defer();
+ if (service.hasAlerts) return $q.when(true);
+
+ var p = service.current;
+
+ if (p.standing_penalties().length ||
+ p.alert_message() ||
+ p.active() == 'f' ||
+ p.barred() == 't' ||
+ service.patron_stats.holds.ready) {
+
+ service.hasAlerts = true;
+ }
+
+
+ // regardless of whether we know of alerts, we still need
+ // to test/fetch the expire data for display
+ service.testExpire().then(function(bool) {
+ if (bool) service.hasAlerts = true;
+ deferred.resolve(service.hasAlerts);
+ });
+
+ return deferred.promise;
+ }
+
+
// grab additional circ info
service.fetchUserStats = function() {
- egCore.net.request(
+ return egCore.net.request(
'open-ils.actor',
'open-ils.actor.user.opac.vital_stats',
egCore.auth.token(), service.current.id()
* Manages tabbed patron view
* */
.controller('PatronCtrl',
- ['$scope','$q','$filter','egCore','egUser','patronSvc',
-function($scope, $q, $filter, egCore, egUser, patronSvc) {
+ ['$scope','$q','$location','$filter','egCore','egUser','patronSvc',
+function($scope, $q, $location , $filter, egCore, egUser, patronSvc) {
// called after each route-specified controller is instantiated.
// this doubles as a way to inform the top-level controller that
$scope.aous = egCore.env.aous;
if (patron_id) {
$scope.patron_id = patron_id
- return patronSvc.setDefault($scope.patron_id);
+ return patronSvc.setDefault($scope.patron_id)
+ .then(function() {return patronSvc.checkAlerts()})
+ .then(function() {
+ console.log("patron has alerts = " + patronSvc.hasAlerts);
+
+ // if the patron has any unshown alerts, show them now
+ if (!patronSvc.alertsShown &&
+ patronSvc.hasAlerts &&
+ !$location.path().match(/\/alerts$/)) {
+ patronSvc.alertsShown = true;
+ $location.path('/circ/patron/'
+ + patronSvc.current.id() + '/alerts');
+ }
+ });
}
return $q.when();
}
['$scope','$routeParams','$location','egCore','patronSvc',
function($scope, $routeParams , $location , egCore , patronSvc) {
- // called with a patron, pre-populate the form args
- $scope.initTab('other', $routeParams.id).then(
- function() {
- patronSvc.alertsShown = true;
- }
- );
+ $scope.initTab('other', $routeParams.id)
+ .then(function() {
+ $scope.patronExpired = patronSvc.patronExpired;
+ $scope.patronExpiresSoon = patronSvc.patronExpiresSoon;
+ });
+
}])