LP1929593 UPDATE_COPY_BARCODE permission
[evergreen-equinox.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
41                 egCore.net.request(
42                     'open-ils.cat',
43                     'open-ils.cat.update_copy_barcode',
44                     egCore.auth.token(), $scope.copyId, $scope.barcode2
45                 ).then(function(resp) {
46                     var evt = egCore.evt.parse(resp);
47                     if (evt) {
48                         console.log('toast 0 here 2', evt);
49                     } else {
50                         $scope.updateOK = true;
51                         $scope.focusBarcode = true;
52                     }
53                 });
54
55             });
56         });
57     }
58 }]);
59