Skip to content

Instantly share code, notes, and snippets.

@ascsystems
Created August 24, 2013 00:58
Show Gist options
  • Select an option

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

Select an option

Save ascsystems/6325348 to your computer and use it in GitHub Desktop.
Backbone.Layout.extend({
manage: true,
prefix: "/scripts/modules/templates/",
fetchTemplate: function(path) {
var done = this.async();
$.get(path + '.html', function(contents) {
done(contents);
});
},
renderTemplate: function(template, context) {
return Handlebars.compile(template)(context);
}
});
this.k12 = {
module: function() {
var modules = {};
return function(name) {
if(modules[name]) {
return modules[name];
}
return modules[name] = { Views: {} }
};
}(),
app: _.extend({}, Backbone.Events)
};
jQuery(function($) {
var app = k12.app;
var Notification = k12.module("notification");
var Router = Backbone.Router.extend({
routes: {
"": "index"
},
fetchNotifications: function() {
var _cache;
return function(done) {
if(_cache) {
return done(_cache);
}
var notifications = new Notification.Collection();
notifications.fetch().success(function(){
_cache = notifications;
done(_cache);
});
};
}(),
index: function() {
var main = new Backbone.Layout({
name: "main"
});
this.fetchNotifications(function(notifications) {
var notifications_list = main.views[".notifications_list"] = new Notification.Views.List({ collection: notifications });
main.render().done(function(contents) {
$(".container").html(contents);
});
});
}
});
app.rounter = new Router();
Backbone.history.start();
});
(function(Notification) {
var app = k12.app;
Notification.Collection = Backbone.Collection.extend({
url: '/api/notifications'
});
Notification.Views.List = Backbone.View.extend({
template: 'notification',
serialize: function() {
return { notifications: this.collection.toJSON() };
}
});
Notification.Views.Detail = Backbone.View.extend({
template: 'notification_detail',
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