]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/statusbar.js
29968f910840b7c30a4daede2e77a1a803de03a1
[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         controller : [
19                     '$scope','$rootScope','egHatch',
20             function($scope , $rootScope , egHatch) {
21             $scope.messages = []; // keep a log of recent messages
22
23             $scope.netConnected = function() {
24                 // TODO: should should be abstracted through egNet
25                 return OpenSRF.websocketConnected();
26             }
27
28             // update the UI whenever we lose connection
29             OpenSRF.onWebSocketClosed = function() {
30                 $scope.$apply();
31             }
32
33             $scope.hatchConnected = function() {
34                 return egHatch.hatchAvailable;
35             }
36
37             // update the UI whenever we lose connection
38             egHatch.onHatchClose = function() {
39                 $scope.$apply();
40             }
41
42             // update the UI whenever we lose connection
43             egHatch.onHatchOpen = function() {
44                 $scope.$apply();
45             }
46
47             $scope.hatchConnect = function() {
48                 egHatch.hatchConnect();
49             }
50
51             $rootScope.$on('egStatusBarMessage', function(evt, args) {
52                 $scope.messages.unshift(args.message);
53
54                 // ensure the list does not exceed 10 messages
55                 // TODO: configurable?
56                 $scope.messages.splice(10, 1); 
57             });
58         }]
59     }
60 });