LP#1570091: webstaff: always check for duplciate barcodes
authorMike Rylander <mrylander@gmail.com>
Fri, 25 Mar 2016 20:30:02 +0000 (16:30 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 20 Apr 2016 14:51:32 +0000 (10:51 -0400)
... and disallow saving if critical data is missing

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2
Open-ILS/src/templates/staff/share/t_autogrid.tt2
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index e110bbf..95e8e50 100644 (file)
@@ -55,7 +55,7 @@
                         </div>
                     </div>
                     <div class="col-xs-2" ng-show="only_vols">
-                        <button class="btn btn-default center-block" ng-click="workingToComplete() && saveAndExit()" type="button">
+                        <button class="btn btn-default center-block" ng-disabled="disableSave()" ng-click="workingToComplete() && saveAndExit()" type="button">
                             <span ng-if="embedded">[% l('Save changes') %]</span>
                             <span ng-if="!embedded">[% l('Save & Exit') %]</span>
                         </button>
         
                           <eg-grid-menu-item handler="workingToComplete"
                            label="[% l('Store Selected') %]"></eg-grid-menu-item>
-                          <eg-grid-menu-item handler="workingSaveAndExit"
+                          <eg-grid-menu-item disabled="disableSave" handler="workingSaveAndExit"
                            label="[% l('Save & Exit') %]"></eg-grid-menu-item>
         
                         
                  <eg-grid-menu-item standalone="true" handler="completeToWorking"
                   label="[% l('Edit Selected') %]"></eg-grid-menu-item>
         
-                 <eg-grid-menu-item handler="saveAndContinue"
+                 <eg-grid-menu-item disabled="disableSave" handler="saveAndContinue"
                   label="[% l('Save Completed') %]"></eg-grid-menu-item>
-                 <eg-grid-menu-item handler="saveAndExit"
+                 <eg-grid-menu-item disabled="disableSave" handler="saveAndExit"
                   label="[% l('Save & Exit') %]"></eg-grid-menu-item>
         
                  <eg-grid-field label="[% l('Barcode') %]"     path='barcode' visible></eg-grid-field>
index 3ffd9f2..e96e2fb 100644 (file)
@@ -15,7 +15,7 @@
     </button>
     <ul class="dropdown-menu scrollable-menu">
       <li ng-repeat="item in menuItems | filter : { standalone : 'false' }" ng-class="{divider: item.divider}">
-        <a ng-if="!item.divider" href ng-disabled="item.disabled"
+        <a ng-if="!item.divider" href a-disabled="item.disabled()"
           ng-click="item.handler()">{{item.label}}</a>
       </li>
     </ul>
index ceedfb9..40efacc 100644 (file)
@@ -240,9 +240,9 @@ function(egCore , $q) {
         service.copies.push(cp);
     }
 
-    service.checkDuplicateBarcode = function(bc) {
+    service.checkDuplicateBarcode = function(bc, id) {
         var final = false;
-        return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc })
+        return egCore.pcrud.search('acp', { deleted : 'f', 'barcode' : bc, id : { '!=' : id } })
             .then(
                 function () { return final },
                 function () { return final },
@@ -281,6 +281,7 @@ function(egCore , $q) {
         cp.opac_visible('t');
         cp.ref('f');
         cp.mint_condition('t');
+        cp.empty_barcode = true;
 
         var status_setting = isFastAdd ?
             'cat.default_copy_status_fast' :
@@ -328,20 +329,20 @@ function(egCore , $q) {
                 $scope.duplicate_barcode_string = window.duplicate_barcode_string;
                 $scope.empty_barcode_string = window.empty_barcode_string;
 
+                if (!$scope.copy.barcode()) $scope.copy.empty_barcode = true;
+
                 $scope.nextBarcode = function (i) {
                     $scope.focusNext(i, $scope.barcode);
                 }
 
                 $scope.updateBarcode = function () {
                     if ($scope.barcode != '') {
-                        $scope.empty_barcode = false;
+                        $scope.copy.empty_barcode = $scope.empty_barcode = false;
                         $scope.barcode_has_error = !Boolean(itemSvc.checkBarcode($scope.barcode));
-                        if ($scope.copy.isnew()) {
-                            itemSvc.checkDuplicateBarcode($scope.barcode)
-                            .then(function (state) { $scope.duplicate_barcode = state });
-                        }
+                        itemSvc.checkDuplicateBarcode($scope.barcode, $scope.copy.id())
+                            .then(function (state) { $scope.copy.duplicate_barcode = $scope.duplicate_barcode = state });
                     } else {
-                        $scope.empty_barcode = true;
+                        $scope.copy.empty_barcode = $scope.empty_barcode = true;
                     }
                         
                     $scope.copy.barcode($scope.barcode);
@@ -427,6 +428,7 @@ function(egCore , $q) {
         controller : ['$scope','itemSvc','egCore',
             function ( $scope , itemSvc , egCore ) {
                 $scope.callNumber =  $scope.copies[0].call_number();
+                if (!$scope.callNumber.label()) $scope.callNumber.emtpy_label = true;
 
                 $scope.empty_label = false;
                 $scope.empty_label_string = window.empty_label_string;
@@ -557,9 +559,9 @@ function(egCore , $q) {
 
                 $scope.updateLabel = function () {
                     if ($scope.label == '') {
-                        $scope.empty_label = true;
+                        $scope.callNumber.empty_label = $scope.empty_label = true;
                     } else {
-                        $scope.empty_label = false;
+                        $scope.callNumber.empty_label = $scope.empty_label = false;
                     }
                     angular.forEach($scope.copies, function(cp) {
                         cp.call_number().label($scope.label);
@@ -1209,6 +1211,25 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             $scope.workingGridDataProvider.refresh();
         });
 
+        $scope.can_save = false;
+        function check_saveable () {
+            var can_save = true;
+            angular.forEach(
+                itemSvc.copies,
+                function (i) {
+                    if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
+                        can_save = false;
+                }
+            );
+
+            $scope.can_save = can_save;
+        }
+
+        $scope.disableSave = function () {
+            check_saveable();
+            return !$scope.can_save;
+        }
+
         $scope.focusNextFirst = function(prev_lib,prev_bc) {
             var n;
             var yep = false;