From 76c05d9c7dd82eae0626a9cbafb2dae156149465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Sat, 5 Apr 2014 17:02:17 +0000 Subject: [PATCH] Delete missions --- public/js/app/views/missions/list_item.js | 27 ++++++++++++++++++----- public/js/tpl/missions/list.html | 3 ++- public/js/tpl/missions/list_item.html | 7 +++++- routes/missions.js | 18 ++++++++++++--- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/public/js/app/views/missions/list_item.js b/public/js/app/views/missions/list_item.js index 324ed0a..b3f1792 100644 --- a/public/js/app/views/missions/list_item.js +++ b/public/js/app/views/missions/list_item.js @@ -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 + }); + }, }); }); diff --git a/public/js/tpl/missions/list.html b/public/js/tpl/missions/list.html index b1c5ad4..25a7b8b 100644 --- a/public/js/tpl/missions/list.html +++ b/public/js/tpl/missions/list.html @@ -2,9 +2,10 @@ Mission + - + diff --git a/public/js/tpl/missions/list_item.html b/public/js/tpl/missions/list_item.html index 731335c..4671eee 100644 --- a/public/js/tpl/missions/list_item.html +++ b/public/js/tpl/missions/list_item.html @@ -1,3 +1,8 @@ <%-name%> - + + + + diff --git a/routes/missions.js b/routes/missions.js index b0ea33f..1510e20 100644 --- a/routes/missions.js +++ b/routes/missions.js @@ -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); -}; \ No newline at end of file + 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}); + } + }); +};