Created
May 17, 2014 21:41
-
-
Save fedeisas/2d8a2d557e0a4de29ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('api', []) | |
.factory('Photos', ['$http', function ($http) { | |
return { | |
items: [], | |
busy: true, | |
stadium_id: null, | |
max_id: null, | |
hasMore: true, | |
resetItems: function () { | |
this.items = []; | |
}, | |
setStadium: function (id) { | |
this.stadium_id = id; | |
}, | |
initialPhotos: function () { | |
var self = this; | |
$http({ | |
method: 'GET', | |
url: 'http://api.worldcupgram.com/stadium/' + this.stadium_id + '/photos', | |
cache: true | |
}).success(function (result) { | |
if (result.data.length > 0) { | |
self.max_id = result.pagination.next_max_id; | |
for (var i = result.data.length - 1; i >= 0; i--) { | |
self.items.push(result.data[i]); | |
} | |
} else { | |
self.hasMore = false; | |
} | |
self.busy = false; | |
}); | |
}, | |
loadMore: function () { | |
this.busy = true; | |
var self = this; | |
$http({ | |
method: 'GET', | |
url: 'http://api.worldcupgram.com/stadium/' + this.stadium_id + '/photos', | |
params: { | |
max_id: this.max_id | |
}, | |
cache: true | |
}).success(function (result) { | |
if (result.data.length) { | |
self.max_id = result.pagination.next_max_id; | |
for (var i = result.data.length - 1; i >= 0; i--) { | |
self.items.push(result.data[i]); | |
} | |
} else { | |
self.hasMore = false; | |
} | |
self.busy = false; | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment