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

@ -1,17 +1,34 @@
define(function (require) {
"use strict";
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone'),
Marionette = require('marionette'),
tpl = require('text!tpl/missions/list_item.html'),
template = _.template(tpl);
return Marionette.ItemView.extend({
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,9 +2,10 @@
<thead>
<tr>
<th>Mission</th>
<th></th>
</tr>
</thead>
<!-- want to insert collection items, here -->
<tbody></tbody>
</table>

View File

@ -1,3 +1,8 @@
<td>
<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

@ -18,7 +18,7 @@ exports.index = function(req, res){
exports.create = function(req, res){
var missionFile = req.files.mission;
fs.readFile(missionFile.path, function (err, data) {
var newPath = config.path + '/mpmissions/' + missionFile.name;
console.log(newPath);
@ -33,5 +33,17 @@ exports.show = 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});
}
});
};