From: Johannes Zellner Date: Tue, 1 Mar 2016 15:07:44 +0000 (+0100) Subject: Implement file deletion X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=9138d7d40ba6570347dd21fc95d03641360c7461;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git Implement file deletion --- diff --git a/app/index.html b/app/index.html index 721ec25..bc9ac22 100644 --- a/app/index.html +++ b/app/index.html @@ -31,6 +31,24 @@ + +
@@ -102,7 +120,7 @@ {{ entry.filePath }} {{ entry.size }} {{ entry.mtime }} - + diff --git a/app/js/app.js b/app/js/app.js index e2fe621..823e4f7 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -101,6 +101,28 @@ function upload() { app.$els.upload.click(); } +function delAsk(entry) { + $('#modalDelete').modal('show'); + app.deleteData = entry; +} + +function del(entry) { + app.busy = true; + + var path = encode(sanitize(app.path + '/' + entry.filePath)); + + superagent.del('/api/files' + path).query({ username: app.session.username, password: app.session.password, recursive: true }).end(function (error, result) { + app.busy = false; + + if (error) return console.error(error); + if (result.statusCode !== 200) return console.error('Error deleting file: ', result.statusCode); + + refresh(); + + $('#modalDelete').modal('hide'); + }); +} + var app = new Vue({ el: '#app', data: { @@ -111,6 +133,7 @@ var app = new Vue({ valid: false }, loginData: {}, + deleteData: {}, entries: [] }, methods: { @@ -119,7 +142,9 @@ var app = new Vue({ loadDirectory: loadDirectory, open: open, up: up, - upload: upload + upload: upload, + delAsk: delAsk, + del: del } });