Created
December 1, 2011 13:09
-
-
Save k33g/1416607 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
#--- MODEL --- | |
class Task extends bob.Model | |
@storage : "Tasks_Storage" | |
constructor:(label)-> | |
@label = label | |
@numericalId = 0 | |
#--- CONTROLLER --- | |
class window.Tasks extends bob.Controller | |
@sortByLabel:-> | |
@render | |
data: | |
tasks: Task.all().orderBy("label").fetch() | |
title: "Tasks List" | |
template: "tasks_template" | |
view: "tasks_view" | |
@sortDescByLabel:-> | |
@render | |
data: | |
tasks: Task.all().orderBy("label","DESC").fetch() | |
title: "Tasks List" | |
template: "tasks_template" | |
view: "tasks_view" | |
@sortById:-> | |
@render | |
data: | |
tasks: Task.all().orderBy("numericalId").fetch() | |
title: "Tasks List" | |
template: "tasks_template" | |
view: "tasks_view" | |
@sortDescById:-> | |
@render | |
data: | |
tasks: Task.all().orderBy("numericalId","DESC").fetch() | |
title: "Tasks List" | |
template: "tasks_template" | |
view: "tasks_view" | |
@getList:-> | |
@render | |
data: | |
tasks: Task.all().orderBy("label","DESC").fetch() | |
title: "Tasks List" | |
template: "tasks_template" | |
view: "tasks_view" | |
@saveTask:-> | |
task = new Task fieldLabel.value | |
task.numericalId = parseInt fieldId.value | |
task.save() | |
@render | |
data: | |
message: "#{task.label} has been saved ..." | |
template: "message_template" | |
view: "message_view" | |
Tasks.callAction "Tasks/getList" | |
fieldId.value = "" | |
fieldLabel.value = "" | |
@remove:(arg)-> | |
task = Task.find("id",arg.id).first() | |
if task | |
@render | |
data: | |
message: "#{task.label} deleted" | |
template: "message_template" | |
view: "message_view" | |
task.delete() | |
@callAction 'Tasks/getList' | |
onready = ()-> | |
window.fieldId = document.querySelector 'input:nth-of-type(1)' | |
window.fieldLabel = document.querySelector 'input:nth-of-type(2)' | |
bob.routes | |
"/" : -> | |
Tasks.getList() | |
bob.ready onready() |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>TODOLIST</title> | |
</head> | |
<body> | |
<h1>TODO LIST</h1> | |
<!-- MESSAGE VIEW --> | |
<script type="text/template" id="message_template"> | |
<h2>#{message}</h2> | |
</script> | |
<div id="message_view"></div> | |
<!-- END MESSAGE VIEW --> | |
<input type="text" placeholder="Task Id"/> | |
<input type="text" placeholder="TODO ?"/> <a href="#Tasks/saveTask">Create Task</a> | |
<hr> | |
<a href="#Tasks/sortByLabel">Sort By Label</a> | |
<a href="#Tasks/sortDescByLabel">Sort By Label, Descending</a> | |
<a href="#Tasks/sortById">Sort By Id</a> | |
<a href="#Tasks/sortDescById">Sort By Id, Descending</a> | |
<hr> | |
<!-- TASKS LIST VIEW --> | |
<script type="text/template" id="tasks_template"> | |
<h2 data-test="#{title}">#{title}</h2> | |
<ul data-set="tasks"> | |
<li>#{numericalId} - #{label} <a href="#Tasks/remove?id=#{id}">Delete</a></li> | |
</ul> | |
</script> | |
<div id="tasks_view"></div> | |
<!-- END TASKS LIST VIEW --> | |
</body> | |
<script src="js/vendors/coffee-script.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/bob.js"></script> | |
<script type="text/coffeescript" src="todolist.template.coffee"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment