In this section, we add a session details view. Since the application now has more than one view, we also add a simple view routing mechanism.
Open index.html and add a template to render a detailed session view:
<script id="session-tpl" type="text/template">
<header class="bar bar-nav">
<a class="btn btn-link btn-nav pull-left" href="#">
<span class="icon icon-left-nav"></span>
</a>
<h1 class="title">Session Detail</h1>
</header>
<!-- NOTE: Bars MUST come before content -->
<nav class="bar bar-tab tabbar">
</nav>
<div class="content">
<div class="card">
<ul class="table-view">
<li class="table-view-cell media">
<img class="media-object pull-left" src="assets/pics/{{pic}}">
<div class="media-body">
{{ firstName }} {{ lastName }}
<p>{{ title }}</p>
</div>
<p>{{ room }} | {{ time }}</p>
</li>
<li class="table-view-cell media" style="min-height: 250px">
<div> <p>{{ description }}</p></div>
</li>
</ul>
</div>
</div>
var SessionView = function(session) {
this.initialize = function() {
this.$el = $('<div/>');
};
this.render = function() {
this.$el.html(this.template(session));
return this;
};
this.initialize();
}
<script src="js/SessionView.js"></script>
<script src="lib/router.js"></script>
SessionView.prototype.template = Handlebars.compile($("#session-tpl").html());
service.initialize().done(function () {
router.addRoute('', function() {
$('body').html(new HomeView(service).render().$el);
});
router.addRoute('sessions/:id', function(id) {
service.findById(parseInt(id)).done(function(session) {
$('body').html(new SessionView(session).render().$el);
});
});
router.start();
});
Test the application.