diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2018-04-06 13:49:36 -0400 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2018-04-06 13:49:36 -0400 |
| commit | 39fc76897126582c63fdfa81d650e2d82aba1922 (patch) | |
| tree | c7727cc4b04eb01f3dd41fe61400d6fb1a1b05e4 /www | |
| parent | 9ce47c606728896a02d1975c20b5230362d8f62b (diff) | |
#603 don't logout explictly, its in doLogin now
Diffstat (limited to 'www')
| -rw-r--r-- | www/js/LoginCtrl.js | 1435 | ||||
| -rwxr-xr-x | www/js/app.js | 21 |
2 files changed, 656 insertions, 800 deletions
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index a2e363b1..74efc2cd 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -2,901 +2,746 @@ /* jslint browser: true*/ /* global cordova,StatusBar,angular,console,alert,URI, localforage */ -angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'NVRDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$stateParams', '$translate', function($scope, $rootScope, zm, $ionicModal, NVRDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $stateParams, $translate) -{ - - var oldLoginData = ''; // used to track any changes - $scope.openMenu = function() - { - - // if ($scope.loginData.serverName) - // saveItems(false); - $ionicSideMenuDelegate.toggleLeft(); - - }; - - var oldName; - var serverbuttons = []; - var availableServers; - $scope.loginData = NVRDataModel.getLogin(); - - $scope.check = { - isUseAuth: false, - isUseEventServer: false - }; +angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'NVRDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$stateParams', '$translate', function ($scope, $rootScope, zm, $ionicModal, NVRDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $stateParams, $translate) { + + var oldLoginData = ''; // used to track any changes + $scope.openMenu = function () { + + // if ($scope.loginData.serverName) + // saveItems(false); + $ionicSideMenuDelegate.toggleLeft(); + + }; + + var oldName; + var serverbuttons = []; + var availableServers; + $scope.loginData = NVRDataModel.getLogin(); + + $scope.check = { + isUseAuth: false, + isUseEventServer: false + }; + + $scope.check.isUseAuth = ($scope.loginData.isUseAuth) ? true : false; + $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; + + document.addEventListener("pause", onPause, false); + document.addEventListener("resume", onResume, false); + + function onResume() { + NVRDataModel.log("Login screen resumed"); + + } + + function onPause() { + NVRDataModel.log("Login screen going to background, saving data"); + localforage.setItem("settings-temp-data", $scope.loginData); + + } + + //---------------------------------------------------------------- + // Alarm notification handling + //---------------------------------------------------------------- + $scope.handleAlarms = function () { + $rootScope.isAlarm = !$rootScope.isAlarm; + if (!$rootScope.isAlarm) { + $rootScope.alarmCount = "0"; + $ionicHistory.nextViewOptions({ + disableBack: true + }); + $state.go("app.events", { + "id": 0, + "playEvent": false + }, { + reload: true + }); + return; + } - $scope.check.isUseAuth = ($scope.loginData.isUseAuth) ? true : false; - $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; + }; - document.addEventListener("pause", onPause, false); - document.addEventListener("resume", onResume, false); + //---------------------------------------------------------------- + // Specifies a linked profile to try if this profile fails + //---------------------------------------------------------------- - function onResume() - { - NVRDataModel.log("Login screen resumed"); + $scope.selectFallback = function () { + var as = Object.keys(NVRDataModel.getServerGroups()); + if (as.length < 2) { + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kError'), + template: $translate.instant('kFallback2Configs'), + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }); + return; } + var ab = [{ + text: $translate.instant('kClear') + }]; + var ld = NVRDataModel.getLogin(); + as.forEach(function (item) { + if (item != ld.serverName) ab.push({ + text: item + }); + }); + var sheet = $ionicActionSheet.show({ + buttons: ab, + titleText: $translate.instant('kSelectFallback'), + cancelText: $translate.instant('kButtonCancel'), + cancel: function () {}, + buttonClicked: function (index) { + //console.log ("YOU WANT " + ab[index].text + index); + if (index == 0) + $scope.loginData.fallbackConfiguration = ""; + else + $scope.loginData.fallbackConfiguration = ab[index].text; + NVRDataModel.setLogin($scope.loginData); + return true; + } + }); - function onPause() - { - NVRDataModel.log("Login screen going to background, saving data"); - localforage.setItem("settings-temp-data", $scope.loginData); + }; - } + //---------------------------------------------------------------- + // This is called when the user changes profiles + //---------------------------------------------------------------- - //---------------------------------------------------------------- - // Alarm notification handling - //---------------------------------------------------------------- - $scope.handleAlarms = function() - { - $rootScope.isAlarm = !$rootScope.isAlarm; - if (!$rootScope.isAlarm) - { - $rootScope.alarmCount = "0"; - $ionicHistory.nextViewOptions( - { - disableBack: true - }); - $state.go("app.events", - { - "id": 0, - "playEvent": false - }, - { - reload: true - }); - return; - } + $scope.serverActionSheet = function () { + var hideSheet = $ionicActionSheet.show({ + buttons: serverbuttons, + destructiveText: $translate.instant('kDelete'), + titleText: $translate.instant('kManageServerGroups'), + cancelText: $translate.instant('kButtonCancel'), + cancel: function () { + // add cancel code.. + }, + buttonClicked: function (index) { + //console.log ("YOU WANT " + serverbuttons[index].text + " INDEX " + index); - }; - - //---------------------------------------------------------------- - // Specifies a linked profile to try if this profile fails - //---------------------------------------------------------------- - - $scope.selectFallback = function() - { - var as = Object.keys(NVRDataModel.getServerGroups()); - if (as.length < 2) - { - $rootScope.zmPopup = SecuredPopups.show('alert', - { - title: $translate.instant('kError'), - template: $translate.instant('kFallback2Configs'), - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }); - return; + if (serverbuttons[index].text == $translate.instant('kServerAdd') + "...") { + $scope.loginData = angular.copy(NVRDataModel.getDefaultLoginObject()); + return true; } - var ab = [ - { - text: $translate.instant('kClear') - }]; - var ld = NVRDataModel.getLogin(); - as.forEach(function(item) - { - if (item != ld.serverName) ab.push( - { - text: item - }); - }); - var sheet = $ionicActionSheet.show( - { - buttons: ab, - titleText: $translate.instant('kSelectFallback'), - cancelText: $translate.instant('kButtonCancel'), - cancel: function() {}, - buttonClicked: function(index) - { - //console.log ("YOU WANT " + ab[index].text + index); - if (index == 0) - $scope.loginData.fallbackConfiguration = ""; - else - $scope.loginData.fallbackConfiguration = ab[index].text; - NVRDataModel.setLogin($scope.loginData); - return true; - } - }); - - }; - - //---------------------------------------------------------------- - // This is called when the user changes profiles - //---------------------------------------------------------------- - - $scope.serverActionSheet = function() - { - var hideSheet = $ionicActionSheet.show( - { - buttons: serverbuttons, - destructiveText: $translate.instant('kDelete'), - titleText: $translate.instant('kManageServerGroups'), - cancelText: $translate.instant('kButtonCancel'), - cancel: function() - { - // add cancel code.. - }, - buttonClicked: function(index) - { - //console.log ("YOU WANT " + serverbuttons[index].text + " INDEX " + index); - - if (serverbuttons[index].text == $translate.instant('kServerAdd') + "...") - { - - $scope.loginData = angular.copy(NVRDataModel.getDefaultLoginObject()); - return true; - } - - var zmServers = NVRDataModel.getServerGroups(); - $scope.loginData = zmServers[serverbuttons[index].text]; - - //console.log ("NEW LOGIN OBJECT IS " + JSON.stringify($scope.loginData)); - $scope.check.isUseAuth = ($scope.loginData.isUseAuth) ? true : false; - $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; + var zmServers = NVRDataModel.getServerGroups(); + $scope.loginData = zmServers[serverbuttons[index].text]; - NVRDataModel.debug("Retrieved state for this profile:" + JSON.stringify($scope.loginData)); + //console.log ("NEW LOGIN OBJECT IS " + JSON.stringify($scope.loginData)); - // lets make sure Event Server is loaded - // correctly + $scope.check.isUseAuth = ($scope.loginData.isUseAuth) ? true : false; + $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == true) ? true : false; - // FIXME: But what happens if you don't save? - // loginData gets written but auth is not done - NVRDataModel.setLogin($scope.loginData); + NVRDataModel.debug("Retrieved state for this profile:" + JSON.stringify($scope.loginData)); - return true; - }, + // lets make sure Event Server is loaded + // correctly - destructiveButtonClicked: function() - { - - if (!$scope.loginData.serverName) - { - NVRDataModel.debug("cannot delete empty entry"); - return true; - - } - $rootScope.zmPopup = SecuredPopups.show('confirm', - { - title: $translate.instant('kDelete'), - template: $translate.instant('kDeleteProfile')+" "+$scope.loginData.serverName, - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }).then(function(res) - { - - if (res) - actuallyDelete(); - - }); - - + // FIXME: But what happens if you don't save? + // loginData gets written but auth is not done + NVRDataModel.setLogin($scope.loginData); - function actuallyDelete() - { + return true; + }, - var zmServers = NVRDataModel.getServerGroups(); - //console.log ("YOU WANT TO DELETE " + $scope.loginData.serverName); - //console.log ("LENGTH OF SERVERS IS " + Object.keys(zmServers).length); - if (Object.keys(zmServers).length > 1) - { + destructiveButtonClicked: function () { - NVRDataModel.log("Deleting " + $scope.loginData.serverName); - delete zmServers[$scope.loginData.serverName]; - NVRDataModel.setServerGroups(zmServers); - // point to first element - // better than nothing - // note this is actually unordered - $scope.loginData = zmServers[Object.keys(zmServers)[0]]; - NVRDataModel.setLogin($scope.loginData); - - availableServers = Object.keys(NVRDataModel.getServerGroups()); - serverbuttons = [ - { - text: $translate.instant('kServerAdd') + "..." - }]; - for (var servIter = 0; servIter < availableServers.length; servIter++) - { - serverbuttons.push( - { - text: availableServers[servIter] - }); - //console.log("ADDING : " + availableServers[servIter]); - } - //console.log (">>>>>>>delete: server buttons " + JSON.stringify(serverbuttons)); - } - else - { - NVRDataModel.displayBanner('error', [$translate.instant('kBannerCannotDeleteNeedOne')]); - } - + if (!$scope.loginData.serverName) { + NVRDataModel.debug("cannot delete empty entry"); + return true; - } + } + $rootScope.zmPopup = SecuredPopups.show('confirm', { + title: $translate.instant('kDelete'), + template: $translate.instant('kDeleteProfile') + " " + $scope.loginData.serverName, + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }).then(function (res) { - return true; - } + if (res) + actuallyDelete(); }); - }; - //---------------------------------------------------------------- - // This is when you tap on event server settings - //---------------------------------------------------------------- - $scope.eventServerSettings = function() - { - NVRDataModel.debug("Saving settings before going to Event Server settings"); - //console.log ( "My loginData saved " + JSON.stringify($scope.loginData)); - NVRDataModel.setLogin($scope.loginData); + function actuallyDelete() { - if (!$rootScope.isLoggedIn) { - $rootScope.zmPopup = $ionicPopup.alert( - { - title: $translate.instant('kError'), - template: $translate.instant('kEventServerNotLoggedIn'), - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }); - return; + var zmServers = NVRDataModel.getServerGroups(); + //console.log ("YOU WANT TO DELETE " + $scope.loginData.serverName); + //console.log ("LENGTH OF SERVERS IS " + Object.keys(zmServers).length); + if (Object.keys(zmServers).length > 1) { - } - else { - $state.go("app.eventserversettings"); - return; - } + NVRDataModel.log("Deleting " + $scope.loginData.serverName); + delete zmServers[$scope.loginData.serverName]; + NVRDataModel.setServerGroups(zmServers); + // point to first element + // better than nothing + // note this is actually unordered + $scope.loginData = zmServers[Object.keys(zmServers)[0]]; + NVRDataModel.setLogin($scope.loginData); - - }; - - //------------------------------------------------------------------------- - // 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() - { - oldLoginData = ''; - //console.log("**VIEW ** LoginCtrl Entered"); - NVRDataModel.setAwake(false); - var ld = NVRDataModel.getLogin(); - oldName = ld.serverName; - - availableServers = Object.keys(NVRDataModel.getServerGroups()); - serverbuttons = [ - { - text: $translate.instant('kServerAdd') + "..." - }]; - for (var servIter = 0; servIter < availableServers.length; servIter++) - { - serverbuttons.push( - { + availableServers = Object.keys(NVRDataModel.getServerGroups()); + serverbuttons = [{ + text: $translate.instant('kServerAdd') + "..." + }]; + for (var servIter = 0; servIter < availableServers.length; servIter++) { + serverbuttons.push({ text: availableServers[servIter] - }); - - //console.log (">>>>>>>ionicview enter: server buttons " + JSON.stringify(serverbuttons)); - } - - NVRDataModel.debug("Does login need to hear the wizard? " + $stateParams.wizard); - - if ($stateParams.wizard == "true") - { - NVRDataModel.log("Creating new login entry for wizard"); - $scope.loginData = angular.copy(NVRDataModel.getDefaultLoginObject()); - $scope.loginData.serverName = $rootScope.wizard.serverName; - $scope.loginData.url = $rootScope.wizard.loginURL; - $scope.loginData.apiurl = $rootScope.wizard.apiURL; - $scope.loginData.streamingurl = $rootScope.wizard.streamingURL; - if ($rootScope.wizard.useauth && $rootScope.wizard.usezmauth) - { - $scope.loginData.username = $rootScope.wizard.zmuser; - $scope.loginData.password = $rootScope.wizard.zmpassword; - } - else - { - $scope.loginData.isUseAuth = false; + }); + //console.log("ADDING : " + availableServers[servIter]); } + //console.log (">>>>>>>delete: server buttons " + JSON.stringify(serverbuttons)); + } else { + NVRDataModel.displayBanner('error', [$translate.instant('kBannerCannotDeleteNeedOne')]); + } - if ((/^https:\/\//i.test($scope.loginData.url))) - { - $scope.loginData.useSSL = true; - } } - else - { - var savedData; - - // this thing is crappy - not sure why it keeps removing - // ES stuff. removing it as of Jan 18 - // this means if you back out while entering login data - // you'll get a blank. small price to pay... - - /*localforage.getItem("settings-temp-data").then(function(value) - { - savedData = value; - //= zmStorageService.getObject ("settings-temp-data"); - if (!NVRDataModel.isEmpty(savedData)) - { - $scope.loginData = savedData; - NVRDataModel.log("retrieved pre-stored loginData on past pause: " + JSON.stringify($scope.loginData)); - localforage.removeItem("settings-temp-data"); - //zmStorageService.setObject("settings-temp-data", {}); - } - else - { - NVRDataModel.log("Not recovering login data as its empty"); - } - });*/ - } - oldLoginData = JSON.stringify($scope.loginData); + return true; + } }); + }; + + //---------------------------------------------------------------- + // This is when you tap on event server settings + //---------------------------------------------------------------- + + $scope.eventServerSettings = function () { + NVRDataModel.debug("Saving settings before going to Event Server settings"); + //console.log ( "My loginData saved " + JSON.stringify($scope.loginData)); + NVRDataModel.setLogin($scope.loginData); + + + if (!$rootScope.isLoggedIn) { + $rootScope.zmPopup = $ionicPopup.alert({ + title: $translate.instant('kError'), + template: $translate.instant('kEventServerNotLoggedIn'), + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }); + return; + + } else { + $state.go("app.eventserversettings"); + return; + } - $scope.$on('$ionicView.beforeLeave', function() - { - //console.log("**VIEW ** LoginCtrl Entered"); - var newLoginData = JSON.stringify($scope.loginData); - if ($scope.loginData.serverName && newLoginData != oldLoginData) { - NVRDataModel.log ("Login data changed, saving..."); - saveItems(false); - } - else { - NVRDataModel.log ("Login data not changed, not saving"); - } - - + }; + + //------------------------------------------------------------------------- + // 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 () { + oldLoginData = ''; + //console.log("**VIEW ** LoginCtrl Entered"); + NVRDataModel.setAwake(false); + var ld = NVRDataModel.getLogin(); + oldName = ld.serverName; + + availableServers = Object.keys(NVRDataModel.getServerGroups()); + serverbuttons = [{ + text: $translate.instant('kServerAdd') + "..." + }]; + for (var servIter = 0; servIter < availableServers.length; servIter++) { + serverbuttons.push({ + text: availableServers[servIter] + }); + + //console.log (">>>>>>>ionicview enter: server buttons " + JSON.stringify(serverbuttons)); + } - }); + NVRDataModel.debug("Does login need to hear the wizard? " + $stateParams.wizard); + + if ($stateParams.wizard == "true") { + NVRDataModel.log("Creating new login entry for wizard"); + $scope.loginData = angular.copy(NVRDataModel.getDefaultLoginObject()); + $scope.loginData.serverName = $rootScope.wizard.serverName; + $scope.loginData.url = $rootScope.wizard.loginURL; + $scope.loginData.apiurl = $rootScope.wizard.apiURL; + $scope.loginData.streamingurl = $rootScope.wizard.streamingURL; + if ($rootScope.wizard.useauth && $rootScope.wizard.usezmauth) { + $scope.loginData.username = $rootScope.wizard.zmuser; + $scope.loginData.password = $rootScope.wizard.zmpassword; + } else { + $scope.loginData.isUseAuth = false; + } + + if ((/^https:\/\//i.test($scope.loginData.url))) { + $scope.loginData.useSSL = true; + } + + } else { + var savedData; + + // this thing is crappy - not sure why it keeps removing + // ES stuff. removing it as of Jan 18 + // this means if you back out while entering login data + // you'll get a blank. small price to pay... + + /*localforage.getItem("settings-temp-data").then(function(value) + { + savedData = value; + //= zmStorageService.getObject ("settings-temp-data"); + if (!NVRDataModel.isEmpty(savedData)) + { + $scope.loginData = savedData; + NVRDataModel.log("retrieved pre-stored loginData on past pause: " + JSON.stringify($scope.loginData)); + localforage.removeItem("settings-temp-data"); + //zmStorageService.setObject("settings-temp-data", {}); + } + else + { + NVRDataModel.log("Not recovering login data as its empty"); + } + });*/ + } - //---------------------------------------------------------------- - // We need to make sure that if the user changes a profile, that - // its saved, which involves re-auth. Not doing this will mess - // up monitors. We can't automatically do it, because we really - // don't want re-auth delays each time a user taps on a new profile - // especially if they switch back - // - // So instead, if check if the profile name has changed - if it has - // we block state change and ask the user to save - //---------------------------------------------------------------- - - // credit: http://stackoverflow.com/questions/33385610/ionic-prevent-navigation-on-leave - /* Disabled - seems to crash with native transitions - - $scope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { - NVRDataModel.setAwake(false); - var ld = NVRDataModel.getLogin(); + oldLoginData = JSON.stringify($scope.loginData); - if (ld.serverName != oldName) { - event.preventDefault(); - $rootScope.zmPopup = SecuredPopups.show('alert', { - title: $translate.instant('kPleaseSave'), - template: $translate.instant('kProfileChangeNotification', { - oldName: oldName, - newName: ld.serverName - }) + }); - }); + $scope.$on('$ionicView.beforeLeave', function () { + //console.log("**VIEW ** LoginCtrl Entered"); + var newLoginData = JSON.stringify($scope.loginData); + if ($scope.loginData.serverName && newLoginData != oldLoginData) { + NVRDataModel.log("Login data changed, saving..."); + saveItems(false); + } else { + NVRDataModel.log("Login data not changed, not saving"); + } - } - });*/ - $rootScope.$on('$stateChangeSuccess', function() - { - $scope.ignoreDirty = false; - }); - // Make a noble attempt at deciphering - - //-------------------------------------------------------------------------- - // When PIN is enabled, this is called to specify a PIN - // FIXME: Get rid of cordovaPinDialog. It's really not needed - //-------------------------------------------------------------------------- - $scope.pinPrompt = function(evt) - { - NVRDataModel.log("Password prompt"); - if ($scope.loginData.usePin) - { - $scope.loginData.pinCode = ""; - $cordovaPinDialog.prompt($translate.instant('kEnterPin'), $translate.instant('kPinProtect')).then( - function(result1) - { - - // console.log (JSON.stringify(result1)); - if (result1.input1 && result1.buttonIndex == 1) - { - $cordovaPinDialog.prompt($translate.instant('kReconfirmPin'), $translate.instant('kPinProtect')) - .then(function(result2) - { - if (result1.input1 == result2.input1) - { - NVRDataModel.log("Pin code match"); - $scope.loginData.pinCode = result1.input1; - } - else - { - NVRDataModel.log("Pin code mismatch"); - $scope.loginData.usePin = false; - NVRDataModel.displayBanner('error', [$translate.instant('kBannerPinMismatch')]); - } - }, - function(error) - { - //console.log("Error inside"); - $scope.loginData.usePin = false; - }); - } - else - { - $scope.loginData.usePin = false; - } - }, - function(error) - { - //console.log("Error outside"); + + }); + + //---------------------------------------------------------------- + // We need to make sure that if the user changes a profile, that + // its saved, which involves re-auth. Not doing this will mess + // up monitors. We can't automatically do it, because we really + // don't want re-auth delays each time a user taps on a new profile + // especially if they switch back + // + // So instead, if check if the profile name has changed - if it has + // we block state change and ask the user to save + //---------------------------------------------------------------- + + // credit: http://stackoverflow.com/questions/33385610/ionic-prevent-navigation-on-leave + /* Disabled - seems to crash with native transitions + + $scope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { + NVRDataModel.setAwake(false); + var ld = NVRDataModel.getLogin(); + + if (ld.serverName != oldName) { + event.preventDefault(); + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kPleaseSave'), + template: $translate.instant('kProfileChangeNotification', { + oldName: oldName, + newName: ld.serverName + }) + + }); + + } + });*/ + + $rootScope.$on('$stateChangeSuccess', function () { + $scope.ignoreDirty = false; + }); + + // Make a noble attempt at deciphering + + //-------------------------------------------------------------------------- + // When PIN is enabled, this is called to specify a PIN + // FIXME: Get rid of cordovaPinDialog. It's really not needed + //-------------------------------------------------------------------------- + $scope.pinPrompt = function (evt) { + NVRDataModel.log("Password prompt"); + if ($scope.loginData.usePin) { + $scope.loginData.pinCode = ""; + $cordovaPinDialog.prompt($translate.instant('kEnterPin'), $translate.instant('kPinProtect')).then( + function (result1) { + + // console.log (JSON.stringify(result1)); + if (result1.input1 && result1.buttonIndex == 1) { + $cordovaPinDialog.prompt($translate.instant('kReconfirmPin'), $translate.instant('kPinProtect')) + .then(function (result2) { + if (result1.input1 == result2.input1) { + NVRDataModel.log("Pin code match"); + $scope.loginData.pinCode = result1.input1; + } else { + NVRDataModel.log("Pin code mismatch"); $scope.loginData.usePin = false; + NVRDataModel.displayBanner('error', [$translate.instant('kBannerPinMismatch')]); + } + }, + function (error) { + //console.log("Error inside"); + $scope.loginData.usePin = false; }); + } else { + $scope.loginData.usePin = false; + } + }, + function (error) { + //console.log("Error outside"); + $scope.loginData.usePin = false; + }); - } - else - { - NVRDataModel.debug("Password disabled"); - } - }; - - //------------------------------------------------------------------------------- - // Makes input easier - //------------------------------------------------------------------------------- + } else { + NVRDataModel.debug("Password disabled"); + } + }; - $scope.portalKeypress = function(evt) - { + //------------------------------------------------------------------------------- + // Makes input easier + //------------------------------------------------------------------------------- - if (/^https:\/\//i.test($scope.loginData.url)) - { - $scope.loginData.useSSL = true; - } - else - { - $scope.loginData.useSSL = false; - } + $scope.portalKeypress = function (evt) { - if ($scope.loginData.url.slice(-1) == '/') - { - $scope.loginData.apiurl = $scope.loginData.url + "api"; - $scope.loginData.streamingurl = $scope.loginData.url + "cgi-bin"; - } - else - { - $scope.loginData.apiurl = $scope.loginData.url + "/api"; - $scope.loginData.streamingurl = $scope.loginData.url + "/cgi-bin"; - } + if (/^https:\/\//i.test($scope.loginData.url)) { + $scope.loginData.useSSL = true; + } else { + $scope.loginData.useSSL = false; + } - }; - //------------------------------------------------------------------------------- - // Adds http to url if not present - // http://stackoverflow.com/questions/11300906/check-if-a-string-starts-with-http-using-javascript - //------------------------------------------------------------------------------- - function addhttp(url) - { - - if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) - { - url = "http://" + url; - } - return url; + if ($scope.loginData.url.slice(-1) == '/') { + $scope.loginData.apiurl = $scope.loginData.url + "api"; + $scope.loginData.streamingurl = $scope.loginData.url + "cgi-bin"; + } else { + $scope.loginData.apiurl = $scope.loginData.url + "/api"; + $scope.loginData.streamingurl = $scope.loginData.url + "/cgi-bin"; } - function addWsOrWss(url) - { + }; + //------------------------------------------------------------------------------- + // Adds http to url if not present + // http://stackoverflow.com/questions/11300906/check-if-a-string-starts-with-http-using-javascript + //------------------------------------------------------------------------------- + function addhttp(url) { - if ((!/^wss?:\/\//i.test(url)) && (url != "")) - { - url = "ws://" + url; - } - return url; + if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) { + url = "http://" + url; } + return url; + } - function endsWith(str, suffix) - { - return str.indexOf(suffix, str.length - suffix.length) !== -1; + function addWsOrWss(url) { + + if ((!/^wss?:\/\//i.test(url)) && (url != "")) { + url = "ws://" + url; } + return url; + } - //----------------------------------------------------------------------------- - // Perform the login action when the user submits the login form - //----------------------------------------------------------------------------- + function endsWith(str, suffix) { + return str.indexOf(suffix, str.length - suffix.length) !== -1; + } - function saveItems(showalert) - { + //----------------------------------------------------------------------------- + // Perform the login action when the user submits the login form + //----------------------------------------------------------------------------- - //console.log ("*********** SAVE ITEMS CALLED "); - //console.log('Saving login'); - NVRDataModel.setFirstUse(false); - NVRDataModel.setCurrentServerVersion(''); - NVRDataModel.setCurrentServerMultiPortSupported(false); + function saveItems(showalert) { - // used for menu display + //console.log ("*********** SAVE ITEMS CALLED "); + //console.log('Saving login'); + NVRDataModel.setFirstUse(false); + NVRDataModel.setCurrentServerVersion(''); + NVRDataModel.setCurrentServerMultiPortSupported(false); - // lets so some basic sanitization of the data - // I am already adding "/" so lets remove spurious ones - // though webkit has no problems. Even so, this is to avoid - // a deluge of folks who look at the error logs and say - // the reason the login data is not working is because - // the app is adding multiple "/" characters + // used for menu display - $scope.loginData.url = $scope.loginData.url.replace(/\s/g, ""); - $scope.loginData.apiurl = $scope.loginData.apiurl.replace(/\s/g, ""); - $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace(/\s/g, ""); - $scope.loginData.eventServer = $scope.loginData.eventServer.replace(/\s/g, ""); + // lets so some basic sanitization of the data + // I am already adding "/" so lets remove spurious ones + // though webkit has no problems. Even so, this is to avoid + // a deluge of folks who look at the error logs and say + // the reason the login data is not working is because + // the app is adding multiple "/" characters - $scope.loginData.username = $scope.loginData.username.trim(); + $scope.loginData.url = $scope.loginData.url.replace(/\s/g, ""); + $scope.loginData.apiurl = $scope.loginData.apiurl.replace(/\s/g, ""); + $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace(/\s/g, ""); + $scope.loginData.eventServer = $scope.loginData.eventServer.replace(/\s/g, ""); - $scope.loginData.isUseAuth = ($scope.check.isUseAuth) ? true : false; - $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? true : false; + $scope.loginData.username = $scope.loginData.username.trim(); - if ($scope.loginData.url.slice(-1) == '/') - { - $scope.loginData.url = $scope.loginData.url.slice(0, -1); + $scope.loginData.isUseAuth = ($scope.check.isUseAuth) ? true : false; + $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? true : false; - } + if ($scope.loginData.url.slice(-1) == '/') { + $scope.loginData.url = $scope.loginData.url.slice(0, -1); - if ($scope.loginData.apiurl.slice(-1) == '/') - { - $scope.loginData.apiurl = $scope.loginData.apiurl.slice(0, -1); + } - } + if ($scope.loginData.apiurl.slice(-1) == '/') { + $scope.loginData.apiurl = $scope.loginData.apiurl.slice(0, -1); - if ($scope.loginData.streamingurl.slice(-1) == '/') - { - $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -1); + } - } + if ($scope.loginData.streamingurl.slice(-1) == '/') { + $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -1); - if ($scope.loginData.eventServer.slice(-1) == '/') - { - $scope.loginData.eventServer = $scope.loginData.eventServer.slice(0, -1); + } - } - // strip cgi-bin if it is there but only at the end - // Nov 17 Don't mess with this path. centos uses zm-cgi-bin of all things + if ($scope.loginData.eventServer.slice(-1) == '/') { + $scope.loginData.eventServer = $scope.loginData.eventServer.slice(0, -1); - /*if ($scope.loginData.streamingurl.slice(-7).toLowerCase() == 'cgi-bin') { - $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -7); - }*/ + } + // strip cgi-bin if it is there but only at the end + // Nov 17 Don't mess with this path. centos uses zm-cgi-bin of all things + + /*if ($scope.loginData.streamingurl.slice(-7).toLowerCase() == 'cgi-bin') { + $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -7); + }*/ + + // check for protocol and if not put it in + + $scope.loginData.url = addhttp($scope.loginData.url); + $scope.loginData.apiurl = addhttp($scope.loginData.apiurl); + $scope.loginData.streamingurl = addhttp($scope.loginData.streamingurl); + $scope.loginData.eventServer = addWsOrWss($scope.loginData.eventServer); + + /* if ($scope.loginData.useSSL) + { + // replace all http with https + $scope.loginData.url = $scope.loginData.url.replace("http:", "https:"); + $scope.loginData.apiurl = $scope.loginData.apiurl.replace("http:", "https:"); + $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("http:", "https:"); + $scope.loginData.eventServer = $scope.loginData.eventServer.replace("ws:", "wss:"); + + } + else + { + // replace all https with http + $scope.loginData.url = $scope.loginData.url.replace("https:", "http:"); + $scope.loginData.apiurl = $scope.loginData.apiurl.replace("https:", "http:"); + $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("https:", "http:"); + // don't do it for WSS - lets mandate that + }*/ + + var apiurl = $scope.loginData.apiurl + '/host/getVersion.json'; + var portalurl = $scope.loginData.url + '/index.php'; + + // Check if isUseAuth is set make sure u/p have a dummy value + if ($scope.check.isUseAuth) { + if (!$scope.loginData.username) $scope.loginData.username = "x"; + if (!$scope.loginData.password) $scope.loginData.password = "x"; + //NVRDataModel.log("Authentication is disabled, setting dummy user & pass"); + } - // check for protocol and if not put it in + if (parseInt($scope.loginData.maxMontage) <= 0) { + $scope.loginData.maxMontage = "100"; + } - $scope.loginData.url = addhttp($scope.loginData.url); - $scope.loginData.apiurl = addhttp($scope.loginData.apiurl); - $scope.loginData.streamingurl = addhttp($scope.loginData.streamingurl); - $scope.loginData.eventServer = addWsOrWss($scope.loginData.eventServer); + // do this before setLogin so message is sent + + if (!$scope.check.isUseEventServer) { + $rootScope.isAlarm = 0; + if ($rootScope.apnsToken) { + NVRDataModel.log("Making sure we don't get push notifications"); + EventServer.sendMessage('push', { + type: 'token', + platform: $rootScope.platformOS, + token: $rootScope.apnsToken, + state: "disabled" + }, 1); + } + } - /* if ($scope.loginData.useSSL) - { - // replace all http with https - $scope.loginData.url = $scope.loginData.url.replace("http:", "https:"); - $scope.loginData.apiurl = $scope.loginData.apiurl.replace("http:", "https:"); - $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("http:", "https:"); - $scope.loginData.eventServer = $scope.loginData.eventServer.replace("ws:", "wss:"); + NVRDataModel.setLogin($scope.loginData); + + $rootScope.runMode = NVRDataModel.getBandwidth(); + + oldName = $scope.loginData.serverName; + + if ($scope.check.isUseEventServer) { + EventServer.init(); + if ($rootScope.apnsToken && $scope.loginData.disablePush != true) { + NVRDataModel.log("Making sure we get push notifications"); + EventServer.sendMessage('push', { + type: 'token', + platform: $rootScope.platformOS, + token: $rootScope.apnsToken, + state: "enabled" + }, 1); + } + EventServer.sendMessage("control", { + type: 'filter', + monlist: $scope.loginData.eventServerMonitors, + intlist: $scope.loginData.eventServerInterval + }); - } - else - { - // replace all https with http - $scope.loginData.url = $scope.loginData.url.replace("https:", "http:"); - $scope.loginData.apiurl = $scope.loginData.apiurl.replace("https:", "http:"); - $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("https:", "http:"); - // don't do it for WSS - lets mandate that - }*/ - - var apiurl = $scope.loginData.apiurl + '/host/getVersion.json'; - var portalurl = $scope.loginData.url + '/index.php'; - - // Check if isUseAuth is set make sure u/p have a dummy value - if ($scope.check.isUseAuth) - { - if (!$scope.loginData.username) $scope.loginData.username = "x"; - if (!$scope.loginData.password) $scope.loginData.password = "x"; - //NVRDataModel.log("Authentication is disabled, setting dummy user & pass"); - } + } - if (parseInt($scope.loginData.maxMontage) <= 0) - { - $scope.loginData.maxMontage = "100"; - } + zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0; color:#fff;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> " + $translate.instant('kAuthenticating') + "...</button>") + // Do the happy menu only if authentication works + // if it does not work, there is an emitter for auth + // fail in app.js that will be called to show an error + // box - // do this before setLogin so message is sent - - if (!$scope.check.isUseEventServer) - { - $rootScope.isAlarm = 0; - if ($rootScope.apnsToken) - { - NVRDataModel.log("Making sure we don't get push notifications"); - EventServer.sendMessage('push', - { - type: 'token', - platform: $rootScope.platformOS, - token: $rootScope.apnsToken, - state: "disabled" - }, 1); - } - } + .then(function (data) { - NVRDataModel.setLogin($scope.loginData); + // Now let's validate if the API works - $rootScope.runMode = NVRDataModel.getBandwidth(); - - oldName = $scope.loginData.serverName; - - if ($scope.check.isUseEventServer) - { - EventServer.init(); - if ($rootScope.apnsToken && $scope.loginData.disablePush != true) - { - NVRDataModel.log("Making sure we get push notifications"); - EventServer.sendMessage('push', - { - type: 'token', - platform: $rootScope.platformOS, - token: $rootScope.apnsToken, - state: "enabled" - }, 1); - } - EventServer.sendMessage("control", - { - type: 'filter', - monlist: $scope.loginData.eventServerMonitors, - intlist: $scope.loginData.eventServerInterval - }); + // note that due to reachability, it might have switched to another server + if ($scope.loginData.serverName != NVRDataModel.getLogin().serverName) { + NVRDataModel.debug(">>> Server information has changed, likely a fallback took over!"); + $scope.loginData = NVRDataModel.getLogin(); + apiurl = $scope.loginData.apiurl + '/host/getVersion.json'; + portalurl = $scope.loginData.url + '/index.php'; } - // lets logout - NVRDataModel.debug("Logging out of current session..."); - $rootScope.authSession = "undefined"; - - - $http( - { - method: 'POST', - timeout:10000, - //withCredentials: true, - url: $scope.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 params = str.join("&"); - return params; - }, + // possible image digits changed between servers + NVRDataModel.getKeyConfigParams(0); + + NVRDataModel.log("Validating APIs at " + apiurl); + $http.get(apiurl) + .success(function (data) { + + NVRDataModel.getTimeZone(true); + var loginStatus = $translate.instant('kExploreEnjoy') + " " + $rootScope.appName + "!"; + EventServer.refresh(); + + // now grab and report PATH_ZMS + NVRDataModel.getPathZms() + .then(function (data) { + var ld = NVRDataModel.getLogin(); + var zm_cgi = data.toLowerCase(); + + var user_cgi = (ld.streamingurl).toLowerCase(); + NVRDataModel.log("ZM relative cgi-path: " + zm_cgi + ", you entered: " + user_cgi); + + $http.get(ld.streamingurl + "/zms") + .success(function (data) { + NVRDataModel.debug("Urk! cgi-path returned success, but it should not have come here"); + loginStatus = $translate.instant('kLoginStatusNoCgi'); + + NVRDataModel.debug("refreshing API version..."); + NVRDataModel.getAPIversion() + .then(function (data) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = data; + }, + function (error) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = "0.0.0"; + NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); + }); - data: - { - action: "logout", - view: "login" - } - }) - .finally(function(ans) - { + if (showalert) { + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kLoginValidatedTitle'), + template: loginStatus, + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }).then(function (res) { - zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0; color:#fff;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> " + $translate.instant('kAuthenticating') + "...</button>") - // Do the happy menu only if authentication works - // if it does not work, there is an emitter for auth - // fail in app.js that will be called to show an error - // box + $ionicSideMenuDelegate.toggleLeft(); + NVRDataModel.debug("Force reloading monitors..."); - .then(function(data) - { + }); + } + }) + .error(function (error, status) { + // If its 5xx, then the cgi-bin path is valid + // if its 4xx then the cgi-bin path is not valid + + if (status < 500) { + loginStatus = $translate.instant('kLoginStatusNoCgiAlt'); + } - // Now let's validate if the API works + if (showalert) { + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kLoginValidatedTitle'), + template: loginStatus, + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }).then(function (res) { - // note that due to reachability, it might have switched to another server + $ionicSideMenuDelegate.toggleLeft(); + NVRDataModel.debug("Force reloading monitors..."); - if ($scope.loginData.serverName != NVRDataModel.getLogin().serverName) + }); + } else // make sure CGI error is always shown { - NVRDataModel.debug(">>> Server information has changed, likely a fallback took over!"); - $scope.loginData = NVRDataModel.getLogin(); - apiurl = $scope.loginData.apiurl + '/host/getVersion.json'; - portalurl = $scope.loginData.url + '/index.php'; + NVRDataModel.displayBanner((status < 500) ? 'error' : 'info', [loginStatus]); } - - // possible image digits changed between servers - NVRDataModel.getKeyConfigParams(0); - - NVRDataModel.log("Validating APIs at " + apiurl); - $http.get(apiurl) - .success(function(data) - { - - NVRDataModel.getTimeZone(true); - var loginStatus = $translate.instant('kExploreEnjoy') + " " + $rootScope.appName + "!"; - EventServer.refresh(); - - // now grab and report PATH_ZMS - NVRDataModel.getPathZms() - .then(function(data) - { - var ld = NVRDataModel.getLogin(); - var zm_cgi = data.toLowerCase(); - - var user_cgi = (ld.streamingurl).toLowerCase(); - NVRDataModel.log("ZM relative cgi-path: " + zm_cgi + ", you entered: " + user_cgi); - - $http.get(ld.streamingurl + "/zms") - .success(function(data) - { - NVRDataModel.debug("Urk! cgi-path returned success, but it should not have come here"); - loginStatus = $translate.instant('kLoginStatusNoCgi'); - - NVRDataModel.debug("refreshing API version..."); - NVRDataModel.getAPIversion() - .then(function(data) - { - var refresh = NVRDataModel.getMonitors(1); - $rootScope.apiVersion = data; - }, - function(error) - { - var refresh = NVRDataModel.getMonitors(1); - $rootScope.apiVersion = "0.0.0"; - NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); - }); - - if (showalert) - { - $rootScope.zmPopup = SecuredPopups.show('alert', - { - title: $translate.instant('kLoginValidatedTitle'), - template: loginStatus, - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }).then(function(res) - { - - $ionicSideMenuDelegate.toggleLeft(); - NVRDataModel.debug("Force reloading monitors..."); - - }); - } - }) - .error(function(error, status) - { - // If its 5xx, then the cgi-bin path is valid - // if its 4xx then the cgi-bin path is not valid - - if (status < 500) - { - loginStatus = $translate.instant('kLoginStatusNoCgiAlt'); - } - - if (showalert) - { - $rootScope.zmPopup = SecuredPopups.show('alert', - { - title: $translate.instant('kLoginValidatedTitle'), - template: loginStatus, - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }).then(function(res) - { - - $ionicSideMenuDelegate.toggleLeft(); - NVRDataModel.debug("Force reloading monitors..."); - - }); - } - else // make sure CGI error is always shown - { - NVRDataModel.displayBanner((status < 500)? 'error':'info', [loginStatus]); - } - NVRDataModel.debug("refreshing API version..."); - NVRDataModel.getAPIversion() - .then(function(data) - { - var refresh = NVRDataModel.getMonitors(1); - $rootScope.apiVersion = data; - }, - function(error) - { - var refresh = NVRDataModel.getMonitors(1); - $rootScope.apiVersion = "0.0.0"; - NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); - }); - - }); - }); - - }) - .error(function(error) - { - NVRDataModel.displayBanner('error', [$translate.instant('kBannerAPICheckFailed'), $translate.instant('kBannerPleaseCheck')]); - NVRDataModel.log("API login error " + JSON.stringify(error)); - - $rootScope.zmPopup = SecuredPopups.show('alert', - { - title: $translate.instant('kLoginValidAPIFailedTitle'), - template: $translate.instant('kBannerPleaseCheck'), - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }); + NVRDataModel.debug("refreshing API version..."); + NVRDataModel.getAPIversion() + .then(function (data) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = data; + }, + function (error) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = "0.0.0"; + NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); }); - }); - }); - } + }); + }); - // ---------------------------------------------- - // Saves the current profile. Note that - // calling saveItems also updates the defaultServer - //----------------------------------------------- - - $scope.saveItems = function() - { - - NVRDataModel.clearZmsMultiPortSupport(); - if (!$scope.loginData.serverName) - { - $rootScope.zmPopup = $ionicPopup.alert( - { - title: $translate.instant('kError'), - template: $translate.instant('kServerEmptyError'), - }) - .then(function(res) - { - return; - }); - } - else - { - saveItems(true); - availableServers = Object.keys(NVRDataModel.getServerGroups()); - serverbuttons = [ - { - text: $translate.instant('kServerAdd') + "..." - }]; - for (var servIter = 0; servIter < availableServers.length; servIter++) - { - serverbuttons.push( - { - text: availableServers[servIter] - }); - } - //console.log (">>>>>>>ionicview save: server buttons " + JSON.stringify(serverbuttons)); + }) + .error(function (error) { + NVRDataModel.displayBanner('error', [$translate.instant('kBannerAPICheckFailed'), $translate.instant('kBannerPleaseCheck')]); + NVRDataModel.log("API login error " + JSON.stringify(error)); - } + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kLoginValidAPIFailedTitle'), + template: $translate.instant('kBannerPleaseCheck'), + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }); + }); + }); + + } + + // ---------------------------------------------- + // Saves the current profile. Note that + // calling saveItems also updates the defaultServer + //----------------------------------------------- + + $scope.saveItems = function () { + + NVRDataModel.clearZmsMultiPortSupport(); + if (!$scope.loginData.serverName) { + $rootScope.zmPopup = $ionicPopup.alert({ + title: $translate.instant('kError'), + template: $translate.instant('kServerEmptyError'), + }) + .then(function (res) { + return; + }); + } else { + saveItems(true); + availableServers = Object.keys(NVRDataModel.getServerGroups()); + serverbuttons = [{ + text: $translate.instant('kServerAdd') + "..." + }]; + for (var servIter = 0; servIter < availableServers.length; servIter++) { + serverbuttons.push({ + text: availableServers[servIter] + }); + } + //console.log (">>>>>>>ionicview save: server buttons " + JSON.stringify(serverbuttons)); + + } - }; + }; }]); diff --git a/www/js/app.js b/www/js/app.js index 36a730c1..9bf7e0a7 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -617,7 +617,7 @@ angular.module('zmApp', [ .factory('timeoutHttpIntercept', ['$rootScope', '$q', 'zm', '$injector', function ($rootScope, $q, zm, $injector) { $rootScope.zmCookie = ""; //console.log ("HHHHHHHHHHHHHH**************************"); - + //console.log ("HERE TIMEOUT"); return { 'request': function (config) { @@ -646,6 +646,7 @@ angular.module('zmApp', [ if ($rootScope.zmCookie) { config.headers.Cookie = "ZMSESSID=" + $rootScope.zmCookie; + // console.log (">>>>> WOOOT HAVE COOKIE AND USING: "+$rootScope.zmCookie); } else { // console.log ("No cookie present in " + config.url); } @@ -690,7 +691,7 @@ angular.module('zmApp', [ if (zmSess) { if (zmSess[1]) { - // console.log ("***** SETTING COOKIE TO " + zmCookie); + //console.log ("***** SETTING COOKIE TO " + zmCookie); $rootScope.zmCookie = zmSess[1]; } } @@ -910,13 +911,23 @@ angular.module('zmApp', [ // which actually means auth failed, but ZM treats it as a success //------------------------------------------------------------------ - function doLogin(str) { + + function doLogoutAndLogin(str) { + return NVRDataModel.logout() + .finally(function(ans) { + doLogin(str); + + }); + } + function doLogin(str) { var d = $q.defer(); var ld = NVRDataModel.getLogin(); + console.log ("INSIDE REAL DO LOGIN"); + /*$rootScope.authSession = 'Test'; $rootScope.apiAuth = true; d.resolve ("Login Success"); @@ -1230,7 +1241,7 @@ angular.module('zmApp', [ return { start: start, stop: stop, - doLogin: doLogin + doLogin: doLogoutAndLogin }; }) @@ -1721,7 +1732,7 @@ angular.module('zmApp', [ }); $fileLogger.setStorageFilename(zm.logFile); - $fileLogger.setTimestampFormat('MMM d, y ' + NVRDataModel.getTimeFormat()); + $fileLogger.setTimestampFormat('MMM d, y ' + NVRDataModel.getTimeFormatSec()); if (NVRDataModel.getLogin().disableNative) { NVRDataModel.log("Disabling native transitions..."); |
