Make the "new task" form functional

This commit is contained in:
Rowan Manning
2013-09-16 11:09:49 +01:00
parent a7aad37ea0
commit 7fd93d114f
5 changed files with 54 additions and 2 deletions

1
app.js
View File

@@ -24,6 +24,7 @@ function initApp (config, callback) {
maxAge: (process.env.NODE_ENV === 'production' ? 604800 : 0)
}));
app.express.use(express.compress());
app.express.use(express.bodyParser());
// View engine
app.express.set('views', __dirname + '/view');

View File

@@ -4,7 +4,22 @@ module.exports = route;
// Route definition
function route (app) {
app.express.get('/new', function (req, res) {
res.render('new');
});
app.express.post('/new', function (req, res) {
var newTask = {
url: req.body.url,
standard: req.body.standard
};
app.webservice.tasks.create(newTask, function (err, task) {
if (err) {
return res.render('new', {error: err});
}
res.redirect('/' + task.id + '?added');
});
});
}

View File

@@ -15,7 +15,8 @@ function route (app) {
}
res.render('task', {
task: task,
results: results
results: results,
added: (typeof req.query.added !== 'undefined')
});
});
});

View File

@@ -7,4 +7,33 @@
<h1>Create A Task</h1>
<p><b>TODO: Add form here and create handler for it.</b></p>
<form action="/new" method="post">
{{#error}}
<div style="color: #c00;">
<p>{{error}}</p>
</div>
{{/error}}
<div>
<label for="new-task-url">URL</label><br/>
<input id="new-task-url" type="text" name="url"/>
</div>
<div>
<label for="new-task-standard">Standard</label><br/>
<select id="new-task-standard" name="standard">
<option>WCAG2A</option>
<option>WCAG2AA</option>
<option>WCAG2AAA</option>
<option>Section508</option>
</select>
</div>
<p><b>TODO: add ignore rules!</b></p>
<div>
<input type="submit" value="Add"/>
</div>
</form>

View File

@@ -7,6 +7,12 @@
<h1>Task: {{task.url}} ({{task.standard}})</h1>
{{#added}}
<div style="color: #090;">
<p>Task added!</p>
</div>
{{/added}}
<p>Here are the results:</p>
{{> results}}