poconsole.controller('eventsCtrl', function($scope, $q, $http, Page) {
    Page.setTitle('Events');
    Page.setPage('events');

    var getEventsDataPage = function(page_number){
        var deferred = $q.defer();
        $http.get('/api/events?q={"order_by":[{"field":"created_on","direction":"desc"}]}&page=' + page_number).success(function(data) {
        	deferred.resolve(data);
        });
        return deferred.promise;
    };

    $scope.loadEventPageData = function(page_number){
        var getData = getEventsDataPage(page_number);
        getData.then(function(d){
            for(var j = 0; j < d.objects.length; j++){
                // console.log({'Date Before':d.objects[j].created_on});
                d.objects[j].created_on = Date.create(d.objects[j].created_on + "Z", { fromUTC: true });
                // console.log({'Date After':d.objects[j].created_on});
            }
            $scope.event_data = d.objects;
            $scope.num_pages = d.total_pages;
            $scope.page_list = [];
            $scope.page_num = d.page;
            $scope.total = d.total;
        });
    };

    $scope.loadEventPageData(1);



});
