]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/statusbar.js
8c7d1162fad95253dded9cc9393aff9e0f1c1105
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / services / statusbar.js
1 /**
2  * egStatusBar
3  *
4  * Displays key information and messages to the user.
5  *
6  * Currently displays network connection status, egHatch connection
7  * status, and messages delivered via 
8  * $scope.$emit('egStatusBarMessage', msg)
9  */
10
11 angular.module('egCoreMod')
12
13 .directive('egStatusBar', function() {
14     return {
15         restrict : 'AE',
16         replace : true,
17         templateUrl : 'eg-status-bar-template',
18         scope : { },
19         controller : [
20                     '$scope','$rootScope','egHatch',
21             function($scope , $rootScope , egHatch) {
22             $scope.messages = []; // keep a log of recent messages
23
24             $scope.netConnected = function() {
25                 // TODO: should should be abstracted through egNet
26                 return OpenSRF.websocketConnected();
27             }
28
29             // update the UI whenever we lose connection
30             OpenSRF.onWebSocketClosed = function() {
31                 $scope.$apply();
32             }
33
34             $scope.hatchConnected = function() {
35                 return egHatch.hatchAvailable;
36             }
37
38             // update the UI whenever we lose connection
39             egHatch.onHatchClose = function() {
40                 $scope.$apply();
41             }
42
43             // update the UI whenever we lose connection
44             egHatch.onHatchOpen = function() {
45                 $scope.$apply();
46             }
47
48             $scope.hatchConnect = function() {
49                 egHatch.hatchConnect();
50             }
51
52             $rootScope.$on('egStatusBarMessage', function(evt, args) {
53                 $scope.messages.unshift(args);
54
55                 // ensure the list does not exceed 10 messages
56                 // TODO: configurable?
57                 $scope.messages.splice(10, 1); 
58             });
59         }]
60     }
61 });