1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
angular.module('zmApp.controllers').controller('zmApp.EventServerSettingsCtrl', ['$scope','$ionicSideMenuDelegate', 'zm', '$stateParams','EventServer', '$ionicHistory', '$rootScope', '$state', 'message', 'ZMDataModel', function ($scope,$ionicSideMenuDelegate,zm, $stateParams, EventServer, $ionicHistory, $rootScope, $state, message, ZMDataModel) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
//----------------------------------------------------------------
// Alarm notification handling
//----------------------------------------------------------------
$scope.handleAlarms = function()
{
$rootScope.isAlarm=!$rootScope.isAlarm;
if (!$rootScope.isAlarm)
{
$rootScope.alarmCount="0";
$ionicHistory.nextViewOptions({disableBack: true});
$state.go("events", {"id": 0}, { reload: true });
}
};
$scope.$on('$ionicView.beforeLeave', function () {
ZMDataModel.zmDebug("Saving Event Server data");
var monstring="";
for (var i=0; i < $scope.monitors.length; i++)
{
if ($scope.monitors[i].Monitor.isChecked)
{
monstring = monstring + $scope.monitors[i].Monitor.Id+",";
}
}
if (monstring.charAt(monstring.length - 1) == ',')
monstring = monstring.substr(0, monstring.length - 1);
$scope.loginData.eventServerMonitors = monstring;
$scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? "1" : "0";
ZMDataModel.setLogin($scope.loginData);
console.log ("**** EVENT MONSTRING " + monstring);
if ($scope.loginData.isUseEventServer)
{
EventServer.init()
.then(function(data) {
console.log ("Sending control filter");
EventServer.sendMessage ("control", { type:'filter',monlist:monstring});
});
}
});
//-------------------------------------------------------------------------
// Controller Main
//------------------------------------------------------------------------
$scope.monitors = [];
$scope.monitors = message;
$scope.loginData = ZMDataModel.getLogin();
$scope.check = {
isUseEventServer: ""
};
$scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == '1') ? true : false;
var res = $scope.loginData.eventServerMonitors.split(",");
function isEnabled(id)
{
if ($scope.loginData.eventServerMonitors=="")
return true;
var isThere = false;
for (var i=0; i<res.length; i++)
{
if (res[i]==id)
{
isThere = true;
console.log ("isRes found: " + id);
break;
}
}
return isThere;
}
for (var i=0; i < $scope.monitors.length; i++)
{
if (!isEnabled($scope.monitors[i].Monitor.Id))
{
// if the filter list has IDs and this is not part of it, uncheck it
$scope.monitors[i].Monitor.isChecked = false;
console.log ("Marking false");
}
else
{
console.log ("Marking true");
$scope.monitors[i].Monitor.isChecked = true;
}
}
}]);
|