summaryrefslogtreecommitdiff
path: root/www/js/StateCtrl.js
diff options
context:
space:
mode:
authorPliable Pixels <pliablepixels@gmail.com>2016-11-18 09:28:08 -0500
committerPliable Pixels <pliablepixels@gmail.com>2016-11-18 09:28:08 -0500
commit31ca68739126f5740681238539a8c6a1b66e0000 (patch)
treeddd6317b70ae500f63a3231a0639c54a02129c20 /www/js/StateCtrl.js
parentcf93ca01f3d54fca62d4222f110c2a63b526badb (diff)
mass formatting and normalization - tweaked JSBeautify options
Diffstat (limited to 'www/js/StateCtrl.js')
-rw-r--r--www/js/StateCtrl.js195
1 files changed, 112 insertions, 83 deletions
diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js
index 58f13c4b..54a2c4c9 100644
--- a/www/js/StateCtrl.js
+++ b/www/js/StateCtrl.js
@@ -4,8 +4,9 @@
// controller for State View
-angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup', '$scope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout', '$ionicHistory', '$translate', function (
- $ionicPopup, $scope, zm, NVRDataModel, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope, $timeout, $ionicHistory, $translate) {
+angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup', '$scope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout', '$ionicHistory', '$translate', function(
+ $ionicPopup, $scope, zm, NVRDataModel, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope, $timeout, $ionicHistory, $translate)
+{
//----------------------------------------------------------------------
// Controller main
@@ -22,8 +23,6 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
$rootScope.zmPopup = "";
-
-
var loginData = NVRDataModel.getLogin();
var apiRun = loginData.apiurl + "/host/daemonCheck.json";
@@ -39,12 +38,14 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
// Let's stagger this by 500ms each to see if Chrome lets these through
// This may also help if your Apache is not configured to let multiple connections through
- $timeout(function () {
+ $timeout(function()
+ {
NVRDataModel.debug("invoking LoadStatus...");
getLoadStatus();
}, 2000);
- $timeout(function () {
+ $timeout(function()
+ {
NVRDataModel.debug("invoking CurrentState...");
getCurrentState();
}, 4000);
@@ -62,7 +63,8 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
// reset power state on exit as if it is called after we enter another
// state, that effectively overwrites current view power management needs
//------------------------------------------------------------------------
- $scope.$on('$ionicView.enter', function () {
+ $scope.$on('$ionicView.enter', function()
+ {
// console.log("**VIEW ** Montage Ctrl Entered");
NVRDataModel.setAwake(false);
});
@@ -71,19 +73,23 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
// This gets the current run state custom name
// if applicable
//---------------------------------------------------------
- function getCurrentState() {
+ function getCurrentState()
+ {
NVRDataModel.debug("StateCtrl: getting state using " + apiCurrentState);
$http.get(apiCurrentState)
.then(
- function (success) {
+ function(success)
+ {
NVRDataModel.debug("State results: " + JSON.stringify(success));
var customStateArray = success.data.states;
var i = 0;
var found = false;
$scope.allStateNames = [];
- for (i = 0; i < customStateArray.length; i++) {
+ for (i = 0; i < customStateArray.length; i++)
+ {
$scope.allStateNames.push(customStateArray[i].State.Name);
- if (customStateArray[i].State.IsActive == '1') {
+ if (customStateArray[i].State.IsActive == '1')
+ {
$scope.customState = customStateArray[i].State.Name;
found = true;
}
@@ -91,7 +97,8 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
if (!found) $scope.customState = "";
},
- function (error) {
+ function(error)
+ {
NVRDataModel.debug("StateCtrl: Error retrieving state list " + JSON.stringify(error));
$scope.customState = "";
@@ -100,21 +107,25 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
}
-
//----------------------------------------------------------------
// Alarm notification handling
//----------------------------------------------------------------
- $scope.handleAlarms = function () {
+ $scope.handleAlarms = function()
+ {
$rootScope.isAlarm = !$rootScope.isAlarm;
- if (!$rootScope.isAlarm) {
+ if (!$rootScope.isAlarm)
+ {
$rootScope.alarmCount = "0";
- $ionicHistory.nextViewOptions({
+ $ionicHistory.nextViewOptions(
+ {
disableBack: true
});
- $state.go("events", {
+ $state.go("events",
+ {
"id": 0,
- "playEvent":false
- }, {
+ "playEvent": false
+ },
+ {
reload: true
});
}
@@ -123,69 +134,78 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
//---------------------------------------------------------
// Allows the user to select a custom run state
//---------------------------------------------------------
- $scope.selectCustomState = function () {
+ $scope.selectCustomState = function()
+ {
$scope.myopt = {
selectedState: ""
};
//console.log(JSON.stringify($scope.allStateNames));
NVRDataModel.log("List of custom states: " + JSON.stringify($scope.allStateNames));
- $rootScope.zmPopup = $ionicPopup.show({
+ $rootScope.zmPopup = $ionicPopup.show(
+ {
scope: $scope,
template: '<ion-radio-fix ng-repeat="item in allStateNames" ng-value="item" ng-model="myopt.selectedState"> {{item}} </ion-radio-fix>',
-
title: $translate.instant('kSelectRunState'),
subTitle: $translate.instant('kCurrentState') + $scope.customState ? ($translate.instant('kCurrentState') + ": " + $scope.customState) : "",
buttons: [
+ {
+ text: $translate.instant('kButtonCancel'),
+ onTap: function(e)
{
- text: $translate.instant('kButtonCancel'),
- onTap: function (e) {
- return "CANCEL";
- }
+ return "CANCEL";
+ }
- },
+ },
+ {
+ text: $translate.instant('kButtonOk'),
+ onTap: function(e)
{
- text: $translate.instant('kButtonOk'),
- onTap: function (e) {
- return "OK";
+ return "OK";
- }
- }
- ]
+ }
+ }]
});
// It seems invoking a popup within a popup handler
// causes issues. Doing this outside due to that reason
- $rootScope.zmPopup.then(function (res) {
+ $rootScope.zmPopup.then(function(res)
+ {
// console.log("GOT : " + JSON.stringify(res));
- if (res == "OK") {
+ if (res == "OK")
+ {
if ($scope.myopt.selectedState != "")
controlZM($scope.myopt.selectedState);
}
});
};
-
//----------------------------------------------------------------------
// returns disk space in gigs taken up by events
//----------------------------------------------------------------------
- function getDiskStatus() {
+ function getDiskStatus()
+ {
NVRDataModel.debug("StateCtrl/getDiskStatus: " + apiDisk);
$http.get(apiDisk)
.then(
- function (success) {
+ function(success)
+ {
NVRDataModel.debug("StateCtrl/getDiskStatus: success");
NVRDataModel.debug("Disk results: " + JSON.stringify(success));
var obj = success.data.usage;
- if (obj.Total.space != undefined) {
+ if (obj.Total.space != undefined)
+ {
$scope.zmDisk = parseFloat(obj.Total.space).toFixed(1).toString() + "G";
- } else {
+ }
+ else
+ {
$scope.zmDisk = "unknown";
NVRDataModel.log("Error retrieving disk space, API returned null for obj.Total.space");
}
},
- function (error) {
+ function(error)
+ {
$scope.zmDisk = "unknown";
// console.log("ERROR:" + JSON.stringify(error));
NVRDataModel.log("Error retrieving DiskStatus: " + JSON.stringify(error), "error");
@@ -196,14 +216,17 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
//----------------------------------------------------------------------
// returns ZM running status
//----------------------------------------------------------------------
- function getRunStatus() {
+ function getRunStatus()
+ {
NVRDataModel.debug("StateCtrl/getRunStatus: " + apiRun);
$http.get(apiRun)
.then(
- function (success) {
+ function(success)
+ {
NVRDataModel.debug("StateCtrl/getRunStatus: success");
NVRDataModel.debug("Run results: " + JSON.stringify(success));
- switch (success.data.result) {
+ switch (success.data.result)
+ {
case 1:
$scope.zmRun = $translate.instant('kZMRunning');
$scope.color = 'color:green;';
@@ -219,10 +242,10 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
break;
}
-
// console.log("X"+success.data.result+"X");
},
- function (error) {
+ function(error)
+ {
//console.log("ERROR in getRun: " + JSON.stringify(error));
NVRDataModel.log("Error getting RunStatus " + JSON.stringify(error), "error");
$scope.color = 'color:red;';
@@ -232,25 +255,26 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
}
-
//----------------------------------------------------------------------
// gets ZM load - max[0], avg[1], min[2]
//----------------------------------------------------------------------
- function getLoadStatus() {
+ function getLoadStatus()
+ {
NVRDataModel.debug("StateCtrl/getLoadStatus: " + apiLoad);
$http.get(apiLoad)
.then(
- function (success) {
+ function(success)
+ {
NVRDataModel.debug("Load results: " + JSON.stringify(success));
//console.log(JSON.stringify(success));
// load returns 3 params - one in the middle is avg.
NVRDataModel.debug("StateCtrl/getLoadStatus: success");
$scope.zmLoad = success.data.load[1];
-
// console.log("X"+success.data.result+"X");
},
- function (error) {
+ function(error)
+ {
//console.log("ERROR in getLoad: " + JSON.stringify(error));
NVRDataModel.log("Error retrieving loadStatus " + JSON.stringify(error), "error");
$scope.zmLoad = 'undetermined';
@@ -258,17 +282,15 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
);
}
-
//----------------------------------------------------------------------
// start/stop/restart ZM
//----------------------------------------------------------------------
- function performZMoperation(str) {
-
+ function performZMoperation(str)
+ {
NVRDataModel.debug("inside performZMoperation with " + str);
-
$scope.zmRun = "...";
$scope.color = 'color:orange;';
$scope.customState = "";
@@ -276,10 +298,12 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
inProgress = 1;
$http.post(apiExec + str + ".json")
.then(
- function (success) {
+ function(success)
+ {
NVRDataModel.debug("StateCtrl/controlZM: returned success");
inProgress = 0;
- switch (str) {
+ switch (str)
+ {
case "stop":
$scope.zmRun = $translate.instant('kZMStopped');
$scope.color = 'color:red;';
@@ -293,7 +317,8 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
}
},
- function (error) {
+ function(error)
+ {
//if (error.status) // it seems to return error with status 0 if ok
// {
//console.log("ERROR in Change State:" + JSON.stringify(error));
@@ -306,11 +331,13 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
});
}
-
- function controlZM(str) {
- if (inProgress) {
+ function controlZM(str)
+ {
+ if (inProgress)
+ {
NVRDataModel.debug("StateCtrl/controlZM: operation in progress");
- $ionicPopup.alert({
+ $ionicPopup.alert(
+ {
title: $translate.instant('kOperationInProgressTitle'),
template: $translate.instant('kOperationInProgressBody') + '...'
});
@@ -320,43 +347,45 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
var statesearch = "startstoprestart";
var promptstring = $translate.instant('kStateAreYouSure') + str + ' Zoneminder?';
- if (statesearch.indexOf(str) == -1) {
+ if (statesearch.indexOf(str) == -1)
+ {
promptstring = "Are you sure you want to change state to " + str;
}
-
- $rootScope.zmPopup = $ionicPopup.show({
+ $rootScope.zmPopup = $ionicPopup.show(
+ {
title: 'Please Confirm',
template: promptstring,
buttons: [
+ {
+ text: 'Cancel',
+ type: 'button-positive'
+ },
+ {
+ text: 'Yes',
+ type: 'button-assertive',
+ onTap: function(e)
{
- text: 'Cancel',
- type: 'button-positive'
- },
- {
- text: 'Yes',
- type: 'button-assertive',
- onTap: function (e) {
- performZMoperation(str);
- }
+ performZMoperation(str);
}
- ]
+ }]
});
-
}
// Binder so template can call controlZM
- $scope.controlZM = function (str) {
+ $scope.controlZM = function(str)
+ {
controlZM(str);
};
-
- $scope.openMenu = function () {
+ $scope.openMenu = function()
+ {
$ionicSideMenuDelegate.toggleLeft();
};
- $scope.$on('$ionicView.leave', function () {
+ $scope.$on('$ionicView.leave', function()
+ {
console.log("**VIEW ** State Ctrl Left");
// FIXME not the best way...
// If the user exits a view before its complete,
@@ -364,8 +393,8 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
inProgress = 0;
});
-
- $scope.doRefresh = function () {
+ $scope.doRefresh = function()
+ {
console.log("***Pull to Refresh");
NVRDataModel.debug("StateCtrl/refresh: calling getRun/Load/Disk/CurrentState");
getRunStatus();
@@ -376,4 +405,4 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
};
-}]); \ No newline at end of file
+}]);