webstaff: Refactor replace-barcode to be reusable, and reuse it in holdings maint
authorMike Rylander <mrylander@gmail.com>
Wed, 9 Sep 2015 17:57:41 +0000 (13:57 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:21 +0000 (15:44 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/src/templates/staff/cat/item/replace_barcode/index.tt2
Open-ILS/src/templates/staff/cat/share/t_replace_barcode.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index c7a1142..6b79312 100644 (file)
@@ -67,6 +67,8 @@
       label="[% l('Copies') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsVolCopyEdit" group="[% l('Edit') %]"
       label="[% l('Volumes and Copies') %]"></eg-grid-action>
+    <eg-grid-action handler="replaceBarcodes" group="[% l('Edit') %]"
+      label="[% l('Replace Barcodes') %]"></eg-grid-action>
 
     <eg-grid-action handler="selectedHoldingsEmptyVolCopyDelete" group="[% l('Delete') %]" disabled="vols_not_shown"
       label="[% l('Empty Volumes') %]"></eg-grid-action>
index 6472a48..a81f7cd 100644 (file)
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/item/replace_barcode/app.js"></script>
 [% END %]
 
-<h2>[% l('Replace Item Barcode') %]</h2>
+[% INCLUDE 'staff/cat/share/t_replace_barcode.tt2' %]
 
-<div class="row">
-  <div class="col-md-6 pad-vert">
-    <form role="form" ng-submit="updateBarcode()">
-      <div class="form-group">
-        <label for="barcode1">[% l('Enter Original Barcode for Item') %]</label>
-        <input type="text" class="form-control" id="barcode1" required
-          ng-model="barcode1"
-          placeholder="[% l('Original Barcode...') %]" select-me="focusBarcode">
-      </div>
-      <div class="form-group">
-        <label for="barcode2">[% l('Enter New Barcode for Item') %]</label>
-        <input type="text" class="form-control" id="barcode2" 
-          ng-model="barcode2"
-          required placeholder="[% l('New Barcode...') %]">
-      </div>
-      <button type="submit" class="btn btn-default">[% l('Submit') %]</button>
-    </form>
-  </div>
-</div>
-
-<div class="row pad-vert">
-  <div class="col-md-6">
-    <div class="alert alert-danger" ng-if="copyNotFound">
-      [% l('Copy Not Found') %]
-    </div>
-    <div class="alert alert-success" ng-if="updateOK">
-      <span>[% l('Copy Updated') %]</span>
-      <span class="horiz-pad" ng-if="copyId">
-        <a href="./cat/item/{{copyId}}/summary" target="_self">
-          [% l('View Item Details') %]
-        </a>
-    </div>
-  </div>
-</div>
 [% END %]
diff --git a/Open-ILS/src/templates/staff/cat/share/t_replace_barcode.tt2 b/Open-ILS/src/templates/staff/cat/share/t_replace_barcode.tt2
new file mode 100644 (file)
index 0000000..83702a3
--- /dev/null
@@ -0,0 +1,45 @@
+<div>
+<div class="row ">
+  <div class="col-md-1"></div>
+  <div class="col-md-6">
+    <h2 class="center-block">[% l('Replace Item Barcode') %]</h2>
+  </div>
+</div>
+
+<div class="row pad-vert">
+  <div class="col-md-1"></div>
+  <div ng-class="{'col-md-6': !isModal, 'col-md-10': isModal}">
+    <form role="form" ng-submit="updateBarcode()">
+      <div class="form-group">
+        <label for="barcode1">[% l('Enter Original Barcode for Item') %]</label>
+        <input type="text" class="form-control" id="barcode1" required
+          ng-model="barcode1"
+          placeholder="[% l('Original Barcode...') %]" select-me="focusBarcode">
+      </div>
+      <div class="form-group">
+        <label for="barcode2">[% l('Enter New Barcode for Item') %]</label>
+        <input type="text" class="form-control" id="barcode2" select-me="focusBarcode2"
+          ng-model="barcode2"
+          required placeholder="[% l('New Barcode...') %]">
+      </div>
+      <button type="submit" class="btn btn-default">[% l('Submit') %]</button>
+      <button ng-if="isModal" class="btn btn-warning" ng-click="cancel($event)">[% l('Cancel') %]</button>
+    </form>
+  </div>
+</div>
+
+<div class="row pad-vert">
+  <div class="col-md-6">
+    <div class="alert alert-danger" ng-if="copyNotFound">
+      [% l('Copy Not Found') %]
+    </div>
+    <div class="alert alert-success" ng-if="updateOK">
+      <span>[% l('Copy Updated') %]</span>
+      <span class="horiz-pad" ng-if="copyId">
+        <a href="./cat/item/{{copyId}}/summary" target="_self">
+          [% l('View Item Details') %]
+        </a>
+    </div>
+  </div>
+</div>
+</div>
index 20fe682..8b84e23 100644 (file)
@@ -531,6 +531,63 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         });
     }
 
+    $scope.replaceBarcodes = function() {
+        var copy_list = gatherSelectedRawCopies();
+        if (copy_list.length == 0) return;
+
+        var holdingsGridDataProviderRef = $scope.holdingsGridDataProvider;
+
+        angular.forEach(copy_list, function (cp) {
+            $modal.open({
+                templateUrl: './cat/share/t_replace_barcode',
+                animation: true,
+                controller:
+                           ['$scope','$modalInstance',
+                    function($scope , $modalInstance) {
+                        $scope.isModal = true;
+                        $scope.focusBarcode = false;
+                        $scope.focusBarcode2 = true;
+                        $scope.barcode1 = cp.barcode();
+
+                        $scope.updateBarcode = function() {
+                            $scope.copyNotFound = false;
+                            $scope.updateOK = false;
+                
+                            egCore.pcrud.search('acp',
+                                {deleted : 'f', barcode : $scope.barcode1})
+                            .then(function(copy) {
+                
+                                if (!copy) {
+                                    $scope.focusBarcode = true;
+                                    $scope.copyNotFound = true;
+                                    return;
+                                }
+                
+                                $scope.copyId = copy.id();
+                                copy.barcode($scope.barcode2);
+                
+                                egCore.pcrud.update(copy).then(function(stat) {
+                                    $scope.updateOK = stat;
+                                    $scope.focusBarcode = true;
+                                    holdingsSvc.fetchAgain().then(function (){
+                                        holdingsGridDataProviderRef.refresh();
+                                    });
+                                });
+
+                            });
+                            $modalInstance.close();
+                        }
+
+                        $scope.cancel = function($event) {
+                            $modalInstance.dismiss();
+                            $event.preventDefault();
+                        }
+                    }
+                ]
+            });
+        });
+    }
+
     // refresh the list of holdings when the record_id is changed.
     $scope.holdings_record_id_changed = function(id) {
         if ($scope.record_id != id) $scope.record_id = id;
@@ -806,13 +863,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                 }
             ).then(function(success) {
                 if (success) {
-                    holdingsSvc.fetch({
-                        rid : $scope.record_id,
-                        org : $scope.holdings_ou,
-                        copy: $scope.holdings_show_copies,
-                        vol : $scope.holdings_show_vols,
-                        empty: $scope.holdings_show_empty
-                    }).then(function() {
+                    holdingsSvc.fetchAgain().then(function() {
                         $scope.holdingsGridDataProvider.refresh();
                     });
                 } else {
@@ -836,13 +887,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                 copy_list
             ).then(function(success) {
                 if (success) {
-                    holdingsSvc.fetch({
-                        rid : $scope.record_id,
-                        org : $scope.holdings_ou,
-                        copy: $scope.holdings_show_copies,
-                        vol : $scope.holdings_show_vols,
-                        empty: $scope.holdings_show_empty
-                    }).then(function() {
+                    holdingsSvc.fetchAgain().then(function() {
                         $scope.holdingsGridDataProvider.refresh();
                     });
                 } else {
@@ -877,13 +922,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
 
     $scope.selectedHoldingsDamaged = function () {
         egCirc.mark_damaged(gatherSelectedHoldingsIds()).then(function() {
-            holdingsSvc.fetch({
-                rid : $scope.record_id,
-                org : $scope.holdings_ou,
-                copy: $scope.holdings_show_copies,
-                vol : $scope.holdings_show_vols,
-                empty: $scope.holdings_show_empty
-            }).then(function() {
+            holdingsSvc.fetchAgain().then(function() {
                 $scope.holdingsGridDataProvider.refresh();
             });
         });
@@ -891,13 +930,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
 
     $scope.selectedHoldingsMissing = function () {
         egCirc.mark_missing(gatherSelectedHoldingsIds()).then(function() {
-            holdingsSvc.fetch({
-                rid : $scope.record_id,
-                org : $scope.holdings_ou,
-                copy: $scope.holdings_show_copies,
-                vol : $scope.holdings_show_vols,
-                empty: $scope.holdings_show_empty
-            }).then(function() {
+            holdingsSvc.fetchAgain().then(function() {
                 $scope.holdingsGridDataProvider.refresh();
             });
         });
@@ -1183,6 +1216,16 @@ function(egCore , $q) {
         }
     }
 
+    service.fetchAgain = function() {
+        return service.fetch({
+            rid: service.rid,
+            org: service.org,
+            copy: service.copy,
+            vol: service.vol,
+            empty: service.empty
+        })
+    }
+
     // resolved with the last received copy
     service.fetch = function(opts) {
         if (service.ongoing) {
@@ -1203,6 +1246,10 @@ function(egCore , $q) {
 
         service.rid = rid;
         service.org = org;
+        service.copy = opts.copy;
+        service.vol = opts.vol;
+        service.empty = opts.empty;
+
         service.copies = [];
         service.index = 0;