function(user) {
service.current = user;
service.localFlesh(user);
+ service.alert_penalties = user.standing_penalties()
+ .filter(function(pen) {
+ return pen.standing_penalty().staff_alert() == 't'
+ });
return service.fetchUserStats();
},
function(err) {
var deferred = $q.defer();
var p = service.current;
- service.alert_penalties = p.standing_penalties().filter(
- function(pen) {
- return pen.standing_penalty().staff_alert() == 't'
- }
- );
-
if (service.alert_penalties.length ||
p.alert_message() ||
p.active() == 'f' ||
function redirectToAlertPanel() {
- $scope.alert_penalties = patronSvc.alert_penalties;
+ $scope.alert_penalties =
+ function() {return patronSvc.alert_penalties}
if (patronSvc.alertsShown) return;
patronSvc.alertsShown = true;
* Manages messages
*/
.controller('PatronMessagesCtrl',
- ['$scope','$routeParams','egCore','$modal',
-function($scope, $routeParams, egCore , $modal) {
+ ['$scope','$q','$routeParams','egCore','$modal','patronSvc',
+function($scope , $q , $routeParams, egCore , $modal , patronSvc) {
$scope.initTab('messages', $routeParams.id);
var usr_id = $routeParams.id;
- $scope.activeRevision = 0;
- $scope.activeSort = ['set_date'];
+ // setup date filters
+ var start = new Date(); // now - 1 year
+ start.setFullYear(start.getFullYear() - 1),
+ $scope.dates = {
+ start_date : start,
+ end_date : new Date()
+ }
+
+ function date_range() {
+ var start = $scope.dates.start_date.toISOString().replace(/T.*/,'');
+ var end = $scope.dates.end_date.toISOString().replace(/T.*/,'');
+ var today = new Date().toISOString().replace(/T.*/,'');
+ if (end == today) end = 'now';
+ return [start, end];
+ }
+
+ // grid queries
+
+ $scope.activeRevision = $scope.archiveRevision = 0;
+ $scope.activeSort = $scope.archiveSort = ['set_date'];
$scope.activeQuery = function() {
return {
usr : usr_id,
]
}
};
-
- $scope.archiveRevision = 0;
- $scope.archiveSort = ['set_date'];
$scope.archiveQuery = function() {
- return {usr : usr_id, stop_date : {'<=' : 'now'}}
+ return {
+ usr : usr_id,
+ stop_date : {'<=' : 'now'},
+ set_date : {between : date_range()}
+ };
};
- var start = new Date(); // now - 1 year
- start.setFullYear(start.getFullYear() - 1),
- $scope.dates = {
- set_date : start,
- stop_date : new Date()
- }
-
- $scope.date_range = function() {
- var start = $scope.dates.set_date.toISOString().replace(/T.*/,'');
- var end = $scope.dates.stop_date.toISOString().replace(/T.*/,'');
- var today = new Date().toISOString().replace(/T.*/,'');
- if (end == today) end = 'now';
- return [start, end];
- }
-
$scope.removePenalty = function(selected) {
// the grid stores flattened penalties. Fetch penalty objects first
});
}
+ // leverage egEnv for caching
+ function fetchPenaltyTypes() {
+ if (egCore.env.csp)
+ return $q.when(egCore.env.csp.list);
+ return egCore.pcrud.search(
+ // id <= 100 are reserved for system use
+ 'csp', {id : {'>': 100}}, {}, {atomic : true})
+ .then(function(penalties) {
+ egCore.env.absorbList(penalties, 'csp');
+ return penalties;
+ });
+ }
+
$scope.createPenalty = function() {
$modal.open({
templateUrl: './circ/patron/t_new_message_dialog',
$scope.ok = function(count) { $modalInstance.close($scope.args) }
$scope.cancel = function () { $modalInstance.dismiss() }
}],
- resolve : {
- staffPenalties : function() {
- return egCore.pcrud.search(
- // id <= 100 are reserved for system use
- 'csp', {id : {'>': 100}}, {}, {atomic : true});
- }
- }
+ resolve : { staffPenalties : fetchPenaltyTypes }
}).result.then(
function(args) {
var pen = new egCore.idl.ausp();
pen.standing_penalty(args.penalty);
pen.staff(egCore.auth.user().id());
pen.set_date('now');
- egCore.pcrud.create(pen).then(
- function() { $scope.activeRevision++ });
+ egCore.pcrud.create(pen).then(function() {
+ $scope.activeRevision++
+ // force a refresh of the user, since they may now
+ // have blocking penalties, etc.
+ patronSvc.setDefault(patronSvc.current.id(), null, true);
+ });
}
);
}
+ $scope.editPenalty = function(selected) {
+ if (selected.length == 0) return;
+
+ // grab the penalty from the user object
+ var penalty = patronSvc.current.standing_penalties().filter(
+ function(p) {return p.id() == selected[0].id})[0];
+ $modal.open({
+ templateUrl: './circ/patron/t_new_message_dialog',
+ controller:
+ ['$scope','$modalInstance','staffPenalties',
+ function($scope , $modalInstance , staffPenalties) {
+ $scope.focusNote = true;
+ $scope.penalties = staffPenalties;
+ $scope.args = {
+ penalty : penalty.standing_penalty().id(),
+ note : penalty.note()
+ }
+ $scope.setPenalty = function(id) {
+ args.penalty = id;
+ }
+ $scope.ok = function(count) { $modalInstance.close($scope.args) }
+ $scope.cancel = function () { $modalInstance.dismiss() }
+ }],
+ resolve : { staffPenalties : fetchPenaltyTypes }
+ }).result.then(
+ function(args) {
+ penalty.note(args.note);
+ penalty.standing_penalty(args.penalty);
+ egCore.pcrud.update(penalty).then(function() {
+ $scope.activeRevision++
+ // force a refresh of the user, since they may now
+ // have blocking penalties, etc.
+ patronSvc.setDefault(patronSvc.current.id(), null, true);
+ });
+ }
+ );
+ }
}])