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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
// Common Controller for the montage view
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console,ionic */
angular.module('zmApp.controllers').controller('ModalCtrl', ['$scope', '$rootScope', 'ZMDataModel', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', function ($scope, $rootScope, ZMDataModel, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate) {
console.log("**** INSIDE MODAL CTRL *****");
// This holds the PTZ menu control
// Note that I hacked radialMenu
// so please don't use the one you get from bower
//var imageStyle=1;
//$scope.imageAspect = "max-width: 100%;max-height: 100%;";
$scope.radialMenuOptions = {
content: '',
background: '#2F4F4F',
isOpen: false,
toggleOnClick: false,
button: {
cssClass: "fa fa-arrows-alt",
},
items: [
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Down');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'DownLeft');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Left');
}
},
{
content: 'D',
empty: true,
onclick: function () {
console.log('About');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'UpLeft');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Up');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'UpRight');
}
},
{
content: 'H',
empty: true,
onclick: function () {
console.log('About');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'Right');
}
},
{
content: '',
cssClass: 'fa fa-chevron-circle-up',
empty: false,
onclick: function () {
controlPTZ($scope.monitorId, 'DownRight');
}
},
{
content: 'K',
empty: true,
onclick: function () {
console.log('About');
}
},
]};
//-------------------------------------------------------------
// Send PTZ command to ZM
// Note: PTZ fails on desktop, don't bother about it
//-------------------------------------------------------------
function controlPTZ(monitorId, cmd) {
//curl -X POST "http://server.com/zm/index.php?view=request" -d
//"request=control&user=admin&passwd=xx&id=4&control=moveConLeft"
if (!$scope.ptzMoveCommand)
{
$ionicLoading.show({
template: "Not Ready for PTZ",
noBackdrop: true,
duration: 2000,
});
return;
}
console.log("Command value " + cmd + " with MID=" + monitorId);
$ionicLoading.hide();
$ionicLoading.show({
template: "please wait...",
noBackdrop: true,
duration: 15000,
});
var loginData = ZMDataModel.getLogin();
$ionicLoading.hide();
$ionicLoading.show({
template: "Sending PTZ..",
noBackdrop: true,
duration: 15000,
});
var req = $http({
method: 'POST',
/*timeout: 15000,*/
url: loginData.url + '/index.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var foo = str.join("&");
console.log("****RETURNING " + foo);
return foo;
},
// NOTE: Refer to
// zoneminder/skins/mobile/includes/control_functions.php
// for move commands
// logic - /zm/api/monitors/X.json, read ControlId = Y
// then zm/api/controls/Y.json
data: {
view: "request",
request: "control",
id: monitorId,
control: $scope.ptzMoveCommand + cmd,
xge: "30", //wtf
yge: "30", //wtf
}
});
req.success(function (resp) {
$ionicLoading.hide();
console.log("SUCCESS: " + JSON.stringify(resp));
// $ionicLoading.hide();
});
req.error(function (resp) {
$ionicLoading.hide();
console.log("ERROR: " + JSON.stringify(resp));
ZMDataModel.zmLog("Error sending PTZ:" + JSON.stringify(resp), "error");
});
}
$scope.finishedLoadingImage = function () {
console.log("***Monitor image FINISHED Loading***");
$ionicLoading.hide();
};
}]);
|