summaryrefslogtreecommitdiff
path: root/www/js/DevOptionsCtrl.js
blob: 2ad40bfa19996f810328a97039e58defc614bcdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */

angular.module('zmApp.controllers').controller('zmApp.DevOptionsCtrl', ['$scope', '$rootScope', '$ionicModal', 'zm', 'NVR', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', '$ionicHistory', '$state', 'SecuredPopups', '$translate','$ionicActionSheet', function ($scope, $rootScope, $ionicModal, zm, NVR, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, $ionicHistory, $state, SecuredPopups, $translate, $ionicActionSheet) {

  $scope.openMenu = function () {
    $ionicSideMenuDelegate.toggleLeft();
    // $scope.this.will.crash = 1;

  };

  
  //----------------------------------------------------------------
  // 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;
    }
  };

  //----------------------------------------------------------------
  // Save anyway when you exit
  //----------------------------------------------------------------

  $scope.$on('$ionicView.beforeLeave', function () {
    saveDevOptions();

  });

  //-------------------------------------------------------------------------
  // 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.beforeEnter', function () {

    $scope.$on ( "process-push", function () {
      NVR.debug (">> DevOptionsCtrl: push handler");
      var s = NVR.evaluateTappedNotification();
      NVR.debug("tapped Notification evaluation:"+ JSON.stringify(s));
      $ionicHistory.nextViewOptions({
        disableAnimate:true,
        disableBack: true
      });
      $state.go(s[0],s[1],s[2]);
    });
  

    //console.log("**VIEW ** DevOptions Ctrl Entered");
    $scope.loginData = NVR.getLogin();
    //console.log("DEV LOGS=" + $scope.loginData.enableLogs);

    $scope.isMultiPort = false;

    NVR.getZmsMultiPortSupport()
      .then(function (data) {
        $scope.isMultiPort = (data == 0) ? false : true;
        NVR.debug("Multiport report:" + $scope.isMultiPort);
      });


    NVR.setAwake(false);
  });

  $scope.isTzSupported = function () {
    return NVR.isTzSupported();
  };

  $scope.getTimeZoneNow = function () {
    return NVR.getTimeZoneNow();
  };

  $scope.checkMultiPortToggle = function () {
    //  if ($rootScope.platformOS == 'ios')
    //    $scope.loginData.disableSimulStreaming = true;
  };
  //------------------------------------------------------------------
  // Perform the login action when the user submits the login form
  //------------------------------------------------------------------

  function saveDevOptions() {
    NVR.debug("SaveDevOptions: called");

    //console.log (JSON.stringify($scope.loginData));
    if (typeof $scope.loginData.zmNinjaCustomId !== 'undefined') {
      $scope.loginData.zmNinjaCustomId = $scope.loginData.zmNinjaCustomId.replace(/\s+/g, '_');

    }
    
    if (parseInt($scope.loginData.cycleMonitorsInterval) < zm.minCycleTime) {
      $scope.loginData.cycleMonitorsInterval = zm.minCycleTime.toString();
    }
    if ((parseInt($scope.loginData.maxFPS) < 0) || (parseInt($scope.loginData.maxFPS) > zm.maxFPS)) {
      $scope.loginData.maxFPS = zm.defaultFPS.toString();
    }

    if (parseInt($scope.loginData.refreshSec) <= 0) {
      NVR.debug("SaveDevOptions: refresh sec was too low at " +
        $scope.loginData.refreshSec + " reset to 1");
      $scope.loginData.refreshSec = 1;

    }

    // make sure only ints are used as CSS classes only use ints
    // in grid scale
    $scope.loginData.montageResizeSteps = parseFloat($scope.loginData.montageResizeSteps);

    if ($scope.loginData.montageResizeSteps < 0.05) {
      $scope.loginData.montageResizeSteps = 0.05;

    }

    if ($scope.loginData.montageResizeSteps > 50) {
      $scope.loginData.montageResizeSteps = 50;

    }

    if ((parseInt($scope.loginData.montageQuality) < zm.safeMontageLimit) ||
      (parseInt($scope.loginData.montageQuality) > 100)) {
      $scope.loginData.montageQuality = 100;
    }

    if ((parseInt($scope.loginData.singleImageQuality) < zm.safeImageQuality) ||
      (parseInt($scope.loginData.singleImageQuality) > 100)) {
      $scope.loginData.singleImageQuality = zm.safeImageQuality.toString();
    }


    NVR.debug("SaveDevOptions: Saving to disk");
    NVR.setLogin($scope.loginData);
    NVR.getMonitors(1);

  }

  $scope.useDefaultCustom = function() {
    if ($scope.loginData.zmNinjaCustomId=='') {
      $scope.loginData.zmNinjaCustomId = 'zmNinja_%APPVER%';
    }
   

  };

  $scope.selectObfuscationScheme = function() {

    var buttons = [
      { text: $translate.instant('kObfuscationLZS'), value:'lzs' },
      { text: $translate.instant('kObfuscationAES'), value:'aes' },
     
    ];

    $ionicActionSheet.show({
      titleText: $translate.instant('kSelect'),
      buttons: buttons,
    
      cancelText: $translate.instant('kButtonCancel'),
      cancel: function() {
       NVR.debug ('obfuscation actionsheet cancelled');
      },
      buttonClicked: function(index) {
       
        $scope.loginData.obfuscationScheme = buttons[index].value;
        NVR.debug ('changed obfuscation scheme to:'+$scope.loginData.obfuscationScheme );
        return true;
      },
     
    });
  };

  $scope.saveDevOptions = function () {

    saveDevOptions();
    // $rootScope.zmPopup.close();
    $rootScope.zmPopup = SecuredPopups.show('alert', {
      title: $translate.instant('kSettingsSaved'),
      template: "{{'kExploreEnjoy' | translate }} {{$root.appName}}",
      okText: $translate.instant('kButtonOk'),
      cancelText: $translate.instant('kButtonCancel'),
    }).then(function (res) {
      $ionicSideMenuDelegate.toggleLeft();
    });

  };
  //------------------------------------------------------------------
  // controller main
  //------------------------------------------------------------------

}]);