Skip to content

Instantly share code, notes, and snippets.

@ascsystems
Created August 31, 2013 20:11
Show Gist options
  • Select an option

  • Save ascsystems/6400333 to your computer and use it in GitHub Desktop.

Select an option

Save ascsystems/6400333 to your computer and use it in GitHub Desktop.
(function(Notification) {
var app = k12.app;
Notification.Model = Backbone.Model.extend({ });
Notification.NotificationCollection = Backbone.Collection.extend({
parse: function(response) {
return response;
}
});
Notification.Collection = Backbone.Collection.extend({
model: Notification.Model,
url: '/api/notifications',
initialize: function(){
this.set({
notifications: new Notification.NotificationCollection(this.get('notifications'))
});
},
parse: function(response) {
return response;
}
});
Notification.Views.List = Backbone.View.extend({
template: 'notifications',
serialize: function() {
return { notifications: this.collection.toJSON() };
},
beforeRender: function() {
$("#notification_count").html(this.collection.count);
this.collection.each(function(m) {
this.insertView('.notification_type', new Notification.Views.Type({collection: m }));
}, this);
}
});
Notification.Views.Type = Backbone.View.extend({
template: 'notification_type',
serialize: function() {
return { notification_type: this.collection.toJSON() };
},
beforeRender: function() {
this.collection.get('notifications').each(function(m) {
this.insertView('.notification_items', new Notification.Views.Detail({model: m}));
}, this);
}
});
Notification.Views.Detail = Backbone.View.extend({
template: 'notification_item',
serialize: function() {
return { notification: this.model.toJSON() };
}
});
})(k12.module("notification"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment