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

angular.module('zmApp.controllers')
  .controller('zmApp.EventDateTimeFilterCtrl', ['$scope', '$ionicSlideBoxDelegate', '$ionicSideMenuDelegate', '$rootScope', '$ionicHistory', 'NVR', '$state', function ($scope, $ionicScrollDelegate, $ionicSideMenuDelegate, $rootScope, $ionicHistory, NVR, $state) {

      //----------------------------------------------------------------
      // 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.$on('$ionicView.beforeEnter', function () {
        $scope.today = moment().format("YYYY-MM-DD");
      });

      //--------------------------------------------------------------------------
      // Clears filters 
      //--------------------------------------------------------------------------

      $scope.removeFilters = function () {
        $rootScope.isEventFilterOn = false;
        $rootScope.fromDate = "";
        $rootScope.fromTime = "";
        $rootScope.toDate = "";
        $rootScope.toTime = "";
        $rootScope.fromString = "";
        $rootScope.toString = "";

        // if you come here via the events pullup
        // you are looking at a specific monitor ID
        // going back will only retain that monitor ID
        // so lets reload with all monitors
        // 
        //console.log (">>> BACKVIEW="+$ionicHistory.backTitle());

        if ($ionicHistory.backTitle() == 'Timeline') {
          $ionicHistory.goBack();
        } else // in events, backview is undefined?
        {
          $ionicHistory.nextViewOptions({
            disableBack: true
          });
          $state.go("app.events", {
            "id": 0,
            "playEvent": false
          });
          return;
        }

        //$ionicHistory.goBack();
      };

      //--------------------------------------------------------------------------
      // Saves filters in root variables so EventFilter can access it. I know:
      // don't root.
      //--------------------------------------------------------------------------
      $scope.saveFilters = function () {
        if (!$rootScope.fromDate) {
          //console.log("RESET fromDate");
          $rootScope.fromDate = new Date();
          NVR.debug("DateTimeFilter: resetting from date");
        }

        if (!$rootScope.toDate) {
          // console.log("RESET toDate");
          $rootScope.toDate = new Date();
          NVR.debug("DateTimeFilter: resetting to date");
        }

        if (!$rootScope.fromTime) {
          // console.log("RESET fromTime");
          $rootScope.fromTime = new Date(99, 5, 24, 0, 0, 0, 0); //moment().format("hh:mm:ss");
          NVR.debug("DateTimeFilter: resetting from time");
        }

        if (!$rootScope.toTime) {
          //console.log("RESET toTime");
          $rootScope.toTime = new Date(99, 5, 24, 23, 59, 59, 0);
          //$rootScope.toTime = "01:01:02"; //moment().format("hh:mm:ss");
          NVR.debug("DateTimeFilter: resetting to time");
        }

        if ($rootScope.fromDate > $rootScope.toDate) {
          NVR.log("From date > To Date, swapping");
          var t = $rootScope.fromDate;
          $rootScope.fromDate = $rootScope.toDate;
          $rootScope.toDate = t;
        }

        $rootScope.isEventFilterOn = true;
        $rootScope.fromString = moment($rootScope.fromDate).format("YYYY-MM-DD") + " " + moment($rootScope.fromTime).format("HH:mm:ss");

        $rootScope.toString = moment($rootScope.toDate).format("YYYY-MM-DD") + " " + moment($rootScope.toTime).format("HH:mm:ss");

        //console.log("CONCAT DATES " + temp);
        //
        // var startDate = moment(temp).format("YYYY-MM-DD hh:mm:ss");
        NVR.debug("DateTimeFilter: From/To is now: " + $rootScope.fromString + " & " + $rootScope.toString);
        $ionicHistory.goBack();
      };

    }

  ]);