Skip to content

Commit

Permalink
implement routing, and first route
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsulc committed Oct 22, 2013
1 parent 91e237d commit 712ee23
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion assets/js/app.js
Expand Up @@ -4,6 +4,21 @@ ContactManager.addRegions({
mainRegion: "#main-region"
});

ContactManager.navigate = function(route, options){
options || (options = {});
Backbone.history.navigate(route, options);
};

ContactManager.getCurrentRoute = function(){
return Backbone.history.fragment
};

ContactManager.on("initialize:after", function(){
ContactManager.ContactsApp.List.Controller.listContacts();
if(Backbone.history){
Backbone.history.start();

if(this.getCurrentRoute() === ""){
ContactManager.trigger("contacts:list");
}
}
});
24 changes: 24 additions & 0 deletions assets/js/apps/contacts/contacts_app.js
@@ -0,0 +1,24 @@
ContactManager.module("ContactsApp", function(ContactsApp, ContactManager, Backbone, Marionette, $, _){
ContactsApp.Router = Marionette.AppRouter.extend({
appRoutes: {
"contacts": "listContacts"
}
});

var API = {
listContacts: function(){
ContactsApp.List.Controller.listContacts();
}
};

ContactManager.on("contacts:list", function(){
ContactManager.navigate("contacts");
API.listContacts();
});

ContactManager.addInitializer(function(){
new ContactsApp.Router({
controller: API
});
});
});
2 changes: 2 additions & 0 deletions index.html
Expand Up @@ -61,6 +61,8 @@ <h1><%= firstName %> <%= lastName %></h1>

<script src="./assets/js/app.js"></script>
<script src="./assets/js/entities/contact.js"></script>

<script src="./assets/js/apps/contacts/contacts_app.js"></script>
<script src="./assets/js/apps/contacts/list/list_view.js"></script>
<script src="./assets/js/apps/contacts/list/list_controller.js"></script>
<script src="./assets/js/apps/contacts/show/show_view.js"></script>
Expand Down

0 comments on commit 712ee23

Please sign in to comment.