From 8c8c8c8f6409df3234dde857eaaaf3b33204e905 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 6 Jun 2014 16:21:58 -0400 Subject: [PATCH] patron messages editing; filter range Signed-off-by: Bill Erickson --- .../src/templates/staff/circ/patron/t_alerts.tt2 | 4 +- .../src/templates/staff/circ/patron/t_messages.tt2 | 10 +- .../src/templates/staff/circ/patron/t_summary.tt2 | 4 +- .../web/js/ui/default/staff/circ/patron/app.js | 129 ++++++++++++++------- 4 files changed, 102 insertions(+), 45 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 index 818fbfef0d..822240c2d6 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 @@ -42,7 +42,7 @@ -
+
@@ -50,7 +50,7 @@
+ ng-repeat="penalty in alert_penalties()">
{{penalty.org_unit().shortname()}}
diff --git a/Open-ILS/src/templates/staff/circ/patron/t_messages.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_messages.tt2 index 4fa23b4bba..ef0844505e 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_messages.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_messages.tt2 @@ -29,8 +29,14 @@

-
[% l('Archived Penalties / Messages') %]
-
+
+
[% l('Archived Penalties / Messages') %]
+
+
[% l('Set Date Start:') %]
+
+
[% l('Set Date End:') %]
+
+
+ ng-repeat="penalty in alert_penalties()">
@@ -14,7 +14,7 @@
+ ng-class="{'patron-summary-divider' : alert_penalties().length}">
[% l('Profile') %]
{{patron().profile().name()}}
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index c16ba007fc..1fd4db717e 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -211,6 +211,10 @@ function($q , $timeout , $location , egCore, egUser , $locale) { 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) { @@ -276,12 +280,6 @@ function($q , $timeout , $location , egCore, egUser , $locale) { 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' || @@ -354,7 +352,8 @@ function($scope, $q, $location , $filter, egCore, egUser, patronSvc) { function redirectToAlertPanel() { - $scope.alert_penalties = patronSvc.alert_penalties; + $scope.alert_penalties = + function() {return patronSvc.alert_penalties} if (patronSvc.alertsShown) return; patronSvc.alertsShown = true; @@ -739,13 +738,31 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egCore, * 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, @@ -755,28 +772,14 @@ function($scope, $routeParams, egCore , $modal) { ] } }; - - $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 @@ -815,6 +818,19 @@ function($scope, $routeParams, egCore , $modal) { }); } + // 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', @@ -830,13 +846,7 @@ function($scope, $routeParams, egCore , $modal) { $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(); @@ -846,13 +856,54 @@ function($scope, $routeParams, egCore , $modal) { 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); + }); + } + ); + } }]) -- 2.11.0