arnaucube
arnaucube/commonroutesAppPublic Self-hosted repository
commonroutesApp/www/js/travels.js
www/js/travels.jsRaw
 1angular.module('app.travels', ['pascalprecht.translate'])
 2
 3  .controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) {
 4    $scope.loadMorePagination = true;
 5
 6    $scope.travels = [];
 7    $scope.page = 0;
 8    $scope.doRefresh = function() {
 9      /* travels refresh: */
10      $http.get(urlapi + 'travels?page=' + $scope.page)
11        .then(function(data) {
12          console.log('data success travels');
13          console.log(data); // for browser console
14          //$scope.travels = data.data; // for UI
15          $scope.travels = $scope.travels.concat(data.data);
16          $scope.$broadcast('scroll.refreshComplete'); //refresher stop
17          $scope.$broadcast('scroll.infiniteScrollComplete');
18          if (data.data.length < 1) {
19              console.log("setting loadMorePagination to false");
20            $scope.loadMorePagination = false;
21            $scope.$broadcast('scroll.infiniteScrollComplete');
22          }
23
24        }, function(data) {
25          console.log('data error');
26          $scope.$broadcast('scroll.refreshComplete'); //refresher stop
27          $ionicLoading.show({
28            template: 'Error connecting server',
29            noBackdrop: true,
30            duration: 2000
31          });
32
33        });
34    };
35    $scope.doRefresh();
36
37    $scope.paginationNext = function() {
38      if ($scope.loadMorePagination == true) {
39        $scope.page++;
40        console.log($scope.page);
41        $scope.doRefresh();
42    }else{
43        console.log("limit pagination reached");
44        $scope.$broadcast('scroll.infiniteScrollComplete');
45    }
46    };
47  });