Updates the Open-ILS/web/js/ui/default/staff/cat/item/app.js since the previous versi... user/abowling/lp1845556_spine_label_enhanced_printing
authorAdam Bowling <abowling@emeralddata.net>
Fri, 15 Jan 2021 05:54:48 +0000 (00:54 -0500)
committerAdam Bowling <abowling@emeralddata.net>
Fri, 15 Jan 2021 05:54:48 +0000 (00:54 -0500)
not take into consideration changes to this file.

Signed-off-by: Adam Bowling <abowling@emeralddata.net>
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index a16de86..1cd8f3e 100644 (file)
@@ -86,8 +86,12 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
         itemSvc.add_copies_to_bucket([$scope.args.copyId]);
     }
 
+    $scope.add_records_to_bucket = function() {
+        itemSvc.add_records_to_bucket([$scope.args.recordId], 'biblio');
+    }
+
     $scope.show_in_catalog = function() {
-        window.open('/eg/staff/cat/catalog/record/' + $scope.args.recordId + '/catalog', '_blank');
+        window.open('/eg2/staff/catalog/record/' + $scope.args.recordId, '_blank');
     }
 
     $scope.print_labels = function() {
@@ -145,41 +149,6 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
         itemSvc.manage_reservations([$scope.args.copyBarcode]);
     }
 
-    $scope.findAcquisition = function() {
-        var acqData;
-        var promises = [];
-        $scope.openAcquisitionLineItem([$scope.args.copyId]);
-    }
-
-    $scope.openAcquisitionLineItem = function (cp_list) {
-        var hasResults = false;
-        var promises = [];
-
-        angular.forEach(cp_list, function (copyId) {
-            promises.push(
-                egNet.request(
-                    'open-ils.acq',
-                    'open-ils.acq.lineitem.retrieve.by_copy_id',
-                    egCore.auth.token(),
-                    copyId
-                ).then(function (acqData) {
-                    if (acqData) {
-                        if (acqData.a) {
-                            acqData = egCore.idl.toHash(acqData);
-                            var url = '/eg/acq/po/view/' + acqData.purchase_order + '/' + acqData.id;
-                            $timeout(function () { $window.open(url, '_blank') });
-                            hasResults = true;
-                        }
-                    }
-                })
-            )
-        });
-
-        $q.all(promises).then(function () {
-            !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
-        });
-    }
-
     $scope.requestItems = function() {
         itemSvc.requestItems([$scope.args.copyId],[$scope.args.recordId]);
     }
@@ -200,7 +169,7 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     }
 
     $scope.show_record_holds = function() {
-        window.open('/eg/staff/cat/catalog/record/' + $scope.args.recordId + '/holds', '_blank');
+        window.open('/eg2/staff/catalog/record/' + $scope.args.recordId + '/holds', '_blank');
     }
 
     $scope.add_item_alerts = function() {
@@ -394,6 +363,9 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     };
 
     $scope.$watch('barcodesFromFile', function(newVal, oldVal) {
+        $scope.context.itemsNotFound = [];
+        $scope.context.fileDoneLoading = false;
+        $scope.context.numBarcodesInFile = 0;
         if (newVal && newVal != oldVal) {
             $scope.args.barcode = '';
             var barcodes = [];
@@ -420,38 +392,71 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
                     if(itemSvc.copies[0]){  // Were any copies actually retrieved
                         copyGrid.selectItems([itemSvc.copies[0].index]);
                     }
+                    $scope.context.fileDoneLoading = true;
                     return;
                 }
 
-                itemSvc.fetch(barcode).then(fetch_next_copy);
+                itemSvc.fetch(barcode).then(function(item) {
+                    if (!item) {
+                        $scope.context.itemsNotFound.push(barcode);
+                    }
+                    fetch_next_copy();
+                })
             }
 
             if (barcodes.length) {
+                $scope.context.numBarcodesInFile = barcodes.length;
                 egProgressDialog.open({value: 0, max: barcodes.length});
                 fetch_next_copy();
             }
         }
     });
 
-    $scope.context.search = function(args) {
-        if (!args.barcode) return;
+    $scope.context.search = function(args, noGridRefresh) {
+        if (!args.barcode) return $q.when();
         $scope.context.itemNotFound = false;
-        itemSvc.fetch(args.barcode).then(function(res) {
-            if (res) {
-                copyGrid.refresh();
-                copyGrid.selectItems([res.index]);
-                $scope.args.barcode = '';
-            } else {
-                $scope.context.itemNotFound = true;
-                egCore.audio.play('warning.item_status.itemNotFound');
-            }
-            $scope.context.selectBarcode = true;
-        })
+
+        //check to see if there are multiple barcodes in CSV format
+        var barcodes = [];
+        //split on commas and clean up barcodes
+        angular.forEach(args.barcode.split(/,/), function(line) {
+            //remove all whitespace and commas
+            line = line.replace(/[\s,]+/g,'');
+
+            //Or remove leading/trailing whitespace
+            //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
+
+            if (!line) return;
+            barcodes.push(line);
+        });
+
+        if(barcodes.length > 1){
+            //convert to newline seperated list and send to barcodesFromFile processor
+            $scope.barcodesFromFile = barcodes.join('\n');
+            //console.log('Barcodes: ',barcodes);
+            return $q.when();
+
+        } else {
+            //Single Barcode
+            return itemSvc.fetch(args.barcode).then(function(res) {
+                if (res) {
+                    if (!noGridRefresh) {
+                        copyGrid.refresh();
+                    }
+                    copyGrid.selectItems([res.index]);
+                    $scope.args.barcode = '';
+                } else {
+                    $scope.context.itemNotFound = true;
+                    egCore.audio.play('warning.item_status.itemNotFound');
+                }
+                $scope.context.selectBarcode = true;
+            })
+        }
     }
 
-    var add_barcode_to_list = function (b) {
-        //console.log('listCtrl: add_barcode_to_list',b);
-        $scope.context.search({barcode:b});
+    var add_barcode_to_list = function (b, noGridRefresh) {
+        // console.log('listCtrl: add_barcode_to_list',b);
+        return $scope.context.search({barcode:b}, noGridRefresh);
     }
     itemSvc.add_barcode_to_list = add_barcode_to_list;
 
@@ -504,6 +509,17 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
         return cp_id_list;
     }
 
+    function gatherSelectedHoldingsRecords() {
+        var record_id_list = [];
+        angular.forEach(
+            copyGrid.selectedItems(),
+            function (item) {
+                record_id_list.push(item['call_number.record.id']);
+            }
+        )
+        return record_id_list;
+    }
+
     $scope.refreshGridData = function() {
         var chain = $q.when();
         var all_items = itemSvc.copies.map(function(item) {
@@ -526,6 +542,11 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
         itemSvc.add_copies_to_bucket(copy_list);
     }
 
+    $scope.add_records_to_bucket = function() {
+        var record_list = gatherSelectedHoldingsRecords();
+        itemSvc.add_copies_to_bucket(record_list, 'biblio');
+    }
+
     $scope.locateAcquisition = function() {
         if (gatherSelectedHoldingsIds) {
             var cp_list = gatherSelectedHoldingsIds();
@@ -614,7 +635,13 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     }
 
     $scope.selectedHoldingsMissing = function () {
-        itemSvc.selectedHoldingsMissing(copyGrid.selectedItems());
+        egProgressDialog.open();
+        itemSvc.selectedHoldingsMissing(copyGrid.selectedItems())
+        .then(function() { 
+            egProgressDialog.close();
+            console.debug('Marking missing complete, refreshing grid');
+            copyGrid.refresh();
+        });
     }
 
     $scope.checkin = function () {
@@ -661,7 +688,7 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
 
     $scope.showBibHolds = function () {
         angular.forEach(gatherSelectedRecordIds(), function (r) {
-            var url = egCore.env.basePath + 'cat/catalog/record/' + r + '/holds';
+            var url = '/eg2/staff/catalog/record/' + r + '/holds';
             $timeout(function() { $window.open(url, '_blank') });
         });
     }
@@ -766,21 +793,21 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
  * Detail view -- shows one copy
  */
 .controller('ViewCtrl', 
-       ['$scope','$q','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
-function($scope , $q , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
+       ['$scope','$q','egGridDataProvider','$location','$routeParams','$timeout','$window','egCore','egItem','egBilling','egCirc',
+function($scope , $q , egGridDataProvider , $location , $routeParams , $timeout , $window , egCore , itemSvc , egBilling , egCirc) {
     var copyId = $routeParams.id;
     $scope.args.copyId = copyId;
     $scope.tab = $routeParams.tab || 'summary';
     $scope.context.page = 'detail';
     $scope.summaryRecord = null;
-
+    $scope.courseModulesOptIn = fetchCourseOptIn();
+    $scope.has_course_perms = fetchCoursePerms();
     $scope.edit = false;
     if ($scope.tab == 'edit') {
         $scope.tab = 'summary';
         $scope.edit = true;
     }
 
-
     // use the cached record info
     if (itemSvc.copy) {
         $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
@@ -987,6 +1014,27 @@ console.debug($scope.copy_alert_count);
         });
     }
 
+    // Check for Course Modules Opt-In to enable Course Info tab
+    function fetchCourseOptIn() {
+        return egCore.org.settings(
+            'circ.course_materials_opt_in'
+        ).then(function(set) {
+            $scope.courseModulesOptIn = set['circ.course_materials_opt_in'];
+
+            return $scope.courseModulesOptIn;
+        });
+    }
+
+    function fetchCoursePerms() {
+        return egCore.perm.hasPermAt('MANAGE RESERVES', true).then(function(orgIds) {
+            if(orgIds.indexOf(egCore.auth.user().ws_ou()) != -1){
+                $scope.has_course_perms = true;
+
+                return $scope.has_course_perms;
+            }
+        });
+    }
+
     $scope.addBilling = function(circ) {
         egBilling.showBillDialog({
             xact_id : circ.id(),
@@ -1161,6 +1209,47 @@ console.debug($scope.copy_alert_count);
         })
     }
 
+    function loadCourseInfo() {
+        delete $scope.courses;
+        delete $scope.instructors;
+        delete $scope.course_ids;
+        delete $scope.instructors_exist;
+        if (!copyId) return;
+        $scope.course_ids = [];
+        $scope.courses = [];
+        $scope.instructors = {};
+
+        egCore.pcrud.search('acmcm', {
+            item: copyId
+        }, {
+            flesh: 3,
+            flesh_fields: {
+                acmcm: ['course']
+            }, order_by: {acmc : 'id desc'}
+        }).then(null, null, function(material) {
+            
+            $scope.courses.push(material.course());
+            egCore.net.request(
+                'open-ils.circ',
+                'open-ils.circ.course_users.retrieve',
+                material.course().id()
+            ).then(null, null, function(instructors) {
+                angular.forEach(instructors, function(instructor) {
+                    var patron_id = instructor.patron_id.toString();
+                    if (!$scope.instructors[patron_id]) {
+                        $scope.instructors[patron_id] = instructor;
+                        $scope.instructors_exist = true;
+                        $scope.instructors[patron_id]._linked_course = [];
+                    }
+                    $scope.instructors[patron_id]._linked_course.push({
+                        role: instructor.usr_role,
+                        course: material.course().name()
+                    });
+                });
+            });
+        });
+    }
+
 
     // we don't need all data on all tabs, so fetch what's needed when needed.
     function loadTabData() {
@@ -1183,6 +1272,10 @@ console.debug($scope.copy_alert_count);
                 loadMostRecentTransit();
                 break;
 
+            case 'course':
+                loadCourseInfo();
+                break;
+
             case 'triggered_events':
                 var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/event_log');
                 url += '?copy_id=' + encodeURIComponent(copyId);