]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/circ/services/transits.js
LP#1842940: add perm to permit staff to edit their own accounts in the client
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / circ / services / transits.js
1 /**
2  * Transits, yo
3  */
4
5 angular.module('egCoreMod')
6
7 .factory('egTransits',
8
9        ['$uibModal','$q','egCore','egConfirmDialog','egAlertDialog',
10 function($uibModal , $q , egCore , egConfirmDialog , egAlertDialog) {
11
12     var service = {};
13
14     service.abort_transits = function(transits,callback) {
15        
16         return $uibModal.open({
17             templateUrl : './circ/share/t_abort_transit_dialog',
18             backdrop: 'static',
19             controller : 
20                 ['$scope', '$uibModalInstance',
21                 function($scope, $uibModalInstance) {
22
23                     $scope.num_transits = transits.length;
24                     $scope.num_hold_transits = 0;
25                     angular.forEach(transits, function(t) {
26                         if (t['hold_transit_copy.hold.id']) {
27                             $scope.num_hold_transits++;
28                         }
29                     });
30                     
31                     $scope.cancel = function($event) {
32                         $uibModalInstance.dismiss();
33                         $event.preventDefault();
34                     }
35
36                     $scope.ok = function() {
37
38                         function abort_one() {
39                             var transit = transits.pop();
40                             if (!transit) {
41                                 $uibModalInstance.close();
42                                 return;
43                             }
44                             egCore.net.request(
45                                 'open-ils.circ', 'open-ils.circ.transit.abort',
46                                 egCore.auth.token(), { 'transitid' : transit['id'] }
47                             ).then(function(resp) {
48                                 if (evt = egCore.evt.parse(resp)) {
49                                     egCore.audio.play('warning.transit.abort_failed');
50                                     console.error('unable to abort transit: ' 
51                                         + evt.toString());
52                                 }
53                                 abort_one();
54                             });
55                         }
56
57                         abort_one();
58                     }
59                 }
60             ]
61         }).result.then(
62             function() {
63                 callback();
64             }
65         );
66     }
67
68     return service;
69 }])
70 ;