Created
February 24, 2010 22:26
-
-
Save pifantastic/313950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialization | |
var app = new Application({ | |
container: "div#container", | |
database: "database.sqlite" | |
}); | |
// Events | |
app.bind("startup", function(e) {}); | |
app.bind("shutdown", function(e) {}); | |
// Controllers | |
var HomeController = Controller.extend({ | |
index: function(req) { | |
var todos = app.orm.factory('todos').findAll(); | |
var template = new Template(app.home, {todos: todos}); | |
template.renderTo("div#container"); | |
}, | |
}); | |
var TodoController = Controller.extend({ | |
add: function(req) { | |
var template = new Template(app.todoForm); | |
template.renderTo("div#container"); | |
if (req.POST) { | |
var todo = app.orm.factory('todos'); | |
todo.name = req.POST.name; | |
todo.save(); | |
return app.redirect('#/home'); | |
} | |
}, | |
edit: function(req, id) { | |
var todo = app.orm.factory('todos').find(id); | |
if (!todo) { | |
return app.error('404'); | |
} | |
var template = new Template(app.todoForm, {todo: todo}); | |
template.renderTo("div#container"); | |
if (req.POST) { | |
var todo = app.orm.factory('todos').find(req.POST.id); | |
if (todo) { | |
todo.name = this.POST.name; | |
todo.save(); | |
} | |
return app.redirect('#/home'); | |
} | |
}, | |
delete: function(req, id) { | |
var todo = app.orm.factory('todos').find(id); | |
if (todo) { | |
todo.delete(); | |
} | |
app.redirect('#/home'); | |
} | |
}); | |
var AccountController = Controller.extend({ | |
login: function() { | |
}, | |
logout: function() { | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment