-
-
Save juarezpaf/6722956 to your computer and use it in GitHub Desktop.
This file contains 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
App.PostRoute = Em.Route.extend({ | |
model: function(params) { | |
return Em.$.ajax({ | |
type: 'GET', | |
url: App.API+'/post/'+ params.post_id, | |
dataType: 'json', | |
contentType: 'application/json', | |
context: this | |
}).then(function(json) { | |
if (json.status.code === 200) {//API return status code with success or errors | |
return App.Post.create(json.data[0]); | |
} else { | |
App.notification('Server is failing! Sorry! Try again later.', 'notification-error'); | |
} | |
}); | |
}, | |
setupController: function(controller, model) { | |
this.controllerFor('postIndex').set('content', model); | |
} | |
}); |
This file contains 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
App.PostsIndexRoute = Em.Route.extend({ | |
model: function() { | |
return Em.$.ajax({ | |
type: 'GET', | |
url: App.API+'/posts', | |
dataType: 'json', | |
contentType: 'application/json', | |
context: this | |
}).then(function(json) { | |
if (json.status.code === 200) { | |
var posts = Em.A(); | |
json.data.forEach(function (post){ | |
posts.pushObject(App.Post.create(post)); | |
}); | |
return posts; | |
} else { | |
App.notification('Server is failing! Sorry! Try again later.', 'notification-error'); | |
} | |
}); | |
} | |
}); |
This file contains 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
var pusher = new Pusher('APP_KEY'); | |
var eventName = 'new-comment'; | |
var callback = function(data) { | |
var applicationRoute = App.__container__.lookup('route:application'); | |
Em.A(data).map(function(comment){ | |
applicationRoute.findModel( "post", comment.post_id ); | |
post.comments.push(App.Comment.create(comment)); | |
}); | |
}; | |
pusher.bind(eventName, callback); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment