summaryrefslogtreecommitdiff
path: root/www/js/HelpCtrl.js
blob: 2e40914e2de4b0bff4fdb522f47cbea19a793858 (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
/* jshint -W041 */
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console, Masonry */

angular.module('zmApp.controllers').controller('zmApp.HelpCtrl', ['$scope', '$rootScope', '$ionicModal', 'NVR', '$ionicSideMenuDelegate', '$ionicHistory', '$state', '$translate', '$q', '$templateRequest', '$sce', '$compile', function ($scope, $rootScope, $ionicModal, NVR, $ionicSideMenuDelegate, $ionicHistory, $state, $translate, $q, $templateRequest, $sce, $compile) {
  $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("app.events", {
        "id": 0,
        "playEvent": false
      }, {
        reload: true
      });
      return;
    }
  };

  //----------------------------------------------------------------
  // This function dynamically inserts the relevant help text file
  // based on selected language
  //----------------------------------------------------------------

  function insertHelp() {

    var l = NVR.getDefaultLanguage() || 'en';
    var lang = "lang/help/help-" + l + ".html";
    //console.log ("LANG IS " + lang);
    var templateUrl = $sce.getTrustedResourceUrl(lang);
    var lang_fb = "lang/help/help-" + "en" + ".html";
    var templateUrlFB = $sce.getTrustedResourceUrl(lang_fb);

    $templateRequest(lang)
      .then(function (template) {
          var elem = angular.element(document.getElementById('insertHelp'));
          $compile(elem.html(template).contents())($scope);
        },
        function (error) {
          NVR.log("Language file " + lang + " not found, falling back");
          $templateRequest(templateUrlFB)
            .then(function (template) {
                var elem = angular.element(document.getElementById('insertHelp'));
                $compile(elem.html(template).contents())($scope);
              },
              function (error) {
                NVR.log("fallback help not found");
              });
        }
      );

  }

  $scope.launchUrl = function (url) {

    options = {
    };
    //console.log ('got '+url);
    if ($rootScope.platformOS == 'desktop' ) {
      window.open(url, '_blank', options);
    } else {
      cordova.InAppBrowser.open(url, '_blank', options);
    }
    

  };

  //-------------------------------------------------------------------------
  // 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 ** Help Ctrl Entered");
    NVR.setAwake(false);
    $scope.zmAppVersion = NVR.getAppVersion();
    insertHelp();

  });

}]);