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          }
22
23        }, function(data) {
24          console.log('data error');
25          $scope.$broadcast('scroll.refreshComplete'); //refresher stop
26          $ionicLoading.show({
27            template: 'Error connecting server',
28            noBackdrop: true,
29            duration: 2000
30          });
31
32        });
33    };
34    $scope.doRefresh();
35
36    $scope.paginationNext = function() {
37      if ($scope.loadMorePagination == true) {
38        $scope.page++;
39        console.log($scope.page);
40        $scope.doRefresh();
41    }else{
42        console.log("limit pagination reached");
43        $scope.$broadcast('scroll.infiniteScrollComplete');
44    }
45    };
46  });