webstaff: circ audio alerts
[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             controller : 
19                 ['$scope', '$uibModalInstance',
20                 function($scope, $uibModalInstance) {
21
22                     $scope.num_transits = transits.length;
23                     $scope.num_hold_transits = 0;
24                     angular.forEach(transits, function(t) {
25                         if (t.hold_transit_copy()) {
26                             $scope.num_hold_transits++;
27                         }
28                     });
29                     
30                     $scope.cancel = function($event) {
31                         $uibModalInstance.dismiss();
32                         $event.preventDefault();
33                     }
34
35                     $scope.ok = function() {
36
37                         function abort_one() {
38                             var transit = transits.pop();
39                             if (!transit) {
40                                 $uibModalInstance.close();
41                                 return;
42                             }
43                             egCore.net.request(
44                                 'open-ils.circ', 'open-ils.circ.transit.abort',
45                                 egCore.auth.token(), { 'transitid' : transit.id() }
46                             ).then(function(resp) {
47                                 if (evt = egCore.evt.parse(resp)) {
48                                     egCore.audio.play('warning.transit.abort_failed');
49                                     console.error('unable to abort transit: ' 
50                                         + evt.toString());
51                                 }
52                                 abort_one();
53                             });
54                         }
55
56                         abort_one();
57                     }
58                 }
59             ]
60         }).result.then(
61             function() {
62                 callback();
63             }
64         );
65     }
66
67     return service;
68 }])
69 ;