Advertisement
Guest User

controllers.js

a guest
Aug 7th, 2014
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. angular.module('sociogram.controllers', [])
  2.  
  3. .controller('AppCtrl', function ($scope, $state, OpenFB) {
  4.  
  5. $scope.logout = function () {
  6. OpenFB.logout().then(
  7. function () {
  8. $state.go('app.login');
  9. },
  10. function () {
  11. alert('Logout failed');
  12. });
  13. };
  14.  
  15. $scope.revokePermissions = function () {
  16. OpenFB.revokePermissions().then(
  17. function () {
  18. $state.go('app.login');
  19. },
  20. function () {
  21. alert('Revoke permissions failed');
  22. });
  23. };
  24.  
  25. })
  26.  
  27. .controller('LoginCtrl', function ($scope, $location, OpenFB) {
  28.  
  29. $scope.facebookLogin = function () {
  30.  
  31. OpenFB.login('email,read_stream,publish_actions').then(
  32. function () {
  33. $location.path('/app/person/me/feed');
  34. },
  35. function () {
  36. alert('OpenFB login failed');
  37. });
  38. };
  39.  
  40. })
  41.  
  42. .controller('ShareCtrl', function ($scope, OpenFB) {
  43.  
  44. $scope.item = {};
  45.  
  46. $scope.share = function () {
  47. OpenFB.post('/me/feed', $scope.item)
  48. .success(function () {
  49. $scope.status = "This item has been shared on OpenFB";
  50. })
  51. .error(function(data) {
  52. alert(data.error.message);
  53. });
  54. };
  55.  
  56. })
  57.  
  58. .controller('ProfileCtrl', function ($scope, OpenFB) {
  59. OpenFB.get('/me').success(function (user) {
  60. $scope.user = user;
  61. });
  62. })
  63.  
  64. .controller('PersonCtrl', function ($scope, $stateParams, OpenFB) {
  65. OpenFB.get('/' + $stateParams.personId).success(function (user) {
  66. $scope.user = user;
  67. });
  68. })
  69.  
  70. .controller('FriendsCtrl', function ($scope, $stateParams, OpenFB) {
  71. OpenFB.get('/' + $stateParams.personId + '/friends', {limit: 50})
  72. .success(function (result) {
  73. $scope.friends = result.data;
  74. })
  75. .error(function(data) {
  76. alert(data.error.message);
  77. });
  78. })
  79.  
  80. .controller('MutualFriendsCtrl', function ($scope, $stateParams, OpenFB) {
  81. OpenFB.get('/' + $stateParams.personId + '/mutualfriends', {limit: 50})
  82. .success(function (result) {
  83. $scope.friends = result.data;
  84. })
  85. .error(function(data) {
  86. alert(data.error.message);
  87. });
  88. })
  89.  
  90. .controller('FeedCtrl', function ($scope, $stateParams, OpenFB, $ionicLoading) {
  91.  
  92. $scope.show = function() {
  93. $scope.loading = $ionicLoading.show({
  94. content: 'Loading feed...'
  95. });
  96. };
  97. $scope.hide = function(){
  98. $scope.loading.hide();
  99. };
  100.  
  101. function loadFeed() {
  102. $scope.show();
  103. OpenFB.get('/' + $stateParams.personId + '/home', {limit: 30})
  104. .success(function (result) {
  105. $scope.hide();
  106. $scope.items = result.data;
  107. // Used with pull-to-refresh
  108. $scope.$broadcast('scroll.refreshComplete');
  109. })
  110. .error(function(data) {
  111. $scope.hide();
  112. alert(data.error.message);
  113. });
  114. }
  115.  
  116. $scope.doRefresh = loadFeed;
  117.  
  118. loadFeed();
  119.  
  120. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement