You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. angular.module('app.users', ['pascalprecht.translate'])
  2. .controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) {
  3. $scope.users = [];
  4. $scope.loadMorePagination = true;
  5. $scope.page = 0;
  6. //$scope.users = JSON.parse(localStorage.getItem('c_users'));
  7. $scope.doRefresh = function() {
  8. /* users refresh: */
  9. $http.get(urlapi + 'users?page=' + $scope.page)
  10. .then(function(data) {
  11. console.log('data success');
  12. console.log(data);
  13. $scope.users = $scope.users.concat(data.data);
  14. $scope.$broadcast('scroll.refreshComplete'); //refresher stop
  15. $scope.$broadcast('scroll.infiniteScrollComplete');
  16. if (data.data.length < 1) {
  17. console.log("setting loadMorePagination to false");
  18. $scope.loadMorePagination = false;
  19. $scope.$broadcast('scroll.infiniteScrollComplete');
  20. }
  21. /*localStorage.setItem('c_users', JSON.stringify($scope.users));
  22. $scope.$broadcast('scroll.refreshComplete'); //refresher stop
  23. //set userdata
  24. $scope.userdata = $filter('filter')($scope.users, {
  25. username: $scope.storageusername
  26. }, true)[0];
  27. console.log("userdata");
  28. console.log($scope.userdata);
  29. localStorage.setItem("c_userdata", JSON.stringify($scope.userdata));*/
  30. }, function(data) {
  31. console.log('data error');
  32. $scope.$broadcast('scroll.refreshComplete'); //refresher stop
  33. $ionicLoading.show({
  34. template: 'Error connecting server',
  35. noBackdrop: true,
  36. duration: 2000
  37. });
  38. });
  39. };
  40. $scope.doRefresh();
  41. $scope.paginationNext = function() {
  42. if ($scope.loadMorePagination == true) {
  43. $scope.page++;
  44. console.log($scope.page);
  45. $scope.doRefresh();
  46. } else {
  47. console.log("limit pagination reached");
  48. $scope.$broadcast('scroll.infiniteScrollComplete');
  49. }
  50. };
  51. });