Skip to content

Instantly share code, notes, and snippets.

@nicolasembleton
Created July 26, 2012 14:12
Show Gist options
  • Save nicolasembleton/3182280 to your computer and use it in GitHub Desktop.
Save nicolasembleton/3182280 to your computer and use it in GitHub Desktop.
App.homeTopNewsController = Ember.ArrayController.create({
content: [],
load: function() {
},
// Callback from SOAP callee
parse: function(data) {
},
// Returns 1st element for Top News
getTopNews: function() {
return this.content.length > 0 ? Ember.ArrayController.create({ content: [this.content[0]] }) : Ember.ArrayController.create({ content: [App.NewsObject.create()] });
}.property(),
// Returns elements 1 to 4 for Other Top News
get3OtherTopNews: function() {
return this.content.length > 1 ? Ember.ArrayController.create({ content: [this.content.slice(1,4)] }) : Ember.ArrayController.create({ content: [App.NewsObject.create()] });
}.property(),
// Returns elements 5 to 8 for Other Top News
get3LatestTopNews: function() {
console.log(this.content.slice(4,7));
return this.content.length > 3 ? Ember.ArrayController.create({ content: this.content.slice(4,7) }) : Ember.ArrayController.create({ content: [App.NewsObject.create()] });
}.property(),
init: function() {
// Do logic to get top news ( Soap )
for(var i=0;i<10;i++){
this.content.push(App.NewsObject.create({
id: i,
title: "Title"+i,
shortDescription: "shortDesc"+i,
longDescription: "longDesc"+i,
image: "apple-touch-icon-114x114-precomposed.png",
content: "article content"+i,
date: "1970-01-01"+i,
url : ""+i
}));
}
}
}); // automatically load, for debugging purpose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment