items out edit due date
authorBill Erickson <berick@esilibrary.com>
Tue, 1 Jul 2014 13:06:46 +0000 (09:06 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 1 Jul 2014 13:06:46 +0000 (09:06 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_edit_due_date_dialog.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js

index 338c3e9..dcca6d3 100644 (file)
@@ -9,9 +9,13 @@
   <div class="modal-body">
     <div class="form-group row pad-vert">
       <div class="col-md-6">
+        [% l('Enter Due Date: ') %]
+      </div>
+      <div class="col-md-6">
         <input eg-date-input class="form-control" ng-model="args.due_date"/>
       </div>
     </div>
+    <!-- TODO: time picker -->
   </div>
   <div class="modal-footer">
     <input type="submit" class="btn btn-primary" value="[% l('OK') %]"/>
index dff599b..cc3767e 100644 (file)
@@ -110,18 +110,50 @@ function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , egGridDataPr
     }
 
     $scope.edit_due_date = function(items) {
+        if (!items.length) return;
+
         $modal.open({
             templateUrl : './circ/patron/t_edit_due_date_dialog',
             controller : [
                         '$scope','$modalInstance',
                 function($scope , $modalInstance) {
+
+                    // if there is only one circ, default to the due date
+                    // of that circ.  Otherwise, default to today.
+                    var due_date = items.length == 1 ? 
+                        Date.parse(items[0].due_date()) : new Date();
+
                     $scope.args = {
                         num_circs : items.length,
-                        due_date : new Date()
+                        due_date : due_date
                     }
+
+                    // Fire off the due-date updater for each circ.
+                    // When all is done, close the dialog
                     $scope.ok = function(args) {
-                        // TODO open-ils.circ.circulation.due_date.update (circ_id, date)
-                        $modalInstance.close();
+                        var due = args.due_date.toISOString().replace(/T.*/,'');
+                        console.debug("applying due date of " + due);
+
+                        var promises = [];
+                        angular.forEach(items, function(circ) {
+                            promises.push(
+                                egCore.net.request(
+                                    'open-ils.circ',
+                                    'open-ils.circ.circulation.due_date.update',
+                                    egCore.auth.token(), circ.id(), due
+
+                                ).then(function(new_circ) {
+                                    // update the grid circ with the canonical 
+                                    // date from the modified circulation.
+                                    circ.due_date(new_circ.due_date());
+                                })
+                            );
+                        });
+
+                        $q.all(promises).then(function() {
+                            $modalInstance.close();
+                            provider.refresh();
+                        });
                     }
                     $scope.cancel = function($event) {
                         $modalInstance.dismiss();