diff --git a/lib/mods.js b/lib/mods.js index 26b44eb..6122b52 100644 --- a/lib/mods.js +++ b/lib/mods.js @@ -1,7 +1,7 @@ var async = require('async'); var events = require('events'); var filesize = require('filesize'); -var fs = require('fs'); +var fs = require('fs.extra'); var _ = require('lodash'); var path = require('path'); var playwithsix = require('playwithsix'); @@ -25,6 +25,14 @@ Mods.removeDuplicates = function (mods) { Mods.prototype = new events.EventEmitter(); +Mods.prototype.delete = function (mod, cb) { + var self = this; + fs.rmrf(path.join(this.config.path, mod), function (err) { + self.updateMods(); + cb(err); + }); +}; + Mods.prototype.download = function (mod, cb) { var self = this; var currentDownloadMod = null; diff --git a/package.json b/package.json index 6e717c5..c552038 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "express": "3.x", "express-resource": "~1.0.0", "filesize": "^3.1.0", + "fs.extra": "~1.3.2", "gamedig": "^0.2.11", "lodash": "^3.6.0", "playwithsix": "0.0.10", diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index e3704ab..0439581 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -7,6 +7,7 @@ define(function (require) { Backbone = require('backbone'), Marionette = require('marionette'), Ladda = require('ladda'), + swal = require('sweet-alert'), tpl = require('text!tpl/mods/list_item.html'), template = _.template(tpl); @@ -16,7 +17,23 @@ define(function (require) { template: template, events: { - "click .update": "update" + "click .destroy": "destroy", + "click .update": "update", + }, + + destroy: function (event) { + var self = this; + sweetAlert({ + title: "Are you sure?", + text: "The mod will be deleted from the server!", + type: "warning", + showCancelButton: true, + confirmButtonClass: "btn-danger", + confirmButtonText: "Yes, delete it!", + }, + function(){ + self.model.destroy(); + }); }, update: function (event) { diff --git a/public/js/tpl/mods/list_item.html b/public/js/tpl/mods/list_item.html index 5671ea8..30ef88b 100644 --- a/public/js/tpl/mods/list_item.html +++ b/public/js/tpl/mods/list_item.html @@ -1,4 +1,4 @@ - + <%-name%> <% if (playWithSix) { %> @@ -12,11 +12,19 @@ <%-progress%>% - <% } else if (outdated) { %> - - - Update + <% } else { %> + + + Delete + + <% if (outdated) { %> + + + Update + + <% } %> +
<% } %> diff --git a/routes/mods.js b/routes/mods.js index 8492fc5..affacf4 100644 --- a/routes/mods.js +++ b/routes/mods.js @@ -36,7 +36,13 @@ module.exports = function (modsManager) { }, destroy: function(req, res){ - res.send('destroy mod ' + req.params.mod); + modsManager.delete(req.params.mod, function (err) { + if (err) { + res.send(500, err); + } else { + res.send(204, {}); + } + }); }, refresh: function(req, res){