summaryrefslogtreecommitdiff
path: root/www/js/EventCtrl.js
blob: 84764f199c54947eafac1a181d8e0764857a26ad (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
// This is the controller for Event view. StateParams is if I recall the monitor ID.
// This was before I got access to the new APIs. FIXME: Revisit this code to see what I am doing with it
// and whether the new API has a better mechanism

angular.module('zmApp.controllers').controller('zmApp.EventCtrl', function ($ionicPlatform, $scope, $stateParams, message, ZMDataModel,$ionicSideMenuDelegate, $ionicModal) {
    console.log("I got STATE PARAM " + $stateParams.id);
    $scope.id = parseInt($stateParams.id,10);

$scope.openMenu = function () {
    $ionicSideMenuDelegate.toggleLeft();
  }

// This is a modal to show the event footage
$ionicModal.fromTemplateUrl('templates/events-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  })
    .then(function(modal) {
    $scope.modal = modal;

  });


$scope.openModal = function(eid,ename,edur) {
      console.log ("Open Modal");
    $scope.eventName = ename;
    $scope.eventId = eid;
    $scope.eventDur = Math.round(edur);
    $scope.loginData = ZMDataModel.getLogin();
    $scope.modal.show();
  };
  $scope.closeModal = function() {
      console.log ("Close Modal");
    $scope.modal.hide();

  };
  //Cleanup the modal when we're done with it!
  $scope.$on('$destroy', function() {
      console.log ("Destroy Modal");
    $scope.modal.remove();
  });

    console.log("***CALLING EVENTS FACTORY");
    var lData = ZMDataModel.getLogin();
    console.log("ZM Service Username = " + lData.username);
    $scope.monitors = message;
    $scope.events = ZMDataModel.getEvents($scope.id)
        .then(function (data) {
            console.log("EventCtrl Got events");
            //var events = [];
            var myevents = data;
            for (var i = 0; i < myevents.length; i++) {

                myevents[i].Event.MonitorName = ZMDataModel.getMonitorName(myevents[i].Event.MonitorId);
            }


            $scope.events = myevents;
        });



    $scope.doRefresh = function () {
        console.log("***Pull to Refresh");
        $scope.events = [];
        $scope.events = ZMDataModel.getEvents($scope.id)
            .then(function (data) {
                console.log("EventCtrl Got events");
                //var events = [];
                var myevents = data;
                for (var i = 0; i < myevents.length; i++) {

                    myevents[i].Event.MonitorName = ZMDataModel.getMonitorName(myevents[i].Event.MonitorId);
                }


                $scope.events = myevents;
                $scope.$broadcast('scroll.refreshComplete');
            });
    }; //dorefresh

});