Action to delete mod in mods list

This commit is contained in:
Björn Dahlgren 2015-07-22 18:16:30 +00:00
parent 1080bc0cbe
commit 0643b28490
5 changed files with 48 additions and 8 deletions

View File

@ -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;

View File

@ -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",

View File

@ -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) {

View File

@ -1,4 +1,4 @@
<td style="width: 100%;">
<td>
<a href='#mods/<%-name%>'><%-name%></a>
<% if (playWithSix) { %>
@ -12,11 +12,19 @@
<%-progress%>%
</div>
</div>
<% } else if (outdated) { %>
<a class="btn btn-primary btn-xs update ladda-button pull-right" data-style="expand-left">
<span class="glyphicon glyphicon-save"></span>
Update
<% } else { %>
<a class="btn btn-primary btn-xs destroy ladda-button pull-right" data-style="expand-left">
<span class="glyphicon glyphicon-trash"></span>
Delete
</a>
<% if (outdated) { %>
<a class="btn btn-primary btn-xs update ladda-button pull-right" data-style="expand-left" style="margin-right: 8px">
<span class="glyphicon glyphicon-save"></span>
Update
</a>
<% } %>
<div class="clearfix"></div>
<% } %>
</td>

View File

@ -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){