app.Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
},
toggle: function () {
this.save({
completed: !this.get('completed')
});
}
});
var html = _.template('<li><%= name %></li>', { name: 'John Smith' });
var TodoList = Backbone.Collection.extend({
model: app.Todo,
localStorage: new Backbone.LocalStorage('todos-backbone'),
app.AppView = Backbone.View.extend({
el: '#todoapp',
statsTemplate: _.template($('#stats-template').html()),
events: {
'click #clear-completed': 'clearCompleted',
},
initialize: function () {
this.$input = this.$('#new-todo');
this.listenTo(app.Todos, 'add', this.addOne);
}
clearCompleted: function () { /* */},
addOne: function () { /* */}
}
var AppRouter = Backbone.Router.extend({
routes: {
"posts/:id": "getPost",
}
});
var app_router = new AppRouter;
app_router.on('route:getPost', function (id) {
alert( "Get post number " + id );
});
Backbone.history.start();
function backbone_todo_library_info() {
$path = drupal_get_path('module', 'backbone_todo');
$options = array(
'scope' => 'footer',
'attributes' => array('defer' => TRUE),
);
$libraries['backbone_todo'] = array(
'title' => 'Backbone todo list',
'version' => '0.1.0',
'js' => array(
$path . '/js/todo.js' => $options,
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'underscore'),
array('system', 'backbone'),
)
);
return $libraries;
}
(TODO - prepare presentation)
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
}
}