Skip to content

Instantly share code, notes, and snippets.

@BorisKozo
Forked from smykes/main.js
Last active December 18, 2015 13:19
Show Gist options
  • Save BorisKozo/5789198 to your computer and use it in GitHub Desktop.
Save BorisKozo/5789198 to your computer and use it in GitHub Desktop.
var AppRouter = Backbone.Router.extend({
routes: {
"" : "list",
"clients/:id" : "clientDetails"
},
initialize: function () {
},
list: function(page) {
$('#header').html(new HeaderView().render().el);
var clientList = new ClientCollection();
clientList.fetch({success: function(){
$("#content").html(new ClientListView({model: clientList}).el);
}})
},
clientDetails: function (id) {
var taskList = new TaskCollection([],{clientId: id});
$('#header').html(new HeaderView().render().el);
taskList.fetch({
success: function(data){
$("#content").html(new TaskListView({model: taskList}).el);
},
error: function() {
alert("error");
}
})
}
});
app = new AppRouter();
Backbone.history.start();
window.Client = Backbone.Model.extend({
urlRoot: "api/client_list",
defaults: {
id: null,
name: null,
city: null,
state: null
}
});
window.ClientCollection = Backbone.Collection.extend({
model: Client,
url: "api/client_list"
});
window.Task = Backbone.Model.extend({
defaults: {
id: null
}
});
window.TaskCollection = Backbone.Collection.extend({
model: Task,
initialize: function(models, options){
this.options = options;
},
url: function(){ return "api/client/"+this.options.clientId;}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment