LP #1821950 Call Number Labels Should Not Be Required In The Copy Editor
authorZavier Banks <zbanks@catalyte.io>
Tue, 5 Nov 2019 20:56:11 +0000 (20:56 +0000)
committerZavier Banks <zbanks@catalyte.io>
Mon, 11 Nov 2019 15:49:44 +0000 (15:49 +0000)
Resolved the bug that caused the server to return a 500 error.
By adding a few conditionals the UI seems to run with minimal
problems.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index 4e1de29..b55020a 100644 (file)
@@ -621,6 +621,7 @@ function(egCore , $q) {
         controller : ['$scope','itemSvc','egCore',
             function ( $scope , itemSvc , egCore ) {
                 $scope.callNumber =  $scope.copies[0].call_number();
+                $scope.callNumber.owning_lib(null)
                 if (!$scope.callNumber.label()) $scope.callNumber.empty_label = true;
 
                 $scope.empty_label = false;
@@ -630,77 +631,79 @@ function(egCore , $q) {
                 $scope.empty_label_string = window.empty_label_string;
 
                 $scope.idTracker = function (x) { if (x && x.id) return x.id() };
+                if($scope.callNumber.owning_lib()){
+                    // XXX $() is not working! arg
+                    $scope.focusNextBarcode = function (i, prev_bc) {
+                        var n;
+                        var yep = false;
+                        angular.forEach($scope.copies, function (cp) {
+                            if (n) return;
+
+                            if (cp.id() == i) {
+                                yep = true;
+                                return;
+                            }
 
-                // XXX $() is not working! arg
-                $scope.focusNextBarcode = function (i, prev_bc) {
-                    var n;
-                    var yep = false;
-                    angular.forEach($scope.copies, function (cp) {
-                        if (n) return;
-
-                        if (cp.id() == i) {
-                            yep = true;
-                            return;
-                        }
-
-                        if (yep) n = cp.id();
-                    });
+                            if (yep) n = cp.id();
+                        });
 
-                    if (n) {
-                        var next = '#' + $scope.callNumber.id() + '_' + n;
-                        var el = $(next);
-                        if (el) {
-                            if (!itemSvc.currently_generating) el.focus();
-                            if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
-                                itemSvc.nextBarcode(prev_bc).then(function(bc){
-                                    el.focus();
-                                    el.val(bc);
-                                    el.trigger('change');
-                                });
-                            } else {
-                                itemSvc.currently_generating = false;
+                        if (n) {
+                            var next = '#' + $scope.callNumber.id() + '_' + n;
+                            var el = $(next);
+                            if (el) {
+                                if (!itemSvc.currently_generating) el.focus();
+                                if (prev_bc && itemSvc.auto_gen_barcode && el.val() == "") {
+                                    itemSvc.nextBarcode(prev_bc).then(function(bc){
+                                        el.focus();
+                                        el.val(bc);
+                                        el.trigger('change');
+                                    });
+                                } else {
+                                    itemSvc.currently_generating = false;
+                                }
                             }
+                        } else {
+                            $scope.focusNext($scope.callNumber.id(),prev_bc)
                         }
-                    } else {
-                        $scope.focusNext($scope.callNumber.id(),prev_bc)
                     }
-                }
 
-                $scope.suffix_list = [];
-                itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
-                    $scope.suffix_list = list;
-                    $scope.$watch('callNumber.suffix()', function (v) {
-                        if (angular.isObject(v)) v = v.id();
-                        $scope.suffix = $scope.suffix_list.filter( function (s) {
-                            return s.id() == v;
-                        })[0];
-                    });
+                    $scope.suffix_list = [];
+                    itemSvc.get_suffixes($scope.callNumber.owning_lib()).then(function(list){
+                        $scope.suffix_list = list;
+                        $scope.$watch('callNumber.suffix()', function (v) {
+                            if (angular.isObject(v)) v = v.id();
+                            $scope.suffix = $scope.suffix_list.filter( function (s) {
+                                return s.id() == v;
+                            })[0];
+                        });
 
-                });
-                $scope.updateSuffix = function () {
-                    angular.forEach($scope.copies, function(cp) {
-                        cp.call_number().suffix($scope.suffix);
-                        cp.call_number().ischanged(1);
                     });
-                }
+                    $scope.updateSuffix = function () {
+                        angular.forEach($scope.copies, function(cp) {
+                            cp.call_number().suffix($scope.suffix);
+                            cp.call_number().ischanged(1);
+                        });
+                    }
 
-                $scope.prefix_list = [];
-                itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
-                    $scope.prefix_list = list;
-                    $scope.$watch('callNumber.prefix()', function (v) {
-                        if (angular.isObject(v)) v = v.id();
-                        $scope.prefix = $scope.prefix_list.filter(function (p) {
-                            return p.id() == v;
-                        })[0];
-                    });
+                    $scope.prefix_list = [];
+                    itemSvc.get_prefixes($scope.callNumber.owning_lib()).then(function(list){
+                        $scope.prefix_list = list;
+                        $scope.$watch('callNumber.prefix()', function (v) {
+                            if (angular.isObject(v)) v = v.id();
+                            $scope.prefix = $scope.prefix_list.filter(function (p) {
+                                return p.id() == v;
+                            })[0];
+                        });
 
-                });
-                $scope.updatePrefix = function () {
-                    angular.forEach($scope.copies, function(cp) {
-                        cp.call_number().prefix($scope.prefix);
-                        cp.call_number().ischanged(1);
                     });
+                    $scope.updatePrefix = function () {
+                        angular.forEach($scope.copies, function(cp) {
+                            cp.call_number().prefix($scope.prefix);
+                            cp.call_number().ischanged(1);
+                        });
+                    }
                 }
+                
                 $scope.$watch('callNumber.owning_lib()', function(oldLib, newLib) {
                     if (oldLib == newLib) return;
                     var currentPrefix = $scope.callNumber.prefix();
@@ -766,7 +769,8 @@ function(egCore , $q) {
                         $scope.callNumber.empty_label = $scope.empty_label = true;
                     } else {
                         $scope.callNumber.empty_label = $scope.empty_label = false;
-                    }
+                    } 
+                    
                 });
 
                 $scope.prefix = $scope.callNumber.prefix();
@@ -910,10 +914,14 @@ function(egCore , $q) {
                 $scope.owning_lib = egCore.org.get($scope.lib);
                 $scope.$watch('owning_lib', function (oldLib, newLib) {
                     if (oldLib == newLib) return;
-                    angular.forEach( Object.keys($scope.struct), function (cn) {
-                        $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
-                        $scope.struct[cn][0].call_number().ischanged(1);
-                    });
+                    if($scope.owning_lib){
+                        angular.forEach( Object.keys($scope.struct), function (cn) {                        
+                            $scope.struct[cn][0].call_number().owning_lib( $scope.owning_lib.id() );
+                            $scope.struct[cn][0].call_number().ischanged(1);
+                        });
+                    }
+                    
+                    
                 });
 
                 $scope.cant_have_vols = function (id) { return !egCore.org.CanHaveVolumes(id); };
@@ -1018,7 +1026,9 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
 
     $scope.new_lib_to_add = egCore.org.get(egCore.auth.user().ws_ou());
     $scope.changeNewLib = function (org) {
-        $scope.new_lib_to_add = org;
+        if(!$scope.cant_have_vols(org)) {
+            $scope.new_lib_to_add = org;
+        }
     }
     $scope.addLibToStruct = function () {
         var newLib = $scope.new_lib_to_add;
@@ -1037,7 +1047,6 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             $scope.fast_add,
             true
         );
-
         $scope.data.addCopy(cp);
 
         // manually increase cn_count numeric input
@@ -1293,6 +1302,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                     $scope.workingGridControls.selectedItems(),
                     function (cp) {
                         $scope.dirty = true;
+                        
 
                         cp.stat_cat_entries(
                             angular.forEach( cp.stat_cat_entries(), function (e) {
@@ -1551,7 +1561,6 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             'open-ils.actor.anon_cache.get_value',
             dataKey, 'edit-these-copies'
         ).then(function (data) {
-
             if (data) {
                 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
                 if (data.hide_copies) {
@@ -1712,6 +1721,9 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                     } else if (i.call_number().empty_label && $scope.require_label) {
                         can_save = false;
                     }
+                    if(!i.call_number().owning_lib()){
+                        can_save = false;
+                    }
                 }
             );
 
@@ -1971,7 +1983,6 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             $scope.floating_list = list;
         });
         createSimpleUpdateWatcher('floating');
-
         createSimpleUpdateWatcher('circ_lib');
         createSimpleUpdateWatcher('circulate');
         createSimpleUpdateWatcher('holdable');
@@ -2007,7 +2018,6 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 if (typeof cnHash[cn_id].suffix() == 'object')
                     cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
             });
-
             if ($scope.only_vols) { // strip off copies when we're in vol-only mode
                 angular.forEach(cnHash, function (v, k) {
                     cnHash[k].copies([]);
@@ -2228,7 +2238,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                     });
                     if (!foundMatch) {
                         egCore.pcrud.search('acpt',
-                            { 
+                            {
                                 owner : egCore.org.fullPath(egCore.auth.user().ws_ou(), true),
                                 label : tagLabel,
                                 tag_type : $scope.tag_type
@@ -2480,13 +2490,13 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             
                         $scope.templates[n] = tmpl;
                         $scope.template_name_list = Object.keys($scope.templates).sort();
-            
-                        itemSvc.save_acp_templates($scope.templates);
+                       itemSvc.save_acp_templates($scope.templates);
                         $scope.$parent.fetchTemplates();
 
                         $scope.dirty = false;
                     } else {
                         // save all templates, as we might do after an import
+                        
                         itemSvc.save_acp_templates($scope.templates);
                         $scope.$parent.fetchTemplates();
                     }
@@ -2506,6 +2516,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                             angular.forEach(Object.keys(newTemplates), function (k) {
                                 $scope.templates[k] = newTemplates[k];
                             });
+                            
                             itemSvc.save_acp_templates($scope.templates);
                             $scope.fetchTemplates();
                         } catch (E) {
index 0fe9918..388ba88 100644 (file)
@@ -1112,9 +1112,6 @@ function($uibModal , $interpolate , egCore) {
                 }
             ).then(
                 function() {
-
-                    $scope.selecteName = '';
-
                     $scope.shortNames = egCore.org.list()
                     .filter(function(org) {
                         return !(
@@ -1132,6 +1129,7 @@ function($uibModal , $interpolate , egCore) {
                         if (orgId) {
                             var org = egCore.org.get(orgId);
                             if (org) {
+                                
                                 $scope.selected = org;
                                 $scope.selectedName = org.shortname();
                             }
@@ -1143,7 +1141,6 @@ function($uibModal , $interpolate , egCore) {
                         $scope.selected = org;
                         $scope.selectedName = org.shortname();
                     }
-    
                     fire_orgsel_onchange(); // no-op if nothing is selected
                     watch_external_changes();
                 }
@@ -1157,7 +1154,7 @@ function($uibModal , $interpolate , egCore) {
              * $scope.selected value during onchange.
              */
             function fire_orgsel_onchange() {
-                if (!$scope.selected || !$scope.onchange) return;
+                if ((!$scope.selected || !$scope.onchange)) return;
                 $timeout(function() {
                     console.debug(
                         'egOrgSelector onchange('+$scope.selected.id()+')');
@@ -1217,8 +1214,6 @@ function($uibModal , $interpolate , egCore) {
                     $scope.selected = egCore.org.list().filter(function(org) {
                         return org.shortname() === $scope.selectedName.trim()
                     })[0];
-                } else {
-                    $scope.selected = null;
                 }
                 if ($scope.selected && $scope.stickySetting) {
                     egCore.hatch.setLocalItem(
@@ -1233,10 +1228,8 @@ function($uibModal , $interpolate , egCore) {
             var dewatcher;
             function watch_external_changes() {
                 dewatcher = $scope.$watch('selected', function(newVal, oldVal) {
-                    if (newVal) {
+                    if (newVal && !$scope.orgIsDisabled(newVal.shortname())) {
                         $scope.selectedName = newVal.shortname();
-                    } else {
-                        $scope.selectedName = '';
                     }
                 });
             }