Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa5dc5
commit edb8f71
Showing
10 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Tasks | ||
===== | ||
|
||
This example app has a corresponding tutorial that steps through its creation. The tutorial can be found [here](http://thatismatt.github.com/josi/tutorial.html). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
this.init = function() { | ||
this.router.add( | ||
// this route matches: /<controller>/<action>/<id> | ||
/^\/(?:(\w+)\/?)?(?:(\w+)\/?)?(?:([0-9]+)\/?)?$/, | ||
{ controller: 'home', action: 'index' } | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var view = require('josi/actionresults').view; | ||
|
||
this.index = function() { | ||
return view({ | ||
title: 'tasks - a josi app', | ||
controller: 'home', | ||
action: 'index', | ||
description: 'tasks is a <a href="http://thatismatt.github.com/josi/">josi</a> app' | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var actionresults = require('josi/actionresults'); | ||
var view = actionresults.view; | ||
var redirect = actionresults.redirect; | ||
var tasks = require('../models/tasks'); | ||
|
||
this.index = function() { | ||
return view({ | ||
title: 'All Tasks', | ||
tasks: tasks.list() | ||
}); | ||
}; | ||
|
||
this.details = function() { | ||
var task = tasks.get(this.route[0]); | ||
return view({ | ||
title: 'Task Details', | ||
task: task | ||
}); | ||
}; | ||
|
||
this.create = function() { | ||
if (this.form.title) { | ||
tasks.save({ | ||
title: this.form.title, | ||
details: this.form.details || 'No details.' | ||
}); | ||
return redirect('/task/'); | ||
} else { | ||
return view({ title: 'Create Task' }); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var tasks = []; | ||
|
||
this.list = function() { | ||
return tasks; | ||
}; | ||
|
||
this.get = function(id) { | ||
return tasks[id]; | ||
}; | ||
|
||
this.save = function(task) { | ||
if (!task.id) { | ||
tasks.push(task); | ||
} else { | ||
tasks[task.id] = task; | ||
} | ||
}; | ||
|
||
// test data | ||
tasks.push( | ||
{ title: 'Go for a jog', details: 'Run miles, and miles, and miles.' }, | ||
{ title: 'Sleep', details: 'I love sleep.' }, | ||
{ title: 'Read a book', details: 'Read a book by someone famous.' } | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p>Controller: <b><%= controller %></b></p> | ||
<p>Action: <b><%= action %></b></p> | ||
<p><%= description %></p> | ||
<p><a href="/task/">Tasks list</a></p> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<h1><%= title %></h1> | ||
<%= main %> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<form method="post" action="/task/create/"> | ||
<div> | ||
<label for="title">Title:</label><input id="title" name="title"> | ||
</div> | ||
<div> | ||
<label for="details">Details:</label><input id="details" name="details"> | ||
</div> | ||
<div> | ||
<input type="submit" value="Create"> | ||
</div> | ||
</form> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2><%= task.title %></h2> | ||
<p><%= task.details %></p> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ul> | ||
<% tasks.forEach(function(t, id) { %> | ||
<li><a href="/task/details/<%= id %>"><%= t.title %></a></li> | ||
<% }); %> | ||
</ul> | ||
<p><a href="/task/create/">Create a new task</a></p> |