webstaff: Add routing list printing on receive/bind and directly from the action...
authorMike Rylander <mrylander@gmail.com>
Thu, 25 May 2017 00:39:52 +0000 (20:39 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:50 +0000 (12:06 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_batch_receive.tt2
Open-ILS/src/templates/staff/serials/t_print_routing_list.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/serials/t_view_items_grid.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index 2944abe..920686b 100644 (file)
@@ -6,6 +6,7 @@
 
 [% BLOCK APP_JS %]
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/grid.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/eframe.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/mfhd.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/services/core.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/app.js"></script>
index 9beaf9c..60c55bd 100644 (file)
       </label>
     </div>
     <div class="col-md-2">
+      <label class="checkbox-inline">
+        <input type="checkbox" ng-disabled="" ng-model="print_routing_lists">[% l('Print routing lists') %]
+      </label>
+    </div>
+    <div class="col-md-2">
       <label class="checkbox-inline" ng-show="items.length > 1">
         <input type="checkbox" ng-disabled="force_bind" ng-model="bind">[% l('Bind') %]
       </label>
     <div class="col-md-2">
       <b>[% l('Circulation modifier') %]</b>
     </div>
+    <div class="col-md-2"></div>
+    <div class="col-md-1">
+      <b>[% l('Routing List') %]</b>
+    </div>
   </div>
 
   <div class="row">
              ng-model="item._barcode" type="text" id="item_barcode_{{$index}}"
              eg-enter="focus_next_barcode($index)"/>
     </div>
+    <div class="col-md-1">
+      <input type="checkbox" ng-disabled="cannot_print($index)" ng-model="item._print_routing_list"/>
+    </div>
   </div>
 
 </div>
diff --git a/Open-ILS/src/templates/staff/serials/t_print_routing_list.tt2 b/Open-ILS/src/templates/staff/serials/t_print_routing_list.tt2
new file mode 100644 (file)
index 0000000..e5da6f1
--- /dev/null
@@ -0,0 +1,15 @@
+<form ng-submit="ok()" role="form">
+<div class="modal-body">
+  <eg-embed-frame handlers="xulg" url="url" afterload="page_init"/>
+</div>
+
+<div class="modal-footer">
+  <div class="row">
+    <div class="col-md-10"></div>
+    <div class="col-md-2">
+      <input type="submit" ng-show="last" class="btn btn-primary" value='[% l('Done') %]'></input>
+      <input type="submit" ng-show="!last" class="btn btn-primary" value='[% l('Next') %]'></input>
+    </div>
+  </div>
+</div>
+</form>
index fb0309f..2f91d61 100644 (file)
@@ -4,7 +4,7 @@
     features="-display,-sort,-multisort"
     items-provider="itemGridProvider"
     grid-controls="itemGridControls"
-    menu-label="[% l('Filter items') %]"
+    menu-label="[% l('Filter items... ') %]"
     persist-key="serials.view_item_grid">
 
     <eg-grid-menu-item handler="filter_items_all"
         label="[% l('Predict New Issues') %]"></eg-grid-menu-item>
 
 
-    <eg-grid-menu-item handler="receive_barcode_checkbox_handler"
+    <eg-grid-menu-item handler="checkbox_handler"
       label="[% l('Barcode on receive') %]"
       checkbox="receive_and_barcode"
       checked="receive_and_barcode"/>
 
+    <eg-grid-menu-item handler="checkbox_handler"
+      label="[% l('Print routing lists') %]"
+      checkbox="do_print_routing_lists"
+      checked="do_print_routing_lists"/>
+
 
 <!-- Hiding this for now ... seems unnecessary?
-    <eg-grid-menu-item handler="receive_barcode_checkbox_handler"
+    <eg-grid-menu-item handler="checkbox_handler"
       label="[% l('Bind on receive') %]"
       checkbox="receive_and_bind"
       checked="receive_and_bind"/>
 -->
 
 
+    <eg-grid-action handler="menu_print_routing_lists"
+      label="[% l('Print routing lists') %]"></eg-grid-action>
+
     <eg-grid-action handler="receive_selected"
       label="[% l('Receive selected') %]"></eg-grid-action>
 
index 3ad5e34..26e76c8 100644 (file)
@@ -10,9 +10,9 @@ angular.module('egSerialsAppDep')
         },
         templateUrl: './serials/t_view_items_grid',
         controller:
-       ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
+       ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider','orderByFilter',
         '$uibModal','ngToast','egConfirmDialog','egPromptDialog','$timeout',
-function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
+function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByFilter ,
          $uibModal , ngToast , egConfirmDialog , egPromptDialog , $timeout) {
 
     $scope.svc = egSerialsCoreSvc;
@@ -225,9 +225,19 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         });
     }
 
+    $scope.do_print_routing_lists = false;
+    egCore.hatch.getItem('eg.serials.items.do_print_routing_lists').then(function(val) {
+        $scope.do_print_routing_lists = val;
+    });
+
     $scope.receive_and_barcode = false;
-    $scope.receive_barcode_checkbox_handler = function(item) {
+    egCore.hatch.getItem('eg.serials.items.receive_and_barcode').then(function(val) {
+        $scope.receive_and_barcode = val;
+    });
+
+    $scope.checkbox_handler = function(item) {
         $scope[item.checkbox] = item.checked;
+        egCore.hatch.setItem('eg.serials.items.'+item.checkbox, item.checked);
     }
 
     $scope.receive_next = function () {
@@ -279,8 +289,9 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         var deferred = $q.defer();
         var current_promise = deferred.promise;
         var last_promise;
-        if (do_barcode || bind) { // supplying a barcode (unit) to new items
+        if (do_barcode || bind) {
 
+            var print_routing_lists = $scope.do_print_routing_lists;
             last_promise = current_promise.then(function(){ return $uibModal.open({
                 templateUrl: './serials/t_batch_receive',
                 size: 'lg',
@@ -289,6 +300,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                 controller:
                 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
 
+                    $scope.print_routing_lists = print_routing_lists;
                     $scope.barcode_items = do_barcode;
                     $scope.force_bind = bind;
                     $scope.bind = bind;
@@ -296,9 +308,43 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                     $scope.acn_list = [];
                     $scope.acpl_list = [];
 
+                    $scope.cannot_print = function (index) {
+                        return $scope.items[index].stream().routing_list_users().length == 0 || ($scope.bind && index > 0);
+                    }
+
+                    $scope.bind_or_none = function (index) {
+                        return !$scope.barcode_items || ($scope.bind && index > 0);
+                    }
+
+                    $scope.focus_next_barcode = function (index) {
+                        index++;
+                        $('#item_barcode_'+index).focus().select();
+                    }
+
+                    $scope.apply_template_overrides = function (e) {
+                        if ($scope.selected_call_number) {
+                            angular.forEach($scope.items, function (i) {
+                                i._call_number = $scope.selected_call_number;
+                            });
+                        }
+                        if ($scope.selected_circ_mod) {
+                            angular.forEach($scope.items, function (i) {
+                                i._circ_mod = $scope.selected_circ_mod;
+                            });
+                        }
+                        if ($scope.selected_copy_location) {
+                            angular.forEach($scope.items, function (i) {
+                                i._copy_location = $scope.selected_copy_location;
+                            });
+                        }
+                    }
+
+                    $scope.ok = function(items) { $uibModalInstance.close(items) }
+                    $scope.cancel = function () { $uibModalInstance.dismiss() }
+
                     var pile_o_promises = [$q.when()];
                     // let's gather what we need...
-                    angular.forEach(list, function (i) {
+                    angular.forEach(list, function (i, index) {
                         if (i.unit()) {
                             i._barcode = i.unit().barcode();
                             pile_o_promises.push(
@@ -322,6 +368,9 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                             i._copy_location = i.stream().distribution()[mode + '_unit_template']().location();
                             i._circ_mod = i.stream().distribution()[mode + '_unit_template']().circ_modifier();
                         }
+
+                        if ($scope.print_routing_lists && !$scope.cannot_print(index))
+                            i._print_routing_list = true;
                     });
 
                     pile_o_promises.push(egCore.pcrud.search(
@@ -353,33 +402,6 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                         console.log('receive data collected');
                     });
 
-                    $scope.bind_or_none = function (index) {
-                        return !$scope.barcode_items || ($scope.bind && index > 0);
-                    }
-
-                    $scope.focus_next_barcode = function (index) {
-                        index++;
-                        $('#item_barcode_'+index).focus().select();
-                    }
-
-                    $scope.apply_template_overrides = function (e) {
-                        if ($scope.selected_call_number) {
-                            angular.forEach($scope.items, function (i) {
-                                i._call_number = $scope.selected_call_number;
-                            });
-                        }
-                        if ($scope.selected_circ_mod) {
-                            angular.forEach($scope.items, function (i) {
-                                i._circ_mod = $scope.selected_circ_mod;
-                            });
-                        }
-                        if ($scope.selected_copy_location) {
-                            angular.forEach($scope.items, function (i) {
-                                i._copy_location = $scope.selected_copy_location;
-                            });
-                        }
-                    }
-
                     $scope.$watch('barcode_items', function (n,o) {
                         if (n === undefined || n == o) return;
                         do_barcode = n;
@@ -388,6 +410,11 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                     $scope.$watch('bind', function (n,o) {
                         if (n === undefined || n == o) return;
                         bind = n;
+                        if (bind) {
+                            angular.forEach($scope.items, function (i,index) {
+                                if (index > 0) i._print_routing_list = false;
+                            });
+                        }
                     });
                         
                     $scope.$watch('auto_barcodes', function (n,o) {
@@ -403,8 +430,17 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                         });
                     });
 
-                    $scope.ok = function(items) { $uibModalInstance.close(items) }
-                    $scope.cancel = function () { $uibModalInstance.dismiss() }
+                    $scope.$watch('print_routing_lists', function (n,o) {
+                        if (n === undefined || n == o) return;
+
+                        angular.forEach($scope.items, function(i, index) {
+                            if (!$scope.cannot_print(index)) {
+                                i._print_routing_list = n;
+                            } else {
+                                i._print_routing_list = false;
+                            }
+                        });
+                    });
                 }]
             }).result});
         } else {
@@ -453,7 +489,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
                         ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
                     } else {
                         ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
-                        return reload($scope.ssubId,_paging_filter);
+                        return $scope.print_routing_lists_impl(items, do_barcode || bind)
+                            .finally(function(){reload($scope.ssubId,_paging_filter)});
                     }
                 },
                 function(resp) {
@@ -465,6 +502,80 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         return deferred.resolve();
     }
 
+    $scope.menu_print_routing_lists = function (items) {
+        items = items.map(function(item) {
+            return egCore.idl.Clone(egSerialsCoreSvc.itemMap[item.id]);
+        });
+        return $scope.print_routing_lists_impl(items, false, true);
+    }
+
+    $scope.print_routing_lists_impl = function (items, check, force) {
+        if (!check && !$scope.do_print_routing_lists && !force) return $q.when();
+
+        return egCore.net.request(
+            'open-ils.search',
+            'open-ils.search.biblio.record.mods_slim.retrieve',
+            $scope.bibId
+        ).then(function(mvr) {
+
+            var by_issuance = {};
+            angular.forEach(items, function (i) {
+                if (check && !i._print_routing_list) return;
+                if (!by_issuance[i.issuance().id()])
+                    by_issuance[i.issuance().id()] = [];
+                by_issuance[i.issuance().id()].push(i);
+            });
+
+            var issuance_matrix = [];
+            angular.forEach(by_issuance, function (list) {
+                issuance_matrix.push(list);
+            });
+
+            var deferred = $q.defer();
+            var promise = deferred.promise;
+
+            angular.forEach(issuance_matrix, function(item_list, index) {
+
+                promise = promise.then(function(){
+                    return $uibModal.open({
+                        templateUrl: './serials/t_print_routing_list',
+                        size: 'lg',
+                        windowClass: 'eg-wide-modal',
+                        backdrop: 'static',
+                        controller:
+                        ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
+                            var all_users = [];
+                            var all_streams = [];
+
+                            angular.forEach(item_list, function(i){
+                                all_streams.push(i.stream());
+                                all_users = all_users.concat(i.stream().routing_list_users());
+                            });
+
+                            $scope.xulg = {
+                                show_print_button: true,
+                                routing_list_data: {
+                                    streams : all_streams,
+                                    mvr     : mvr,
+                                    issuance: item_list[0].issuance(),
+                                    users   : orderByFilter(all_users, 'pos')
+                                }
+                            };
+
+                            $scope.url = '/eg/serial/print_routing_list_users?ses=' + egCore.auth.token();
+                            $scope.last = index == issuance_matrix.length - 1 ? true : false; 
+                            $scope.ok = function() { $uibModalInstance.close() }
+                        }]
+                    }).result;
+                });
+
+            });
+
+            return deferred.resolve();
+        });
+
+    }
+
     $scope.add_issuances = function () {
         var lastItem = egSerialsCoreSvc.itemList[egSerialsCoreSvc.itemList.length - 1];
 
index db707a5..77e4acd 100644 (file)
@@ -128,7 +128,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
         return egCore.pcrud.search('ssub', {
                 record_entry : bibId
             }, {
-                flesh : 3,
+                flesh : 5,
                 flesh_fields : {
                     'ssub'  : ['owning_lib','distributions', 'scaps', 'notes'],
                     'sdist' : [ 'record_entry','holding_lib',
@@ -137,7 +137,9 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
                                 'bind_call_number',
                                 'bind_unit_template',
                                 'streams','notes'],
-                    'sstr'  : ['routing_list_users']
+                    'sstr'  : ['routing_list_users'],
+                    'srlu'  : ['reader'],
+                    'au'    : ['card','home_ou','mailing_address','billing_address']
                 }
             },
             { atomic : true }
@@ -229,7 +231,9 @@ function(egCore , orderByFilter , $q , $filter , $uibModal) {
             angular.forEach(sub.distributions(), function(dist) {
                 angular.forEach(dist.streams(), function(stream) {
                     angular.forEach(tmp[stream.id()], function (item) {
+                        var routing_list = egCore.idl.Clone(stream.routing_list_users());
                         var st = egCore.idl.Clone(stream,1);
+                        st.routing_list_users(routing_list);
                         var d = egCore.idl.Clone(dist,1);
                         var ss = egCore.idl.Clone(sub,1);
                         ss.distributions([]);