Delete missions

This commit is contained in:
Björn Dahlgren 2014-04-05 17:02:17 +00:00
parent 0c57678db6
commit 76c05d9c7d
4 changed files with 45 additions and 10 deletions

View File

@ -12,6 +12,23 @@ define(function (require) {
return Marionette.ItemView.extend({ return Marionette.ItemView.extend({
tagName: "tr", tagName: "tr",
template: template template: template,
events: {
"click .delete": "delete"
},
delete: function (event) {
var self = this;
event.preventDefault();
$.ajax({
url: "/api/missions/" + this.model.get('name'),
type: 'DELETE',
success: function (resp) {
self.model.destroy();
},
error: $.noop
});
},
}); });
}); });

View File

@ -2,6 +2,7 @@
<thead> <thead>
<tr> <tr>
<th>Mission</th> <th>Mission</th>
<th></th>
</tr> </tr>
</thead> </thead>

View File

@ -1,3 +1,8 @@
<td> <td>
<a href='#missions/<%-name%>'><%-name%></a> <a href='#missions/<%-name%>'><%-name%></a>
</td> </td>
<td>
<button type="button" class="btn btn-danger btn-xs delete">
<span class="glyphicon glyphicon-remove"></span> Delete
</button>
</td>

View File

@ -33,5 +33,17 @@ exports.show = function(req, res){
}; };
exports.destroy = function(req, res){ exports.destroy = function(req, res){
res.send('destroy mission ' + req.params.mission); var path = config.path + '/mpmissions/' + req.params.mission;
if (req.params.format) {
path += '.' + req.params.format;
}
fs.unlink(path, function (err) {
if (err) {
res.json(500, {success: false});
} else {
res.json({success: true});
}
});
}; };