Skip to content

Commit

Permalink
Added GoldenEggUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyCC committed Feb 1, 2014
1 parent fa52018 commit 46ade2a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 26 deletions.
40 changes: 16 additions & 24 deletions client/app/scripts/controllers/facebook-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ angular.module('facebook')
// NB: this is a contrived example for demo purposes, you would never write the following code in a real app

// normally you would define a User.js data module for all your user objects and the method below would be on the user, e.g. $rootScope.currentUser.fbConnect()

ParseQueryAngular(Parse.FacebookUtils,{functionToCall:"logIn", params:[Parse.User.current(), "user_likes"]}).then(function(user) {
alert('facebook connected!');
ParseQueryAngular(Parse.FacebookUtils,{functionToCall:"logIn", params:[null,
{
success: function(users) {
FB.api(
"/me",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
},error: function(err){
console.log(err);
}
}
]}).then(function(user) {

$scope.facebookCtrl.fbAuthData = user.get('authData');

Expand All @@ -35,28 +48,7 @@ angular.module('facebook')

}

$scope.exampleCall = function() {

FB.apiAngular(
'/me/apprequests',
{ message: 'From the app to the user.' },
'POST')

.then(function(data) {

alert('FB Request Successfully Sent!');

$scope.facebookCtrl.response = data;

}, function(error) {

alert('FB Request Unsuccessful!');

$scope.facebookCtrl.response = error;

});

}


}]);
76 changes: 76 additions & 0 deletions client/app/scripts/modules/data/GoldenEggUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// reference the module we declared earlier
angular.module('ExternalDataServices')

// add a factory
.factory('GoldenEggUserService', ['ParseQueryAngular', function(ParseQueryAngular) {

var GoldenEggUser = Parse.Object.extendAngular({
className:"GoldenEggUser",
setUserId: function(id) {
this.set('userId',id);
return this;
},
setFaceBookId: function(id){
this.set('facebookId',id);
return this;
}
setRole: function(role) {
this.set('role', role);
return this;
},
getUserId: function(id) {
return this.get('userId');
},
getFaceookId: function(id){
return this.get('facebookId');
},
getRole: function(role) {
return this.get('role');
},
destroyParse:function(){
return ParseQueryAngular(this,{functionToCall:"destroy"});
}
});

var GoldenEggUsers = Parse.Collection.extendAngular({
model: GoldenEggUser,
comparator: function(model) {
return -model.createdAt.getTime();
},
loadGoldenEggUserWithId: function(id) {
this.query = (new Parse.Query(GoldenEggUser));
this.query.equalTo('id', id);
// use the enhanced load() function to fetch the collection
return this.load();
},
addGoldenEggUser: function(userId, facebookId, email, role) {
// save request_id to Parse
var _this = this;

var user = new GoldenEggUser;
user.setUser(userId);
user.setFacebookId(facebookId);
user.setRole(role);
user.setEmail(email);

// use the extended Parse SDK to perform a save and return the promised object back into the Angular world
return user.saveParse().then(function(data){
_this.add(data);
})
},
removeGoldenEggUser:function(user) {
if (!this.get(user)) return false;
var _this = this;
return user.destroyParse().then(function(){
_this.remove(user);
});
}
});

// Return a simple API : model or collection.
return {
model: GoldenEggUser,
collection: GoldenEggUsers
};

}]);
12 changes: 10 additions & 2 deletions client/app/scripts/modules/states/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ angular.module('facebook', ['ParseServices', 'ExternalDataServices'])

.state('demo.facebook', {
abstract: true,
templateUrl: 'app/views/app-layout.html'
templateUrl: 'app/views/app-layout.html',

})
.state('demo.facebook.example', {
url: '/facebook',
views: {
'detail@demo' : {
templateUrl: 'app/views/detail/facebook.example.html',
controller: 'FacebookExampleController'
controller: 'FacebookExampleController',
resolve: {

'goldenEggUsers':['GoldenEggUserService', function(GoldenEggUserService) {
var goldenEggUsers = new GoldenEggUserService.collection;
return goldenEggUsers.load();
}]
}
}

}
Expand Down

0 comments on commit 46ade2a

Please sign in to comment.