webstaff: consolidate code for generate new copies
authorGalen Charlton <gmc@esilibrary.com>
Wed, 27 Jan 2016 21:38:33 +0000 (16:38 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 2 Feb 2016 19:58:54 +0000 (14:58 -0500)
This patch does a bit of refactoring to get rid of
some copy-and-paste code that creates new copies
in the volume/copy editor.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 5ec7c28..2052e79 100644 (file)
@@ -250,6 +250,30 @@ function(egCore , $q) {
         );
     }
 
         );
     }
 
+    // create a new acp object with default values
+    // (both hard-coded and coming from OU settings)
+    service.generateNewCopy = function(callNumber, owningLib, isNew) {
+        var cp = new egCore.idl.acp();
+        cp.id( --service.new_cp_id );
+        if (isNew) {
+            cp.isnew( true );
+        }
+        cp.circ_lib( owningLib );
+        cp.call_number( callNumber );
+        cp.deposit(0);
+        cp.price(0);
+        cp.deposit_amount(0);
+        cp.fine_level(2); // Normal
+        cp.loan_duration(2); // Normal
+        cp.location(1); // Stacks
+        cp.circulate('t');
+        cp.holdable('t');
+        cp.opac_visible('t');
+        cp.ref('f');
+        cp.mint_condition('t');
+        return cp;
+    }
+
     return service;
 }])
 
     return service;
 }])
 
@@ -506,22 +530,10 @@ function(egCore , $q) {
 
                 $scope.changeCPCount = function () {
                     while ($scope.copy_count > $scope.copies.length) {
 
                 $scope.changeCPCount = function () {
                     while ($scope.copy_count > $scope.copies.length) {
-                        var cp = new egCore.idl.acp();
-                        cp.id( --itemSvc.new_cp_id );
-                        cp.isnew( true );
-                        cp.circ_lib( $scope.callNumber.owning_lib() );
-                        cp.call_number( $scope.callNumber );
-                        cp.deposit(0);
-                        cp.price(0);
-                        cp.deposit_amount(0);
-                        cp.fine_level(2); // Normal
-                        cp.loan_duration(2); // Normal
-                        cp.location(1); // Stacks
-                        cp.circulate('t');
-                        cp.holdable('t');
-                        cp.opac_visible('t');
-                        cp.ref('f');
-                        cp.mint_condition('t');
+                        var cp = itemSvc.generateNewCopy(
+                            $scope.callNumber,
+                            $scope.callNumber.owning_lib()
+                        );
                         $scope.copies.push( cp );
                         $scope.allcopies.push( cp );
 
                         $scope.copies.push( cp );
                         $scope.allcopies.push( cp );
 
@@ -639,25 +651,7 @@ function(egCore , $q) {
                             cn.owning_lib( $scope.owning_lib.id() );
                             cn.record( $scope.full_cn.record() );
 
                             cn.owning_lib( $scope.owning_lib.id() );
                             cn.record( $scope.full_cn.record() );
 
-                            var cp = new egCore.idl.acp();
-                            cp.call_number( cn );
-                            cp.id( --itemSvc.new_cp_id );
-                            cp.isnew( true );
-
-                            cp.deposit(0);
-                            cp.price(0);
-                            cp.deposit_amount(0);
-                            cp.fine_level(2); // Normal
-                            cp.loan_duration(2); // Normal
-                            cp.location(1); // Stacks
-                            cp.circulate('t');
-                            cp.holdable('t');
-                            cp.opac_visible('t');
-                            cp.ref('f');
-                            cp.mint_condition('t');
-
-                            cp.circ_lib( $scope.owning_lib.id() );
-                            cp.call_number( cn );
+                            var cp = itemSvc.generateNewCopy(cn, $scope.owning_lib.id());
 
                             $scope.struct[cn.id()] = [cp];
                             $scope.allcopies.push(cp);
 
                             $scope.struct[cn.id()] = [cp];
                             $scope.allcopies.push(cp);
@@ -1068,23 +1062,11 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                             if (proto.callnumber) {
                                 return egCore.pcrud.retrieve('acn', proto.callnumber)
                                 .then(function(cn) {
                             if (proto.callnumber) {
                                 return egCore.pcrud.retrieve('acn', proto.callnumber)
                                 .then(function(cn) {
-                                    var cp = new egCore.idl.acp();
-                                    cp.call_number( cn );
-                                    cp.id( --itemSvc.new_cp_id );
-                                    if (!$scope.only_vols) cp.isnew( true );
-                                    cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
-
-                                    cp.deposit(0);
-                                    cp.price(0);
-                                    cp.deposit_amount(0);
-                                    cp.fine_level(2); // Normal
-                                    cp.loan_duration(2); // Normal
-                                    cp.location(1); // Stacks
-                                    cp.circulate('t');
-                                    cp.holdable('t');
-                                    cp.opac_visible('t');
-                                    cp.ref('f');
-                                    cp.mint_condition('t');
+                                    var cp = new itemSvc.generateNewCopy(
+                                        cn,
+                                        proto.owner || egCore.auth.user().ws_ou(),
+                                        ((!$scope.only_vols) ? true : false)
+                                    );
 
                                     if (proto.barcode) cp.barcode( proto.barcode );
 
 
                                     if (proto.barcode) cp.barcode( proto.barcode );
 
@@ -1126,24 +1108,11 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                                     }
                                 });
 
                                     }
                                 });
 
-                                var cp = new egCore.idl.acp();
-                                cp.call_number( cn );
-                                cp.id( --itemSvc.new_cp_id );
-                                cp.isnew( true );
-
-                                cp.deposit(0);
-                                cp.price(0);
-                                cp.deposit_amount(0);
-                                cp.fine_level(2); // Normal
-                                cp.loan_duration(2); // Normal
-                                cp.location(1); // Stacks
-                                cp.circulate('t');
-                                cp.holdable('t');
-                                cp.opac_visible('t');
-                                cp.ref('f');
-                                cp.mint_condition('t');
-
-                                cp.circ_lib( proto.owner || egCore.auth.user().ws_ou() );
+                                var cp = new itemSvc.generateNewCopy(
+                                    cn,
+                                    proto.owner || egCore.auth.user().ws_ou()
+                                );
+
                                 if (proto.barcode) cp.barcode( proto.barcode );
 
                                 itemSvc.addCopy(cp)
                                 if (proto.barcode) cp.barcode( proto.barcode );
 
                                 itemSvc.addCopy(cp)