patron messages editing; filter range
authorBill Erickson <berick@esilibrary.com>
Fri, 6 Jun 2014 20:21:58 +0000 (16:21 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 6 Jun 2014 20:21:58 +0000 (16:21 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2
Open-ILS/src/templates/staff/circ/patron/t_messages.tt2
Open-ILS/src/templates/staff/circ/patron/t_summary.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index 818fbfe..822240c 100644 (file)
@@ -42,7 +42,7 @@
   </div>
 
   <!-- penalties -->
-  <div class="row" ng-if="alert_penalties.length">
+  <div class="row" ng-if="alert_penalties().length">
     <div class="col-md-12">
       <div class="panel panel-warning">
         <div class="panel-heading">
@@ -50,7 +50,7 @@
         </div>
         <div class="panel-body">
           <div class="row" 
-            ng-repeat="penalty in alert_penalties">
+            ng-repeat="penalty in alert_penalties()">
             <div class="col-md-2">
               {{penalty.org_unit().shortname()}}
             </div>
index 4fa23b4..ef08445 100644 (file)
 
 <div class="pad-vert"><hr/></div>
 
-<div class="strong-text-2">[% l('Archived Penalties / Messages') %]</div>
-<div class="pad-vert"></div>
+<div class="pad-vert flex-row padded">
+  <div class="strong-text-2">[% l('Archived Penalties / Messages') %]</div>
+  <div class="flex-cell"></div>
+  <div>[% l('Set Date Start:') %]</div>
+  <div><input eg-date-input class="form-control" ng-model="dates.start_date"/></div>
+  <div>[% l('Set Date End:') %]</div>
+  <div><input eg-date-input class="form-control" ng-model="dates.end_date"/></div>
+</div>
 <eg-grid
   idl-class="ausp"
   query="archiveQuery"
index db51b8b..50ba849 100644 (file)
@@ -3,7 +3,7 @@
   <div ng-show="patron()" id="patron-summary-grid">
     <div class="row" 
       ng-class="{'patron-summary-divider' : !$index}"
-      ng-repeat="penalty in alert_penalties">
+      ng-repeat="penalty in alert_penalties()">
       <div 
         class="col-md-9 patron-summary-alert"
         title="{{penalty.standing_penalty().name()}}">
@@ -14,7 +14,7 @@
       </div>
     </div>
     <div class="row" 
-      ng-class="{'patron-summary-divider' : alert_penalties.length}">
+      ng-class="{'patron-summary-divider' : alert_penalties().length}">
       <div class="col-md-5">[% l('Profile') %]</div>
       <div class="col-md-7">{{patron().profile().name()}}</div>
     </div>
index c16ba00..1fd4db7 100644 (file)
@@ -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);
+                });
+            }
+        );
+    }
 }])