diff options
Diffstat (limited to 'www/js')
| -rw-r--r-- | www/js/DataModel.js | 2 | ||||
| -rw-r--r-- | www/js/LoginCtrl.js | 24 | ||||
| -rw-r--r-- | www/js/MonitorCtrl.js | 836 | ||||
| -rw-r--r-- | www/js/MontageCtrl.js | 18 | ||||
| -rw-r--r-- | www/js/PortalLoginCtrl.js | 11 | ||||
| -rw-r--r-- | www/js/WizardCtrl.js | 606 | ||||
| -rw-r--r-- | www/js/app.js | 1 |
7 files changed, 782 insertions, 716 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 5602f7eb..28357500 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -66,7 +66,7 @@ angular.module('zmApp.controllers') 'pinCode': '', 'canSwipeMonitors': true, 'persistMontageOrder': false, - 'onTapScreen': 'events', + 'onTapScreen': $translate.instant('kTapEvents'), 'enableh264': true, 'gapless': false, 'montageOrder': '', diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index 63ac65e0..e67867fe 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -14,11 +14,11 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r $scope.loginData = ZMDataModel.getLogin(); $scope.check = { - isUseAuth: "", - isUseEventServer: "" + isUseAuth: false, + isUseEventServer: false }; - $scope.check.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false; + $scope.check.isUseAuth = ($scope.loginData.isUseAuth ) ? true : false; $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; //---------------------------------------------------------------- @@ -108,7 +108,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r console.log ("NEW LOGIN OBJECT IS " + JSON.stringify($scope.loginData)); - $scope.check.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false; + $scope.check.isUseAuth = ($scope.loginData.isUseAuth) ? true : false; $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; ZMDataModel.zmDebug("Retrieved state for this profile:" + JSON.stringify($scope.loginData)); @@ -217,11 +217,17 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r { $scope.loginData.username = $rootScope.wizard.zmuser; $scope.loginData.password = $rootScope.wizard.zmpassword; - if ((/^https:\/\//i.test($scope.loginData.url))) - { - $scope.loginData.useSSL = true; - } } + else + { + $scope.loginData.isUseAuth = false; + } + + if ((/^https:\/\//i.test($scope.loginData.url))) + { + $scope.loginData.useSSL = true; + } + } @@ -385,7 +391,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r - $scope.loginData.isUseAuth = ($scope.check.isUseAuth) ? "1" : "0"; + $scope.loginData.isUseAuth = ($scope.check.isUseAuth) ? true:false; $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? true : false; if ($scope.loginData.url.slice(-1) == '/') { diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index ab3631aa..42683717 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -6,453 +6,491 @@ // refer to comments in EventCtrl for the modal stuff. They are almost the same angular.module('zmApp.controllers') - .controller('zmApp.MonitorCtrl', ['$ionicPopup', 'zm', '$scope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout','$ionicHistory', '$ionicPlatform', '$translate', + .controller('zmApp.MonitorCtrl', ['$ionicPopup', 'zm', '$scope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout', '$ionicHistory', '$ionicPlatform', '$translate', function ($ionicPopup, zm, $scope, ZMDataModel, message, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope, $timeout, $ionicHistory, $ionicPlatform, $translate) { - //----------------------------------------------------------------------- - // Controller Main - //----------------------------------------------------------------------- - - // var isModalOpen = false; - - // console.log("***EVENTS: Waiting for Monitors to load before I proceed"); - $scope.monitors = []; - $scope.monitors = message; - - - - - if ($scope.monitors.length == 0) - { - $rootScope.zmPopup= $ionicPopup.alert({ - title: $translate.instant('kNoMonitors'), - template: $translate.instant('kPleaseCheckCredentials') - }); - $ionicHistory.nextViewOptions({ - disableBack: true - }); - $state.go("login" ,{"wizard": false}); - return; - } - - var loginData = ZMDataModel.getLogin(); - monitorStateCheck(); - //console.log("Setting Awake to " + ZMDataModel.getKeepAwake()); - ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); - - // FIXME: need this as modalctrl uses it. Not needed for monitor - // mode - - - // -------------------------------------------------------- - // Handling of back button in case modal is open should - // close the modal - // -------------------------------------------------------- - - $ionicPlatform.registerBackButtonAction(function (e) { - e.preventDefault(); - if ($scope.modal.isShown()) - { - // switch off awake, as liveview is finished - ZMDataModel.zmDebug("Modal is open, closing it"); - ZMDataModel.setAwake(false); - $scope.modal.remove(); - } - else - { - ZMDataModel.zmDebug("Modal is closed, so toggling or exiting"); - if (!$ionicSideMenuDelegate.isOpenLeft()) - { - $ionicSideMenuDelegate.toggleLeft(); - - } - else - { - navigator.app.exitApp(); + //----------------------------------------------------------------------- + // Controller Main + //----------------------------------------------------------------------- + + // var isModalOpen = false; + + // console.log("***EVENTS: Waiting for Monitors to load before I proceed"); + + + + var loginData; + + + + // -------------------------------------------------------- + // Handling of back button in case modal is open should + // close the modal + // -------------------------------------------------------- + + $ionicPlatform.registerBackButtonAction(function (e) { + e.preventDefault(); + if ($scope.modal.isShown()) { + // switch off awake, as liveview is finished + ZMDataModel.zmDebug("Modal is open, closing it"); + ZMDataModel.setAwake(false); + $scope.modal.remove(); + } else { + ZMDataModel.zmDebug("Modal is closed, so toggling or exiting"); + if (!$ionicSideMenuDelegate.isOpenLeft()) { + $ionicSideMenuDelegate.toggleLeft(); + + } else { + navigator.app.exitApp(); + } + } - - } - - }, 1000); - - - - - $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 }); - } - }; - //----------------------------------------------------------------------- - // This function takes care of changing monitor parameters - // For now, I've only limited it to enable/disable and change monitor mode - // and changing monitor function - //----------------------------------------------------------------------- - $scope.changeConfig = function (monitorName, monitorId, enabled, func) { - var checked = false; - //console.log("called with " + monitorId + ":" + enabled + ":" + func); - if (enabled == '1') checked = true; - - $scope.monFunctions = [ - { - text: $translate.instant('kMonModect'), - value: "Modect" + + }, 1000); + + + + + $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 + }); + } + }; + //----------------------------------------------------------------------- + // This function takes care of changing monitor parameters + // For now, I've only limited it to enable/disable and change monitor mode + // and changing monitor function + //----------------------------------------------------------------------- + $scope.changeConfig = function (monitorName, monitorId, enabled, func) { + var checked = false; + //console.log("called with " + monitorId + ":" + enabled + ":" + func); + if (enabled == '1') checked = true; + + $scope.monFunctions = [ + { + text: $translate.instant('kMonModect'), + value: "Modect" }, - { - text: $translate.instant('kMonMocord'), - value: "Mocord" + { + text: $translate.instant('kMonMocord'), + value: "Mocord" }, - { - text: $translate.instant('kMonRecord'), - value: "Record" + { + text: $translate.instant('kMonRecord'), + value: "Record" }, - { - text:$translate.instant('kMonNodect'), - value: "Nodect" + { + text: $translate.instant('kMonNodect'), + value: "Nodect" }, - { - text: $translate.instant('kMonMonitor'), - value: "Monitor" + { + text: $translate.instant('kMonMonitor'), + value: "Monitor" }, - { - text: $translate.instant('kMonNone'), - value: "None" + { + text: $translate.instant('kMonNone'), + value: "None" } ]; - $scope.monfunc = { - myfunc: func, - myenabled: checked - }; + $scope.monfunc = { + myfunc: func, + myenabled: checked + }; - $rootScope.zmPopup = $ionicPopup.show({ - scope: $scope, - template: '<ion-toggle ng-model="monfunc.myenabled" ng-checked="monfunc.myenabled" toggle-class="toggle-calm">Enabled</ion-toggle><ion-radio-fix ng-repeat="item in monFunctions" ng-value="item.value" ng-model="monfunc.myfunc"> {{item.text}} </ion-radio-fix>', + $rootScope.zmPopup = $ionicPopup.show({ + scope: $scope, + template: '<ion-toggle ng-model="monfunc.myenabled" ng-checked="monfunc.myenabled" toggle-class="toggle-calm">Enabled</ion-toggle><ion-radio-fix ng-repeat="item in monFunctions" ng-value="item.value" ng-model="monfunc.myfunc"> {{item.text}} </ion-radio-fix>', - title: $translate.instant('kChangeSettingsFor') + ' '+monitorName, + title: $translate.instant('kChangeSettingsFor') + ' ' + monitorName, - buttons: [ - { - text: $translate.instant('kButtonCancel'), + buttons: [ + { + text: $translate.instant('kButtonCancel'), }, - { - text:$translate.instant('kButtonSave'), - onTap: function (e) { + { + text: $translate.instant('kButtonSave'), + onTap: function (e) { - ZMDataModel.zmDebug("MonitorCtrl:changeConfig selection:" + $scope.monfunc.myenabled + - $scope.monfunc.myfunc); - var loginData = ZMDataModel.getLogin(); - var apiRestart = loginData.apiurl + "/states/change/restart.json"; - var apiMon = loginData.apiurl + "/monitors/" + monitorId + ".json"; + ZMDataModel.zmDebug("MonitorCtrl:changeConfig selection:" + $scope.monfunc.myenabled + + $scope.monfunc.myfunc); + var loginData = ZMDataModel.getLogin(); + var apiRestart = loginData.apiurl + "/states/change/restart.json"; + var apiMon = loginData.apiurl + "/monitors/" + monitorId + ".json"; - ZMDataModel.zmDebug("MonitorCtrl: URLs for changeConfig save:" + apiMon); + ZMDataModel.zmDebug("MonitorCtrl: URLs for changeConfig save:" + apiMon); - var isEnabled = ""; - isEnabled = ($scope.monfunc.myenabled == true) ? '1' : '0'; - - $ionicLoading.show({ - template:$translate.instant('kApplyingChanges')+"...", - noBackdrop: true, - duration: zm.largeHttpTimeout, - }); + var isEnabled = ""; + isEnabled = ($scope.monfunc.myenabled == true) ? '1' : '0'; - $http({ - url: apiMon, - method: 'post', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': '*/*', - }, - 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); - ZMDataModel.zmDebug("MonitorCtrl: parmeters constructed: " + foo); - return foo; - }, - data: { - 'Monitor[Function]': $scope.monfunc.myfunc, - 'Monitor[Enabled]': isEnabled, - } - - }) - - // I am not restarting ZM after monitor change - - .success(function () { - $ionicLoading.hide(); - ZMDataModel.zmDebug("MonitorCtrl: Not restarting ZM - Make sure you have the patch installed in MonitorsController.php or this won't work"); - doRefresh(); - /* ZMDataModel.zmDebug ("MonitorCtrl: Restarting ZM"); - $ionicLoading.show({ - template: "Successfully changed Monitor. Please wait, restarting ZoneMinder...", - noBackdrop: true, - duration: zm.largeHttpTimeout, - }); - $http.post(apiRestart) - .then(function (success) { - $ionicLoading.hide(); - var refresh = ZMDataModel.getMonitors(1); - refresh.then(function (data) { - $scope.monitors = data; - $scope.$broadcast('scroll.refreshComplete'); - }); - - }, - function (error) { - $ionicLoading.hide(); - - } - );*/ - - }) - .error(function (data, status, headers, config) { - ZMDataModel.zmDebug("MonitorCtrl: Error changing monitor " + JSON.stringify(data)); - $ionicLoading.hide(); $ionicLoading.show({ - template: $translate.instant('kErrorChangingMonitors')+"...", + template: $translate.instant('kApplyingChanges') + "...", noBackdrop: true, - duration: 3000, + duration: zm.largeHttpTimeout, }); - }); - } + $http({ + url: apiMon, + method: 'post', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': '*/*', + }, + 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); + ZMDataModel.zmDebug("MonitorCtrl: parmeters constructed: " + foo); + return foo; + }, + data: { + 'Monitor[Function]': $scope.monfunc.myfunc, + 'Monitor[Enabled]': isEnabled, + } + + }) + + // I am not restarting ZM after monitor change + + .success(function () { + $ionicLoading.hide(); + ZMDataModel.zmDebug("MonitorCtrl: Not restarting ZM - Make sure you have the patch installed in MonitorsController.php or this won't work"); + doRefresh(); + /* ZMDataModel.zmDebug ("MonitorCtrl: Restarting ZM"); + $ionicLoading.show({ + template: "Successfully changed Monitor. Please wait, restarting ZoneMinder...", + noBackdrop: true, + duration: zm.largeHttpTimeout, + }); + $http.post(apiRestart) + .then(function (success) { + $ionicLoading.hide(); + var refresh = ZMDataModel.getMonitors(1); + refresh.then(function (data) { + $scope.monitors = data; + $scope.$broadcast('scroll.refreshComplete'); + }); + + }, + function (error) { + $ionicLoading.hide(); + + } + );*/ + + }) + .error(function (data, status, headers, config) { + ZMDataModel.zmDebug("MonitorCtrl: Error changing monitor " + JSON.stringify(data)); + $ionicLoading.hide(); + $ionicLoading.show({ + template: $translate.instant('kErrorChangingMonitors') + "...", + noBackdrop: true, + duration: 3000, + }); + }); + + } }, ] - }); - - }; - - - - // same logic as EventCtrl.js - $scope.finishedLoadingImage = function () { - // console.log("***Monitor image FINISHED Loading***"); - $ionicLoading.hide(); - }; - - - $scope.$on('$ionicView.loaded', function () { - // console.log("**VIEW ** Monitor Ctrl Loaded"); - }); - - - - - - //------------------------------------------------------------------------- - // Lets make sure we set screen dim properly as we enter - // The problem is we enter other states before we leave previous states - // from a callback perspective in ionic, so we really can't predictably - // 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 () { - // console.log("**VIEW ** Monitor Ctrl Entered"); - ZMDataModel.setAwake(false); - $ionicSideMenuDelegate.canDragContent(true); - $scope.areImagesLoading = true; - }); - - $scope.$on('$ionicView.leave', function () { - // console.log("**VIEW ** Monitor Ctrl Left, force removing modal"); - if ($scope.modal) $scope.modal.remove(); - }); - - $scope.$on('$ionicView.unloaded', function () { - // console.log("**VIEW ** Monitor Ctrl Unloaded"); - }); - - $scope.openModal = function (mid, controllable, controlid, connKey, monitor) { - ZMDataModel.zmDebug("MonitorCtrl:Open Monitor Modal with monitor Id=" + mid + - " and Controllable:" + controllable + " with control ID:" + controlid); - - - $scope.monitor = monitor; - //console.log (">>>>>>>>>>>> MONITOR CRL " + $scope.monitor. - $scope.monitorId = mid; - $scope.monitorName = ZMDataModel.getMonitorName(mid); - $scope.LoginData = ZMDataModel.getLogin(); - $scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; - $scope.refMonitor = monitor; - ZMDataModel.zmLog("Monitor Orientation is: " + $scope.orientation); - $rootScope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; - - - - $scope.showPTZ = false; - $scope.monitorId = mid; - $scope.monitorName = ZMDataModel.getMonitorName(mid); - $scope.controlid = controlid; - - $scope.LoginData = ZMDataModel.getLogin(); - $rootScope.modalRand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; - $scope.ptzMoveCommand = ""; - $scope.ptzStopCommand = ""; - - $scope.zoomInCommand = ""; - $scope.zoomOutCommand = ""; - $scope.zoomStopCommand = "zoomStop"; - $scope.canZoom = false; - - $scope.presetOn = false; - - $scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); - $scope.isControllable = controllable; - - - // This is a modal to show the monitor footage - // We need to switch to always awake if set so the feed doesn't get interrupted - ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); - - - - $ionicModal.fromTemplateUrl('templates/monitors-modal.html', { - scope: $scope, - animation: 'slide-in-up' - }) - .then(function (modal) { - $scope.modal = modal; - - $ionicLoading.show({ - template: $translate.instant('kPleaseWait')+"...", - noBackdrop: true, - duration: zm.loadingTimeout }); - $scope.isModalActive = true; - $scope.modal.show(); + + }; + + + + // same logic as EventCtrl.js + $scope.finishedLoadingImage = function () { + // console.log("***Monitor image FINISHED Loading***"); + $ionicLoading.hide(); + }; + + + $scope.$on('$ionicView.loaded', function () { + // console.log("**VIEW ** Monitor Ctrl Loaded"); + }); + + + + + + //------------------------------------------------------------------------- + // Lets make sure we set screen dim properly as we enter + // The problem is we enter other states before we leave previous states + // from a callback perspective in ionic, so we really can't predictably + // 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 () { + // console.log("**VIEW ** Monitor Ctrl Entered"); + ZMDataModel.setAwake(false); + $ionicSideMenuDelegate.canDragContent(true); + $scope.areImagesLoading = true; }); - }; - - $scope.closeModal = function () { - // console.log("Close & Destroy Monitor Modal"); - - // stop networking -nph-zms keeps sucking data - - // switch off awake, as liveview is finished - ZMDataModel.setAwake(false); - $scope.modal.remove(); - $timeout (function() {ZMDataModel.zmLog("MonitorCtrl:Stopping network pull...");if (ZMDataModel.isForceNetworkStop()) ZMDataModel.stopNetwork("MonitorCtrl-closeModal");},300); - - - }; - //Cleanup the modal when we're done with it! - $scope.$on('$destroy', function () { - //console.log("Destroy Monitor Modal"); - $scope.modal.remove(); - }); - - - - - //----------------------------------------------------------------------- - // Controller Main - //----------------------------------------------------------------------- - - - function monitorStateCheck() { - var apiMonCheck; - - // The status is provided by zmdc.pl - // "not running", "pending", "running since", "Unable to connect" - var i; - for (i = 0; i < $scope.monitors.length; i++) { - (function (j) { - $scope.monitors[j].Monitor.isRunningText = "..."; - $scope.monitors[j].Monitor.isRunning = "..."; - $scope.monitors[j].Monitor.color = zm.monitorCheckingColor; - $scope.monitors[j].Monitor.char = "ion-checkmark-circled"; - apiMonCheck = loginData.apiurl + "/monitors/daemonStatus/id:" + $scope.monitors[j].Monitor.Id + "/daemon:zmc.json"; - - - //apiMonCheck = apiMonCheck.replace(loginData.url, $scope.monitors[j].Monitor.baseURL); - - - // in multiserver replace apiurl with baseurl - - - ZMDataModel.zmDebug("MonitorCtrl:monitorStateCheck: " + apiMonCheck); - //console.log("**** ZMC CHECK " + apiMonCheck); - $http.get(apiMonCheck) - .success(function (data) { - ZMDataModel.zmDebug("MonitorCtrl: monitor check state returned: " + JSON.stringify(data)); - if (data.statustext.indexOf("not running") > -1) { - $scope.monitors[j].Monitor.isRunning = "false"; - $scope.monitors[j].Monitor.color = zm.monitorNotRunningColor; - $scope.monitors[j].Monitor.char = "ion-close-circled"; - } else if (data.statustext.indexOf("pending") > -1) { - $scope.monitors[j].Monitor.isRunning = "pending"; - $scope.monitors[j].Monitor.color = zm.monitorPendingColor; - } else if (data.statustext.indexOf("running since") > -1) { - $scope.monitors[j].Monitor.isRunning = "true"; - $scope.monitors[j].Monitor.color = zm.monitorRunningColor; - } else if (data.statustext.indexOf("Unable to connect") > -1) { - $scope.monitors[j].Monitor.isRunning = "false"; - $scope.monitors[j].Monitor.color = zm.monitorNotRunningColor; - $scope.monitors[j].Monitor.char = "ion-close-circled"; + + $scope.$on('$ionicView.afterEnter', function () { + // console.log("**VIEW ** Monitor Ctrl Entered"); + $scope.monitors = []; + $scope.monitors = message; + + + + + if ($scope.monitors.length == 0) { + $rootScope.zmPopup = $ionicPopup.alert({ + title: $translate.instant('kNoMonitors'), + template: $translate.instant('kPleaseCheckCredentials') + }); + $ionicHistory.nextViewOptions({ + disableBack: true + }); + $state.go("login", { + "wizard": false + }); + return; + } + + loginData = ZMDataModel.getLogin(); + monitorStateCheck(); + //console.log("Setting Awake to " + ZMDataModel.getKeepAwake()); + ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); + // Now lets see if we need to load live screen + + // $rootScope.tappedMid = 1; + if ($rootScope.tappedMid != 0) { + ZMDataModel.zmLog("Notification tapped, we need to go to monitor " + $rootScope.tappedMid); + + var tm = $rootScope.tappedMid; + $rootScope.tappedMid = 0; + var monitem; + for (var m = 0; m < $scope.monitors.length; m++) { + if ($scope.monitors[m].Monitor.Id == tm) { + monitem = $scope.monitors[m]; + break; } + } + + openModal(monitem.Monitor.Id, monitem.Monitor.Controllable, monitem.Monitor.ControlId, monitem.Monitor.connKey, monitem); + } + + + }); + + + $scope.$on('$ionicView.leave', function () { + // console.log("**VIEW ** Monitor Ctrl Left, force removing modal"); + if ($scope.modal) $scope.modal.remove(); + }); + + $scope.$on('$ionicView.unloaded', function () { + // console.log("**VIEW ** Monitor Ctrl Unloaded"); + }); + + + $scope.openModal = function (mid, controllable, controlid, connKey, monitor) { + + openModal(mid, controllable, controlid, connKey, monitor); + + }; + + function openModal(mid, controllable, controlid, connKey, monitor) { + ZMDataModel.zmDebug("MonitorCtrl:Open Monitor Modal with monitor Id=" + mid + + " and Controllable:" + controllable + " with control ID:" + controlid); + + + $scope.monitor = monitor; + //console.log (">>>>>>>>>>>> MONITOR CRL " + $scope.monitor. + $scope.monitorId = mid; + $scope.monitorName = ZMDataModel.getMonitorName(mid); + $scope.LoginData = ZMDataModel.getLogin(); + $scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; + $scope.refMonitor = monitor; + ZMDataModel.zmLog("Monitor Orientation is: " + $scope.orientation); + $rootScope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; - $scope.monitors[j].Monitor.isRunningText = data.statustext; + + + $scope.showPTZ = false; + $scope.monitorId = mid; + $scope.monitorName = ZMDataModel.getMonitorName(mid); + $scope.controlid = controlid; + + $scope.LoginData = ZMDataModel.getLogin(); + $rootScope.modalRand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111; + $scope.ptzMoveCommand = ""; + $scope.ptzStopCommand = ""; + + $scope.zoomInCommand = ""; + $scope.zoomOutCommand = ""; + $scope.zoomStopCommand = "zoomStop"; + $scope.canZoom = false; + + $scope.presetOn = false; + + $scope.connKey = (Math.floor((Math.random() * 999999) + 1)).toString(); + $scope.isControllable = controllable; + + + // This is a modal to show the monitor footage + // We need to switch to always awake if set so the feed doesn't get interrupted + ZMDataModel.setAwake(ZMDataModel.getKeepAwake()); + + + + $ionicModal.fromTemplateUrl('templates/monitors-modal.html', { + scope: $scope, + animation: 'slide-in-up' }) - .error(function (data) { - ZMDataModel.zmDebug("MonitorCtrl: Error->monitor check state returned: " + - JSON.stringify(data)); - ZMDataModel.displayBanner('error', [$translate.instant('kErrorRetrievingState'), $translate.instant('kPleaseTryAgain')]); - $scope.monitors[j].Monitor.isRunning = "error"; - $scope.monitors[j].Monitor.color = zm.monitorErrorColor; - $scope.monitors[j].Monitor.char = "ion-help-circled"; + .then(function (modal) { + $scope.modal = modal; + + $ionicLoading.show({ + template: $translate.instant('kPleaseWait') + "...", + noBackdrop: true, + duration: zm.loadingTimeout + }); + $scope.isModalActive = true; + $scope.modal.show(); }); + } - })(i); - } - } + $scope.closeModal = function () { + // console.log("Close & Destroy Monitor Modal"); + // stop networking -nph-zms keeps sucking data - function doRefresh() { - $scope.monitors = []; + // switch off awake, as liveview is finished + ZMDataModel.setAwake(false); + $scope.modal.remove(); + $timeout(function () { + ZMDataModel.zmLog("MonitorCtrl:Stopping network pull..."); + if (ZMDataModel.isForceNetworkStop()) ZMDataModel.stopNetwork("MonitorCtrl-closeModal"); + }, 300); + + + }; + //Cleanup the modal when we're done with it! + $scope.$on('$destroy', function () { + //console.log("Destroy Monitor Modal"); + $scope.modal.remove(); + }); + + + + + //----------------------------------------------------------------------- + // Controller Main + //----------------------------------------------------------------------- + + + function monitorStateCheck() { + var apiMonCheck; + + // The status is provided by zmdc.pl + // "not running", "pending", "running since", "Unable to connect" + var i; + for (i = 0; i < $scope.monitors.length; i++) { + (function (j) { + $scope.monitors[j].Monitor.isRunningText = "..."; + $scope.monitors[j].Monitor.isRunning = "..."; + $scope.monitors[j].Monitor.color = zm.monitorCheckingColor; + $scope.monitors[j].Monitor.char = "ion-checkmark-circled"; + apiMonCheck = loginData.apiurl + "/monitors/daemonStatus/id:" + $scope.monitors[j].Monitor.Id + "/daemon:zmc.json"; + + + //apiMonCheck = apiMonCheck.replace(loginData.url, $scope.monitors[j].Monitor.baseURL); - var refresh = ZMDataModel.getMonitors(1); - refresh.then(function (data) { - $scope.monitors = data; - monitorStateCheck(); - $scope.$broadcast('scroll.refreshComplete'); - }); - } + // in multiserver replace apiurl with baseurl + + + ZMDataModel.zmDebug("MonitorCtrl:monitorStateCheck: " + apiMonCheck); + //console.log("**** ZMC CHECK " + apiMonCheck); + $http.get(apiMonCheck) + .success(function (data) { + ZMDataModel.zmDebug("MonitorCtrl: monitor check state returned: " + JSON.stringify(data)); + if (data.statustext.indexOf("not running") > -1) { + $scope.monitors[j].Monitor.isRunning = "false"; + $scope.monitors[j].Monitor.color = zm.monitorNotRunningColor; + $scope.monitors[j].Monitor.char = "ion-close-circled"; + } else if (data.statustext.indexOf("pending") > -1) { + $scope.monitors[j].Monitor.isRunning = "pending"; + $scope.monitors[j].Monitor.color = zm.monitorPendingColor; + } else if (data.statustext.indexOf("running since") > -1) { + $scope.monitors[j].Monitor.isRunning = "true"; + $scope.monitors[j].Monitor.color = zm.monitorRunningColor; + } else if (data.statustext.indexOf("Unable to connect") > -1) { + $scope.monitors[j].Monitor.isRunning = "false"; + $scope.monitors[j].Monitor.color = zm.monitorNotRunningColor; + $scope.monitors[j].Monitor.char = "ion-close-circled"; + } + + + $scope.monitors[j].Monitor.isRunningText = data.statustext; + }) + .error(function (data) { + ZMDataModel.zmDebug("MonitorCtrl: Error->monitor check state returned: " + + JSON.stringify(data)); + ZMDataModel.displayBanner('error', [$translate.instant('kErrorRetrievingState'), $translate.instant('kPleaseTryAgain')]); + $scope.monitors[j].Monitor.isRunning = "error"; + $scope.monitors[j].Monitor.color = zm.monitorErrorColor; + $scope.monitors[j].Monitor.char = "ion-help-circled"; + }); + + + })(i); + } + } + + + function doRefresh() { + $scope.monitors = []; + + var refresh = ZMDataModel.getMonitors(1); + + refresh.then(function (data) { + $scope.monitors = data; + monitorStateCheck(); + $scope.$broadcast('scroll.refreshComplete'); + }); + } - $scope.doRefresh = function () { - //console.log("***Pull to Refresh"); - doRefresh(); + $scope.doRefresh = function () { + //console.log("***Pull to Refresh"); + doRefresh(); - }; + }; }]);
\ No newline at end of file diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index 09353ea9..2fa976b3 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -638,7 +638,13 @@ function initPackery() //--------------------------------------------------------------------- // main monitor modal open - if drag is not on, this is called on touch //--------------------------------------------------------------------- - $scope.openModal = function (mid, controllable, controlid, connKey, monitor) { + + $scope.openModal = function (mid, controllable, controlid, connKey, monitor) + { + openModal (mid, controllable, controlid, connKey, monitor); + }; + + function openModal(mid, controllable, controlid, connKey, monitor) { ZMDataModel.zmDebug("MontageCtrl: Open Monitor Modal with monitor Id=" + mid + " and Controllable:" + controllable + " with control ID:" + controlid); // $scope.isModalActive = true; // Note: no need to setAwake(true) as its already awake @@ -703,7 +709,7 @@ function initPackery() }); - }; + } //--------------------------------------------------------------------- // @@ -811,6 +817,10 @@ $scope.$on ('$ionicView.beforeEnter', function() { $scope.minimal = $stateParams.minimal; //console.log ("**************** MINIMAL ENTER " + $scope.minimal); $scope.zmMarginTop = $scope.minimal ? 0 : 15; + + + + }); @@ -921,6 +931,9 @@ $scope.$on('$ionicView.afterEnter', function () { $timeout ( function () {initPackery(); },500); document.addEventListener("pause", onPause, false); document.addEventListener("resume", onResume, false); + + + }); @@ -946,6 +959,7 @@ $scope.$on('$ionicView.afterEnter', function () { }); + $scope.$on('$ionicView.unloaded', function () { diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index c202c20d..10dd30ce 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -165,6 +165,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic if ($rootScope.tappedNotification) { + var ld = ZMDataModel.getLogin(); ZMDataModel.zmLog ("Came via push tap. onTapScreen="+ld.onTapScreen); @@ -172,19 +173,25 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic $rootScope.tappedNotification = 0; $ionicHistory.nextViewOptions({disableBack: true}); - if (ld.onTapScreen == 'montage' ) + if (ld.onTapScreen == $translate.instant('kTapMontage') ) { ZMDataModel.zmDebug("Going to montage"); $state.go("montage", {}, { reload: true }); return; } - else + else if (ld.onTapScreen == $translate.instant ('kTapEvents')) { ZMDataModel.zmDebug("Going to events"); $state.go("events", {"id": 0}, { reload: true }); return; } + else // we go to live + { + ZMDataModel.zmDebug("Going to live view but Montage for now"); + $state.go("montage", {}, { reload: true }); + return; + } } ZMDataModel.zmDebug("Transitioning state to: " + $rootScope.lastState ? $rootScope.lastState : 'montage'); diff --git a/www/js/WizardCtrl.js b/www/js/WizardCtrl.js index a0cc975d..b36cf668 100644 --- a/www/js/WizardCtrl.js +++ b/www/js/WizardCtrl.js @@ -2,7 +2,7 @@ /* jslint browser: true*/ /* global cordova,StatusBar,angular,console, Masonry, URI */ -angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups', '$http', '$q', 'zm','$ionicLoading', 'WizardHandler','$translate', function ($scope, $rootScope, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups, $http, $q, zm, $ionicLoading, WizardHandler, $translate) { +angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups', '$http', '$q', 'zm', '$ionicLoading', 'WizardHandler', '$translate', function ($scope, $rootScope, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups, $http, $q, zm, $ionicLoading, WizardHandler, $translate) { $scope.openMenu = function () { $ionicSideMenuDelegate.toggleLeft(); }; @@ -11,7 +11,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ //-------------------------------------------------------------------------- // logs into ZM //-------------------------------------------------------------------------- - + function login(u, zmu, zmp) { var d = $q.defer(); @@ -41,11 +41,11 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ }) .success(function (data, status, headers) { console.log("LOOKING FOR " + zm.loginScreenString); - console.log ("DATA RECEIVED " + JSON.stringify(data)); + console.log("DATA RECEIVED " + JSON.stringify(data)); if (data.indexOf(zm.loginScreenString) == -1) { - + $scope.wizard.loginURL = $scope.wizard.fqportal; - $scope.wizard.portalValidText = $translate.instant('kPortal')+": "+$scope.wizard.loginURL; + $scope.wizard.portalValidText = $translate.instant('kPortal') + ": " + $scope.wizard.loginURL; $scope.wizard.portalColor = "#16a085"; d.resolve(true); return d.promise; @@ -57,96 +57,87 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ return d.promise; } }) - .error (function (error) { - console.log("************ERROR"); - $scope.wizard.portalValidText = $translate.instant('kPortalDetectionFailed'); - $scope.wizard.portalColor = "#e74c3c"; - d.reject(false); - return d.promise; - - }); + .error(function (error) { + console.log("************ERROR"); + $scope.wizard.portalValidText = $translate.instant('kPortalDetectionFailed'); + $scope.wizard.portalColor = "#e74c3c"; + d.reject(false); + return d.promise; + + }); return d.promise; } - + //-------------------------------------------------------------------------- // we need a monitor ID to do cgi-bin detection - if you don't have // monitors configured, cgi-bin won't work //-------------------------------------------------------------------------- - - function getFirstMonitor() - { - var d=$q.defer(); $http.get($scope.wizard.apiURL+"/monitors.json") - .then (function (success) { - if (success.data.monitors.length > 0) - { - var foundMid = -1; - for (var i=0; i< success.data.monitors.length; i++) - { - if ( success.data.monitors[i].Monitor.Function != 'None' && - success.data.monitors[i].Monitor.Enabled == '1') - { - foundMid = success.data.monitors[i].Monitor.Id; - break; + + function getFirstMonitor() { + var d = $q.defer(); + $http.get($scope.wizard.apiURL + "/monitors.json") + .then(function (success) { + console.log("getfirst monitor success: " + JSON.stringify(success)); + if (success.data.monitors.length > 0) { + var foundMid = -1; + for (var i = 0; i < success.data.monitors.length; i++) { + if (success.data.monitors[i].Monitor.Function != 'None' && + success.data.monitors[i].Monitor.Enabled == '1') { + foundMid = success.data.monitors[i].Monitor.Id; + break; + } + } + + if (foundMid != -1) { + ZMDataModel.zmDebug("zmWizard - getFirstMonitor returned " + foundMid); + d.resolve(foundMid); + return d.promise; + } else { + d.reject(false); + return d.promise; + } + + + + } else { + d.reject(false); + return d.promise; } - } - - if (foundMid != -1) - { - ZMDataModel.zmDebug("zmWizard - getFirstMonitor returned " + foundMid); d.resolve(foundMid); - return d.promise; - } - else - { + }, + function (error) { + console.log("getfirst monitor error: " + JSON.stringify(error)); d.reject(false); return d.promise; - } - - - - } - else - { - d.reject(false); - return d.promise; - } - }, - function (error) { - d.reject(false); - return d.promise; - }); + }); return d.promise; } - + //-------------------------------------------------------------------------- // Utility function - iterates through a list of URLs // Don't put loginData.reachability here --> we are using this to iterate // through multiple options - not the same as fallback //-------------------------------------------------------------------------- - - function findFirstReachableUrl(urls, tail) - { + + function findFirstReachableUrl(urls, tail) { var d = $q.defer(); - if (urls.length > 0) - { + if (urls.length > 0) { var t = ""; if (tail) t = tail; - //$ionicLoading.show({template: 'trying ' + urls[0].server}); - ZMDataModel.zmLog ("zmWizard test.." + urls[0]+t); - return $http.get(urls[0]+t).then(function () { - ZMDataModel.zmLog ("Success: on "+ urls[0]+t); + //$ionicLoading.show({template: 'trying ' + urls[0].server}); + ZMDataModel.zmLog("zmWizard test.." + urls[0] + t); + return $http.get(urls[0] + t).then(function () { + ZMDataModel.zmLog("Success: on " + urls[0] + t); //$ionicLoading.hide(); return urls[0]; - }, function(err) { - ZMDataModel.zmLog ("zmWizard:Failed on "+ urls[0]+t+ " with error " + JSON.stringify(err)); - return findFirstReachableUrl(urls.slice(1),tail); + }, function (err) { + ZMDataModel.zmLog("zmWizard:Failed on " + urls[0] + t + " with error " + JSON.stringify(err)); + return findFirstReachableUrl(urls.slice(1), tail); }); - } - else - { - // $ionicLoading.hide(); - ZMDataModel.zmLog ("zmWizard: findFirst returned no success"); + } else { + // $ionicLoading.hide(); + ZMDataModel.zmLog("zmWizard: findFirst returned no success"); d.reject("No reachable URL"); return d.promise; @@ -155,202 +146,195 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ return d.promise; } - + //-------------------------------------------------------------------------- // removes proto scheme from string //-------------------------------------------------------------------------- - - function stripProto(u) - { - if (u.indexOf('://')!=-1) - return u.substr(u.indexOf('://')+3); + + function stripProto(u) { + if (u.indexOf('://') != -1) + return u.substr(u.indexOf('://') + 3); else return u; } - + //-------------------------------------------------------------------------- // tries to detect cgi-bin //-------------------------------------------------------------------------- - - function detectcgi() - { + + function detectcgi() { var d = $q.defer(); var c = URI.parse($scope.wizard.loginURL); - var p1,p2; - p1 =""; - p2 =""; - + var p1, p2; + p1 = ""; + p2 = ""; + if (c.userinfo) - p1 = c.userinfo+"@"; + p1 = c.userinfo + "@"; if (c.port) - p2 = ":"+c.port; - - var baseUri = c.scheme+"://"+p1+c.host+p2; - - ZMDataModel.zmLog ("zmWizard CGI: baseURL is " +baseUri); - - var a3 = baseUri+"/zm/cgi-bin"; // ubuntu/debian - var a2 = baseUri+"/cgi-bin-zm"; //fedora/centos/rhel - var a1 = baseUri+"/cgi-bin"; // doofus - - - var urls = [a1,a2,a3]; - - + p2 = ":" + c.port; + + var baseUri = c.scheme + "://" + p1 + c.host + p2; + + ZMDataModel.zmLog("zmWizard CGI: baseURL is " + baseUri); + + var a4 = baseUri + "/cgi-bin/zm"; // another one I found with a CentOS 6 guy + var a3 = baseUri + "/zm/cgi-bin"; // ubuntu/debian + var a2 = baseUri + "/cgi-bin-zm"; //fedora/centos/rhel + var a1 = baseUri + "/cgi-bin"; // doofus + + + var urls = [a1, a2, a3, a4]; + + ZMDataModel.getPathZms() // what does ZM have stored in PATH_ZMS? - .then (function(data){ - // remove zms or nph-zms - var path = data.trim(); - path = path.replace("/nph-zms",""); - path = path.replace("/zms",""); - urls.push (baseUri.trim()+path); - ZMDataModel.zmLog ("zmWizard: getPathZMS succeeded, adding "+baseUri+path+" to things to try"); - continueCgi(urls); - }, - function (error) { - ZMDataModel.zmLog ("zmWizard: getPathZMS failed, but continuing..."); - continueCgi(urls); - }); - + .then(function (data) { + // remove zms or nph-zms + var path = data.trim(); + path = path.replace("/nph-zms", ""); + path = path.replace("/zms", ""); + urls.push(baseUri.trim() + path); + ZMDataModel.zmLog("zmWizard: getPathZMS succeeded, adding " + baseUri + path + " to things to try"); + continueCgi(urls); + }, + function (error) { + ZMDataModel.zmLog("zmWizard: getPathZMS failed, but continuing..."); + continueCgi(urls); + }); + // Well, PATH_ZMS or not, lets call this function and brute force it - function continueCgi (urls) - { + function continueCgi(urls) { $ionicLoading.show({ - template: $translate.instant('kDiscovering')+"...", + template: $translate.instant('kDiscovering') + "...", noBackdrop: true, duration: zm.httpTimeout - }); + }); getFirstMonitor() - .then (function (success){ - $ionicLoading.hide(); - var tail = "/nph-zms?mode=single&monitor="+success; - if ($scope.wizard.useauth && $scope.wizard.usezmauth) - { - - var ck = Math.floor(Math.random() * (50000 - 10000 + 1)) + 10000; - ZMDataModel.getAuthKey(success,ck) - .then (function (success) - { - if (success=="") - { - ZMDataModel.zmLog ("getAuthKey returned null, so going user=&pwd= way"); - tail+= "&user="+$scope.wizard.zmuser+"&pass="+$scope.wizard.zmpassword; - } - else - { - tail+=success; - } - ZMDataModel.zmLog ("auth computed is : " + tail); - proceedwithCgiAfterAuth(urls,tail); - }, - function (error) - { - ZMDataModel.zmLog ("Should never come here, getAuthKey doesn't return error"); - - }); - - - //console.log ("****CDING " + tail); - } - - function proceedwithCgiAfterAuth(urls,tail) - { - - $ionicLoading.show({ - template: $translate.instant('kDiscovering')+"...", - noBackdrop: true, - duration: zm.httpTimeout - }); - - findFirstReachableUrl(urls,tail ) - .then (function (success) { + .then(function (success) { $ionicLoading.hide(); - ZMDataModel.zmLog ("Valid cgi-bin found with: " + success); - $scope.wizard.streamingURL = success; - $scope.wizard.streamingValidText = "cgi-bin: "+$scope.wizard.streamingURL; - $scope.wizard.streamingColor = "#16a085"; - d.resolve(true); - return d.promise; + var tail = "/nph-zms?mode=single&monitor=" + success; + if ($scope.wizard.useauth && $scope.wizard.usezmauth) { + + var ck = Math.floor(Math.random() * (50000 - 10000 + 1)) + 10000; + ZMDataModel.getAuthKey(success, ck) + .then(function (success) { + if (success == "") { + ZMDataModel.zmLog("getAuthKey returned null, so going user=&pwd= way"); + tail += "&user=" + $scope.wizard.zmuser + "&pass=" + $scope.wizard.zmpassword; + } else { + tail += success; + } + ZMDataModel.zmLog("auth computed is : " + tail); + proceedwithCgiAfterAuth(urls, tail); + }, + function (error) { + ZMDataModel.zmLog("Should never come here, getAuthKey doesn't return error"); + + }); + + + //console.log ("****CDING " + tail); + } else // no auth case + { + proceedwithCgiAfterAuth(urls, tail); + } + + function proceedwithCgiAfterAuth(urls, tail) { + $ionicLoading.show({ + template: $translate.instant('kDiscovering') + "...", + noBackdrop: true, + duration: zm.httpTimeout + }); + + findFirstReachableUrl(urls, tail) + .then(function (success) { + $ionicLoading.hide(); + ZMDataModel.zmLog("Valid cgi-bin found with: " + success); + $scope.wizard.streamingURL = success; + $scope.wizard.streamingValidText = "cgi-bin: " + $scope.wizard.streamingURL; + $scope.wizard.streamingColor = "#16a085"; + d.resolve(true); + return d.promise; + + }, + function (error) { + $ionicLoading.hide(); + console.log("No cgi-bin found: " + error); + $scope.wizard.streamingValidText = $translate.instant('kPortalCgiBinFailed'); + $scope.wizard.streamingColor = "#e74c3c"; + d.reject(false); + return (d.promise); + }); + } }, function (error) { $ionicLoading.hide(); - console.log ("No cgi-bin found: " + error); - $scope.wizard.streamingValidText = $translate.instant('kPortalCgiBinFailed'); + $scope.wizard.streamingValidText = $translate.instant('kPortalCgiBinFailed') + " -" + $translate.instant('kPortalNoMonitorFound'); $scope.wizard.streamingColor = "#e74c3c"; - d.reject (false); + d.reject(false); return (d.promise); + }); - } - }, - function (error){ - $ionicLoading.hide(); - $scope.wizard.streamingValidText = $translate.instant('kPortalCgiBinFailed')+" -"+$translate.instant('kPortalNoMonitorFound'); - $scope.wizard.streamingColor = "#e74c3c"; - d.reject (false); - return (d.promise); - - }); } - - // https://server/zm/cgi-bin/nph-zms?mode=single&monitor=1&user=admin&pass=cc - + + // https://server/zm/cgi-bin/nph-zms?mode=single&monitor=1&user=admin&pass=cc + return d.promise; - + } - - + + //-------------------------------------------------------------------------- // Finds an appropriate API to use //-------------------------------------------------------------------------- - - function detectapi() - { - var u = $scope.wizard.loginURL; - var d = $q.defer(); - var api1 = u+"/api" ; - var api3 = u+"/zm/api"; + + function detectapi() { + var u = $scope.wizard.loginURL; + var d = $q.defer(); + var api1 = u + "/api"; + var api3 = u + "/zm/api"; var c = URI.parse(u); - + // lets also try without the path - var api2 = c.scheme+"://"; - if (c.userinfo) api2+= c.userinfo+"@"; - api2 +=c.host; - if (c.port) api2+= ":"+c.port; - api2+="/api"; - - - + var api2 = c.scheme + "://"; + if (c.userinfo) api2 += c.userinfo + "@"; + api2 += c.host; + if (c.port) api2 += ":" + c.port; + api2 += "/api"; + + + // lets try both /zm/api and /api. What else is there? var apilist = [api1, api2, api3]; - + findFirstReachableUrl(apilist, '/host/getVersion.json') - .then (function (success) { - ZMDataModel.zmLog ("Valid API response found with:" + success); - $scope.wizard.apiURL = success; - - - - $scope.wizard.apiValidText = "API: "+$scope.wizard.apiURL; - $scope.wizard.apiColor = "#16a085"; - d.resolve(true); - return d.promise; - }, - function (error) { - console.log ("No APIs found: " + error); - $scope.wizard.apiValidText = $translate.instant('kPortalAPIFailed'); - $scope.wizard.apiColor = "#e74c3c"; - d.reject (false); - return (d.promise); - }); - + .then(function (success) { + ZMDataModel.zmLog("Valid API response found with:" + success); + $scope.wizard.apiURL = success; + + + + $scope.wizard.apiValidText = "API: " + $scope.wizard.apiURL; + $scope.wizard.apiColor = "#16a085"; + d.resolve(true); + return d.promise; + }, + function (error) { + console.log("No APIs found: " + error); + $scope.wizard.apiValidText = $translate.instant('kPortalAPIFailed'); + $scope.wizard.apiColor = "#e74c3c"; + d.reject(false); + return (d.promise); + }); + return d.promise; } - + //-------------------------------------------------------------------------- // logs out of ZM //-------------------------------------------------------------------------- - + function logout(u) { var d = $q.defer(); @@ -376,20 +360,28 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ view: "login" } }) - .then (function (success) {$rootScope.zmCookie="";console.log ("ZMlogout success, cookie removed"); d.resolve(true); return d.promise;}, function (error) {console.log ("ZMlogout success");d.resolve(true); return d.promise;}); - + .then(function (success) { + $rootScope.zmCookie = ""; + console.log("ZMlogout success, cookie removed"); + d.resolve(true); + return d.promise; + }, function (error) { + console.log("ZMlogout success"); + d.resolve(true); + return d.promise; + }); + return d.promise; } - + //-------------------------------------------------------------------------- // clears all status updates in the verify results page - if you // get back to it //-------------------------------------------------------------------------- - - $scope.enterResults = function() - { + + $scope.enterResults = function () { $scope.portalValidText = ""; $scope.apiValidateText = ""; $scope.streamingValidateText = ""; @@ -408,18 +400,18 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ $scope.wizard.apiValidText = ""; $scope.wizard.streamingValidText = ""; $scope.wizard.fqportal = ""; - $scope.wizard.loginURL= ""; - $scope.wizard.apiURL= ""; - $scope.wizard.streamingURL= ""; + $scope.wizard.loginURL = ""; + $scope.wizard.apiURL = ""; + $scope.wizard.streamingURL = ""; $scope.wizard.serverName = ""; - + var d = $q.defer(); var c = URI.parse($scope.wizard.portalurl); - + $scope.wizard.serverName = c.host; - if (c.port) - $scope.wizard.serverName += "-"+c.port; + if (c.port) + $scope.wizard.serverName += "-" + c.port; var b = ""; if ($scope.wizard.useauth && $scope.wizard.usebasicauth) { @@ -454,68 +446,68 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ // use it even after logging in ZMDataModel.zmLog("zmWizard: logging out"); $ionicLoading.show({ - template: $translate.instant('kCleaningUp')+"...", - noBackdrop: true, - duration: zm.httpTimeout - }); + template: $translate.instant('kCleaningUp') + "...", + noBackdrop: true, + duration: zm.httpTimeout + }); logout(u) .then(function (ans) { // login now $ionicLoading.hide(); ZMDataModel.zmLog("zmWizard: logging in with " + u + " " + zmu + ":" + zmp); - + // The logic will be: // Login then do an api detect and cgi-detect together $ionicLoading.show({ - template: $translate.instant('kDiscoveringPortal')+"...", - noBackdrop: true, - duration: zm.httpTimeout + template: $translate.instant('kDiscoveringPortal') + "...", + noBackdrop: true, + duration: zm.httpTimeout }); login(u, zmu, zmp) .then(function (success) { $ionicLoading.hide(); ZMDataModel.zmLog("zmWizard: login succeeded"); - + // API Detection $ionicLoading.show({ - template: $translate.instant('kDiscoveringAPI')+"...", - noBackdrop: true, - duration: zm.httpTimeout - }); - detectapi() - .then (function (success) { - $ionicLoading.hide(); - ZMDataModel.zmLog ("zmWizard: API succeeded"); - - $ionicLoading.show({ - template: $translate.instant('kDiscoveringCGI')+"...", + template: $translate.instant('kDiscoveringAPI') + "...", noBackdrop: true, duration: zm.httpTimeout - }); - // CGI detection - detectcgi () - .then (function (success) { - $ionicLoading.hide(); - // return true here because we want to progress - return d.resolve(true); - }, - function (error) { - $ionicLoading.hide(); - // return true here because we want to progress - return d.resolve(true); - }); - }, - function (error) { - $ionicLoading.hide(); - ZMDataModel.zmLog("zmWizard: api failed"); - - // return true here because we want to progress - return d.resolve(true); }); - - + detectapi() + .then(function (success) { + $ionicLoading.hide(); + ZMDataModel.zmLog("zmWizard: API succeeded"); + + $ionicLoading.show({ + template: $translate.instant('kDiscoveringCGI') + "...", + noBackdrop: true, + duration: zm.httpTimeout + }); + // CGI detection + detectcgi() + .then(function (success) { + $ionicLoading.hide(); + // return true here because we want to progress + return d.resolve(true); + }, + function (error) { + $ionicLoading.hide(); + // return true here because we want to progress + return d.resolve(true); + }); + }, + function (error) { + $ionicLoading.hide(); + ZMDataModel.zmLog("zmWizard: api failed"); + + // return true here because we want to progress + return d.resolve(true); + }); + + }, - + // if login failed, don't progress in the wizard function (error) { $ionicLoading.hide(); @@ -609,9 +601,9 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ if (!$scope.wizard.portalurl) { $rootScope.zmPopup = SecuredPopups.show('show', { title: $translate.instant('kError'), - template: $translate.instant ('kPortalEmpty'), + template: $translate.instant('kPortalEmpty'), buttons: [{ - text: $translate.instant ('kButtonOk') + text: $translate.instant('kButtonOk') }] }); @@ -619,24 +611,31 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ } if (!checkscheme($scope.wizard.portalurl)) { - - $scope.portalproto = [ {text:"http",value:"http://"}, {text:"https",value:"https://"}]; - $scope.myproto = {proto:""}; - - - + + $scope.portalproto = [{ + text: "http", + value: "http://" + }, { + text: "https", + value: "https://" + }]; + $scope.myproto = { + proto: "" + }; + + + $rootScope.zmPopup = $ionicPopup.show({ title: $translate.instant('kPortalNoProto'), scope: $scope, - template: $translate.instant('kPortalPleaseSelect')+': <ion-radio-fix ng-repeat="item in portalproto" ng-value="item.value" ng-model="myproto.proto">{{item.text}}</ion-radio-fix>', + template: $translate.instant('kPortalPleaseSelect') + ': <ion-radio-fix ng-repeat="item in portalproto" ng-value="item.value" ng-model="myproto.proto">{{item.text}}</ion-radio-fix>', buttons: [{ - text: $translate.instant ('kButtonOk'), - onTap: function(e) - { - ZMDataModel.zmDebug ("Protocol selected:" + $scope.myproto.proto); - $scope.wizard.portalurl = $scope.myproto.proto+stripProto($scope.wizard.portalurl); + text: $translate.instant('kButtonOk'), + onTap: function (e) { + ZMDataModel.zmDebug("Protocol selected:" + $scope.myproto.proto); + $scope.wizard.portalurl = $scope.myproto.proto + stripProto($scope.wizard.portalurl); } - + }] }); @@ -654,7 +653,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ title: $translate.instant('kError'), template: $translate.instant('kPortalInvalidUrl'), buttons: [{ - text: $translate.instant ('kButtonOk') + text: $translate.instant('kButtonOk') }] }); @@ -683,7 +682,7 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ // part of auth wizard - toggles display of auth components //-------------------------------------------------------------------------- $scope.toggleAuth = function () { - + if (!$scope.wizard.useauth) { $scope.wizard.usebasicauth = false; $scope.wizard.usezmauth = false; @@ -702,13 +701,14 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ $scope.wizard.tiptext = $translate.instant('kShowTip'); }; - $scope.gotoLoginState = function() - { + $scope.gotoLoginState = function () { $rootScope.wizard = angular.copy($scope.wizard); $ionicHistory.nextViewOptions({ - disableBack: true - }); - $state.go("login", {"wizard":true}); + disableBack: true + }); + $state.go("login", { + "wizard": true + }); }; //-------------------------------------------------------------------------- @@ -747,4 +747,4 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$ }); -}]);
\ No newline at end of file +}]); diff --git a/www/js/app.js b/www/js/app.js index 6cac5802..63eb0e1a 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -932,6 +932,7 @@ angular.module('zmApp', [ $rootScope.loggedIntoZm = 0; $rootScope.apnsToken = ''; $rootScope.tappedNotification = 0; + $rootScope.tappedMid = 0; //var eventsToDisplay=[]; $rootScope.alarmCount = "0"; $rootScope.platformOS = "desktop"; |
