Skip to content

Instantly share code, notes, and snippets.

@jackkitley
Created January 24, 2013 11:48
Show Gist options
  • Save jackkitley/4620545 to your computer and use it in GitHub Desktop.
Save jackkitley/4620545 to your computer and use it in GitHub Desktop.
Ember js controller with computed properties
App.DashboardController = Em.ArrayController.extend({
content: [],
// contentRecent: Em.ArrayController.create({
// content: [],
// count: Em.computed(function() {
// return this.get('content').length;
// }).property('content.@each')
// }),
// contentWhatsnew: Em.ArrayController.create({
// content: [],
// count: Em.computed(function() {
// return this.get('content').length;
// }).property('content.@each')
// }),
// contentMessages: Em.ArrayController.create({
// content: [],
// count: Em.computed(function() {
// return this.get('content').length;
// }).property('content.@each')
// }),
// contentActivities: Em.ArrayController.create({
// content: [],
// count: Em.computed(function() {
// return this.get('content').length;
// }).property('content.@each')
// }),
templatehtmltext: '',
init: function() {
var me = this;
//me.loadContent();
},
loadContent: function() {
var me = this;
me.set('content', []);
var recentItemsController = App.RecentItemsController.create();
recentItemsController.set('content', []);
// App.WhatsNew.set('content', []);
// App.Messages.set('content', []);
// App.Activities.set('content', []);
$.post('data/Ajax.php', {'class': 'App', 'method': 'getDashboardObjects', 'params': ['']}, function(data) {
if (data) {
if (data.templatehtmltext) me.set('templatehtmltext', data.templatehtmltext);
if (data['recent']) recentItemsController.pushObjects(data['recent']);
// if (data['whatsnew']) me.get('contentWhatsnew').pushObjects(data['whatsnew']);
// if (data['messages']) me.get('contentMessages').pushObjects(data['messages']);
// if (data['activities']) me.get('contentActivities').pushObjects(data['activities']);
}
}, 'json');
}
});
App.RecentItemsController = Em.ArrayController.extend({
content: [],
count: Em.computed(function() {
return this.get('content').length;
}).property('content.@each')
});
App.WhatsNewController = Em.ArrayController.extend({
content: [],
count: Em.computed(function() {
return this.get('content').length;
}).property('content.@each')
});
App.MessagesController = Em.ArrayController.extend({
content: [],
count: Em.computed(function() {
return this.get('content').length;
}).property('content.@each')
});
App.ActivitiesController = Em.ArrayController.extend({
content: [],
count: Em.computed(function() {
return this.get('content').length;
}).property('content.@each')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment