Skip to content

Commit

Permalink
Current to Part 7 of the blog series - http://brianmajewski.com/2015/…
Browse files Browse the repository at this point in the history
  • Loading branch information
bmajewski committed Feb 22, 2015
1 parent e55dbc2 commit c29507a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/routes/user.js
Expand Up @@ -49,7 +49,7 @@ module.exports = function (app, express) {
if (err) res.send(err); if (err) res.send(err);


if (req.body.name) user.name = req.body.name; if (req.body.name) user.name = req.body.name;
if (req.body.username) user.username = req.body.username; if (req.body.email) user.email = req.body.email;
if (req.body.password) user.password = req.body.password; if (req.body.password) user.password = req.body.password;


user.save(function (err) { user.save(function (err) {
Expand Down
5 changes: 4 additions & 1 deletion bower.json
Expand Up @@ -21,6 +21,9 @@
"jquery": "~2.1.3", "jquery": "~2.1.3",
"handlebars": "~3.0.0", "handlebars": "~3.0.0",
"requirejs-text": "~2.0.14", "requirejs-text": "~2.0.14",
"require-handlebars-plugin": "~0.11.2" "require-handlebars-plugin": "~0.11.2",
"font-awesome": "~4.3.0",
"datatables": "~1.10.5",
"datatables-bootstrap3-plugin": "~0.3.0"
} }
} }
3 changes: 3 additions & 0 deletions public/app/page/headerTemplate.hbs
Expand Up @@ -4,6 +4,9 @@
<div class="navbar-header"> <div class="navbar-header">
<a href="/" class="navbar-brand"><b>relearning backbone</b></a> <a href="/" class="navbar-brand"><b>relearning backbone</b></a>
</div> </div>
<ul class="nav navbar-nav">
<li><a href="#users"><span class="fa fa-users"></span> Users</a></li>
</ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
[Navigation Elements] [Navigation Elements]
</ul> </ul>
Expand Down
13 changes: 12 additions & 1 deletion public/app/router.js
Expand Up @@ -15,7 +15,18 @@ define(function (require) {


routes: { routes: {
'': 'home', '': 'home',
'home': 'home' 'home': 'home',
'users': 'users'
},

users: function() {
console.log('routing - users');
require(['users/collection', 'users/listView'], function(Collection, View) {
var collection = new Collection();
collection.fetch().done(function(){
mediator.trigger('page:displayView', new View({collection: collection}));
});
});
}, },


home: function () { home: function () {
Expand Down
11 changes: 11 additions & 0 deletions public/app/users/collection.js
@@ -0,0 +1,11 @@
define(function (require) {

'use strict';
var Backbone = require('backbone');
var Model = require('users/model');

return Backbone.Collection.extend({
model: Model,
url: '/api/users'
});
});
19 changes: 19 additions & 0 deletions public/app/users/list.hbs
@@ -0,0 +1,19 @@
<div class="well">
<h4><b>Users</b></h4>
</div>
<table class="table table-bordered table-striped">
<thead>
<th>ID</th>
<th>Email</th>
<th>Name</th>
</thead>
<tbody>
{{#each users}}
<tr>
<td>{{_id}}</td>
<td>{{email}}</td>
<td>{{name}}</td>
</tr>
{{/each}}
</tbody>
</table>
18 changes: 18 additions & 0 deletions public/app/users/listView.js
@@ -0,0 +1,18 @@
define(function (require) {

'use strict';
var Backbone = require('backbone');
var template = require('hbs!users/list');
require('datatables');
require('datatables-bootstrap3');

return Backbone.View.extend({
el: '#content',
render: function(){
this.$el.html(template({users: this.collection.toJSON()}));
this.$('table').DataTable();
return this;
}
});

});
11 changes: 11 additions & 0 deletions public/app/users/model.js
@@ -0,0 +1,11 @@
define(function (require) {

'use strict';
var Backbone = require('backbone');

return Backbone.Model.extend({
idAttribute: '_id',
urlRoot: '/api/users'
});

});
2 changes: 2 additions & 0 deletions public/index.html
Expand Up @@ -5,6 +5,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Relearning Backbone</title> <title>Relearning Backbone</title>
<link rel="stylesheet" href="assets/css/bootstrap-lumen.min.css"> <link rel="stylesheet" href="assets/css/bootstrap-lumen.min.css">
<link rel="stylesheet" href="components/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="components/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css">


<script src="components/requirejs/require.js" data-main="require-main.js"></script> <script src="components/requirejs/require.js" data-main="require-main.js"></script>
</head> </head>
Expand Down
4 changes: 3 additions & 1 deletion public/require-main.js
Expand Up @@ -7,7 +7,9 @@ requirejs.config({
"backbone": "../components/backbone/backbone", "backbone": "../components/backbone/backbone",
"handlebars": "../components/handlebars/handlebars.amd", "handlebars": "../components/handlebars/handlebars.amd",
"text": "../components/requirejs-text/text", "text": "../components/requirejs-text/text",
"hbs": "../components/require-handlebars-plugin/hbs" "hbs": "../components/require-handlebars-plugin/hbs",
"datatables": "../components/datatables/media/js/jquery.dataTables",
"datatables-bootstrap3": "../components/datatables-bootstrap3-plugin/media/js/datatables-bootstrap3"
} }
}); });


Expand Down

0 comments on commit c29507a

Please sign in to comment.