]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/item/replace_barcode/app.js
lp1890498: Replace Item Barcode now warns about duplicate barcode
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / item / replace_barcode / app.js
1 /**
2  * Item Display
3  */
4
5 angular.module('egItemReplaceBarcode', 
6     ['ngRoute', 'ui.bootstrap', 'egCoreMod','egUiMod'])
7
8 .controller('ReplaceItemBarcodeCtrl',
9        ['$scope','egCore',
10 function($scope , egCore) {
11     egCore.startup.go();
12
13     $scope.focusBarcode = true;
14
15     $scope.updateBarcode = function() {
16         $scope.copyNotFound = false;
17         $scope.duplicateBarcode = false;
18         $scope.updateOK = false;
19
20         egCore.pcrud.search('acp',
21             {deleted : 'f', barcode : $scope.barcode1})
22         .then(function(copy) {
23
24             if (!copy) {
25                 $scope.focusBarcode = true;
26                 $scope.copyNotFound = true;
27                 return;
28             }
29
30             egCore.pcrud.search('acp',
31                 {deleted : 'f', barcode : $scope.barcode2})
32             .then(function(newBarcodeCopy) {
33
34                 if (newBarcodeCopy) {
35                     $scope.duplicateBarcode = true;
36                     return;
37                 }
38
39                 $scope.copyId = copy.id();
40                 copy.barcode($scope.barcode2);
41
42                 egCore.pcrud.update(copy).then(function(stat) {
43                     $scope.updateOK = stat;
44                     $scope.focusBarcode = true;
45                 });
46             });
47         });
48     }
49 }]);
50